:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(visual-review): exclude quarantined and tolerated snapshots from approval comment (#63515)
Paul D'Ambra155a9d925a26
diff --git a/products/visual_review/backend/logic.py b/products/visual_review/backend/logic.pyindex b8b9e5565c8c..b62953cdb353 100644--- a/products/visual_review/backend/logic.py+++ b/products/visual_review/backend/logic.py@@ -1853,6 +1853,22 @@ def _image_cell(url: str | None, alt: str) -> str:_IMAGE_TABLE_HEADER = "| Snapshot | Before | After |\n| --- | --- | --- |"+_REVIEWABLE_RESULTS = (SnapshotResult.CHANGED, SnapshotResult.NEW, SnapshotResult.REMOVED)+++def _reviewable_snapshot_qs(run: Run) -> db_models.QuerySet[RunSnapshot]:+ return run.snapshots.using(READER_DB).filter(result__in=_REVIEWABLE_RESULTS)+++def _postable_snapshot_qs(run: Run) -> db_models.QuerySet[RunSnapshot]:+ """Reviewable snapshots minus the ones an approval comment should not surface.++ Quarantined snapshots are suppressed by policy and tolerated ones are+ intentional known drift, so neither belongs in the comment.+ """+ return _reviewable_snapshot_qs(run).exclude(is_quarantined=True).exclude(review_state=ReviewState.TOLERATED)++def _build_snapshot_image_tables(run: Run, repo: Repo) -> str:"""Before/after image tables for the approved snapshots.@@ -1863,8 +1879,7 @@ def _build_snapshot_image_tables(run: Run, repo: Repo) -> str:resolved (e.g. object storage disabled) so the comment stays text-only."""snapshots = list(- run.snapshots.using(READER_DB)- .filter(result__in=(SnapshotResult.CHANGED, SnapshotResult.NEW, SnapshotResult.REMOVED))+ _postable_snapshot_qs(run).select_related("current_artifact","current_artifact__thumbnail",@@ -1924,11 +1939,8 @@ def _build_approval_comment_body(run: Run, repo: Repo, approver: _Approver | Nonreviewer can eyeball them without leaving the PR (omitted when no image canbe resolved)."""- counts = Counter(- run.snapshots.filter(- result__in=(SnapshotResult.CHANGED, SnapshotResult.NEW, SnapshotResult.REMOVED)- ).values_list("result", flat=True)- )+ counts = Counter(_postable_snapshot_qs(run).values_list("result", flat=True))+ suppressed_only = not counts and _reviewable_snapshot_qs(run).exists()if approver is None:approver_text = "a reviewer"@@ -1955,6 +1967,8 @@ def _build_approval_comment_body(run: Run, repo: Repo, approver: _Approver | Non]if summary:sections.append(f"{summary}.")+ elif suppressed_only:+ sections.append("All visual changes in this run were quarantined or tolerated.")if add_images:tables = _build_snapshot_image_tables(run, repo)if tables:diff --git a/products/visual_review/backend/tests/test_logic.py b/products/visual_review/backend/tests/test_logic.pyindex b7770d4dcdb4..586294b457d2 100644--- a/products/visual_review/backend/tests/test_logic.py+++ b/products/visual_review/backend/tests/test_logic.py@@ -2540,6 +2540,70 @@ class TestApprovalComment:assert "changed" not in bodyassert "new" not in bodyassert "removed" not in body+ # A genuinely empty run stays silent — the suppressed-only note must not fire+ assert "quarantined or tolerated" not in body++ def test_build_approval_comment_body_excludes_quarantined_and_tolerated(self, repo):+ run = Run.objects.create(+ team_id=repo.team_id,+ repo=repo,+ commit_sha="mixed",+ branch="feature",+ pr_number=42,+ review_decision=ReviewDecision.HUMAN_APPROVED,+ )+ RunSnapshot.objects.create(+ team_id=repo.team_id, run=run, identifier="Real/Change", result=SnapshotResult.CHANGED+ )+ RunSnapshot.objects.create(+ team_id=repo.team_id,+ run=run,+ identifier="Flaky/Quarantined",+ result=SnapshotResult.CHANGED,+ is_quarantined=True,+ )+ RunSnapshot.objects.create(+ team_id=repo.team_id,+ run=run,+ identifier="Known/Tolerated",+ result=SnapshotResult.NEW,+ review_state=ReviewState.TOLERATED,+ )++ body = logic._build_approval_comment_body(run, repo, logic._Approver(label="bob", is_github_login=True))++ assert "1 changed." in body+ assert "new" not in body+ assert "quarantined or tolerated" not in body++ def test_build_approval_comment_body_notes_when_only_quarantined_and_tolerated(self, repo):+ run = Run.objects.create(+ team_id=repo.team_id,+ repo=repo,+ commit_sha="suppressed",+ branch="feature",+ pr_number=42,+ review_decision=ReviewDecision.HUMAN_APPROVED,+ )+ RunSnapshot.objects.create(+ team_id=repo.team_id,+ run=run,+ identifier="Flaky/Quarantined",+ result=SnapshotResult.CHANGED,+ is_quarantined=True,+ )+ RunSnapshot.objects.create(+ team_id=repo.team_id,+ run=run,+ identifier="Known/Tolerated",+ result=SnapshotResult.NEW,+ review_state=ReviewState.TOLERATED,+ )++ body = logic._build_approval_comment_body(run, repo, logic._Approver(label="bob", is_github_login=True))++ assert "All visual changes in this run were quarantined or tolerated." in body+ assert "1 changed" not in bodydef test_post_approval_comment_skips_when_pr_comments_disabled(self, repo, run_with_snapshots, mocker):repo.enable_pr_comments = False@@ -2711,6 +2775,35 @@ class TestApprovalComment:# Long-lived URL so GitHub's image proxy can still fetch it laterassert f"exp={logic._COMMENT_IMAGE_URL_EXPIRATION}" in body+ def test_build_snapshot_image_tables_excludes_quarantined_and_tolerated(self, repo, run_with_artifacts, mocker):+ mocker.patch.object(logic, "ArtifactStorage", self._fake_storage())+ RunSnapshot.objects.create(+ team_id=repo.team_id,+ run=run_with_artifacts,+ identifier="Flaky/Quarantined",+ result=SnapshotResult.CHANGED,+ is_quarantined=True,+ baseline_artifact=self._mk_artifact(repo, "base_q"),+ current_artifact=self._mk_artifact(repo, "curr_q"),+ )+ RunSnapshot.objects.create(+ team_id=repo.team_id,+ run=run_with_artifacts,+ identifier="Known/Tolerated",+ result=SnapshotResult.CHANGED,+ review_state=ReviewState.TOLERATED,+ baseline_artifact=self._mk_artifact(repo, "base_t"),+ current_artifact=self._mk_artifact(repo, "curr_t"),+ )++ body = logic._build_snapshot_image_tables(run_with_artifacts, repo)++ assert "Flaky/Quarantined" not in body+ assert "Known/Tolerated" not in body+ assert "curr_q" not in body+ assert "curr_t" not in body+ assert "Login/Form" in body+def test_build_approval_comment_body_deep_links_each_snapshot(self, repo, run_with_artifacts, mocker):mocker.patch.object(logic, "ArtifactStorage", self._fake_storage())