diff --git a/script/quality_scale_review/__main__.py b/script/quality_scale_review/__main__.py index 6d4efac80fb4..bfb9e8f9a161 100644 --- a/script/quality_scale_review/__main__.py +++ b/script/quality_scale_review/__main__.py @@ -83,8 +83,9 @@ def main(argv: list[str] | None = None) -> int: parser.error("GITHUB_TOKEN is unset") pr = github_api.fetch_pull_request(args.repo, args.pr_number, token) + # The diff excludes test snapshots, so they do not make a domain touched. domains = integrations.with_quality_scale( - integrations.touched_domains(pr.filenames), pr.file_statuses + integrations.touched_domains(pr.reviewed_filenames), pr.file_statuses ) decision = decide_skip( pr, diff --git a/script/quality_scale_review/models.py b/script/quality_scale_review/models.py index 34dd5f009423..bec748a50ff6 100644 --- a/script/quality_scale_review/models.py +++ b/script/quality_scale_review/models.py @@ -31,6 +31,11 @@ class PullRequest: """Return the paths of the changed files.""" return list(self.file_statuses) + @property + def reviewed_filenames(self) -> list[str]: + """Return the paths of the changed files that are not test snapshots.""" + return [name for name in self.file_statuses if not name.endswith(".ambr")] + @property def changed_lines(self) -> int: """Return the number of added plus deleted lines.""" diff --git a/tests/scripts/quality_scale_review/test_main.py b/tests/scripts/quality_scale_review/test_main.py index cb977eea2a38..d2338f639448 100644 --- a/tests/scripts/quality_scale_review/test_main.py +++ b/tests/scripts/quality_scale_review/test_main.py @@ -1,5 +1,6 @@ """Tests for script.quality_scale_review.__main__.""" +from dataclasses import replace import json from pathlib import Path @@ -174,6 +175,28 @@ def test_skips_a_pull_request_without_a_quality_scale( assert not (tmp_path / "rules-index.txt").exists() +def test_skips_a_pull_request_that_only_changes_snapshots( + monkeypatch: pytest.MonkeyPatch, tmp_path: Path +) -> None: + """Snapshots are left out of the diff, so they do not make a domain touched.""" + pr = replace( + _pull_request(1, 1, 1, snapshot_lines=2, snapshot_files=1), + file_statuses={ + "tests/components/peblar/snapshots/test_sensor.ambr": "modified" + }, + ) + monkeypatch.setattr(github_api, "fetch_pull_request", lambda *args: pr) + monkeypatch.setattr(integrations, "with_quality_scale", lambda domains, *a: domains) + + assert __main__.main(["--pr-number", "42", "--output", str(tmp_path)]) == 0 + + results = json.loads((tmp_path / "results.json").read_text()) + assert results["skip"] is True + assert results["too_long"] is False + assert results["domains"] == [] + assert not (tmp_path / "pr-diff.patch").exists() + + def test_skips_a_pull_request_that_is_too_long( monkeypatch: pytest.MonkeyPatch, tmp_path: Path ) -> None: diff --git a/tests/scripts/quality_scale_review/test_models.py b/tests/scripts/quality_scale_review/test_models.py index e04768287e99..9a88ddc4bade 100644 --- a/tests/scripts/quality_scale_review/test_models.py +++ b/tests/scripts/quality_scale_review/test_models.py @@ -40,6 +40,17 @@ def test_reviewed_counts_exclude_snapshots() -> None: assert (pr.reviewed_lines, pr.reviewed_files) == (22, 2) +def test_reviewed_filenames_exclude_snapshots() -> None: + """Test snapshot files are left out of the reviewed file names.""" + pr = _pull_request( + file_statuses={ + "homeassistant/components/peblar/sensor.py": "modified", + "tests/components/peblar/snapshots/test_sensor.ambr": "modified", + } + ) + assert pr.reviewed_filenames == ["homeassistant/components/peblar/sensor.py"] + + def test_to_meta_dict_omits_the_changed_filenames() -> None: """The metadata payload holds exactly the keys the agent reads.""" assert _pull_request().to_meta_dict() == {