: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): link PR comment thumbnails to full-resolution images (#65544)
Rafael Audibert81f79976ed16
diff --git a/products/visual_review/backend/logic.py b/products/visual_review/backend/logic.pyindex dfb27003030d..72de2e9d2710 100644--- a/products/visual_review/backend/logic.py+++ b/products/visual_review/backend/logic.py@@ -1841,17 +1841,17 @@ _MAX_COMMENT_IMAGES = 8def _comment_image_url(repo: Repo, artifact: Artifact | None) -> str | None:- """Presigned URL for embedding a snapshot image in a PR comment.+ """Presigned URL for the full-resolution snapshot image in a PR comment.- Prefers the thumbnail to keep the comment lightweight. Returns None when the- artifact is missing or object storage is disabled — the caller renders an- empty cell in that case.+ Serves the original artifact (not the thumbnail) so the embedded image opens at full+ resolution when clicked — GitHub constrains the rendered size via the ``<img width>``+ attribute but links the original. Returns None when the artifact is missing or object+ storage is disabled — the caller renders an empty cell in that case."""if artifact is None:return None- display = artifact.thumbnail or artifactstorage = ArtifactStorage(str(repo.id))- return storage.get_presigned_download_url(display.content_hash, expiration=_COMMENT_IMAGE_URL_EXPIRATION)+ return storage.get_presigned_download_url(artifact.content_hash, expiration=_COMMENT_IMAGE_URL_EXPIRATION)_TABLE_BREAKING_CHARS_RE = re.compile(r"[\x00-\x1f\x7f]")@@ -1887,7 +1887,12 @@ def _snapshot_link_cell(run: Run, repo: Repo, snapshot: RunSnapshot, suffix: strdef _image_cell(url: str | None, alt: str) -> str:- """Render an image (or an empty placeholder) for a before/after table cell."""+ """Render an image (or an empty placeholder) for a before/after table cell.++ The image is constrained to ``_COMMENT_IMAGE_WIDTH`` so the table stays compact, but+ ``src`` points at the full-resolution original — GitHub opens that original when the+ image is clicked.+ """if not url:return "_(none)_"# Escape both attributes — a URL containing a quote would otherwise break out of src.@@ -1927,9 +1932,7 @@ def _build_snapshot_image_tables(run: Run, repo: Repo) -> str:_postable_snapshot_qs(run).select_related("current_artifact",- "current_artifact__thumbnail","baseline_artifact",- "baseline_artifact__thumbnail",).order_by("identifier"))diff --git a/products/visual_review/backend/tests/test_logic.py b/products/visual_review/backend/tests/test_logic.pyindex 68662717aefc..e1ec1811ecaf 100644--- a/products/visual_review/backend/tests/test_logic.py+++ b/products/visual_review/backend/tests/test_logic.py@@ -2823,10 +2823,12 @@ class TestApprovalComment:body = logic._build_approval_comment_body(run_with_artifacts, repo, None, add_images=True)- # Changed table: baseline (thumbnail) before, current after+ # Changed table: baseline before, current after — full-resolution originals,+ # not thumbnails, so clicking opens the image at full sizeassert "**Changed**" in bodyassert "| Snapshot | Before | After |" in body- assert "https://cdn.example/thumb_a" in body # prefers the thumbnail+ assert "https://cdn.example/base_a" in body # full-res original, not thumb_a+ assert "https://cdn.example/thumb_a" not in bodyassert "https://cdn.example/curr_a" in body# Removed snapshot lives in the changed table with an empty after cellassert "_(removed)_" in body@@ -2933,6 +2935,12 @@ class TestApprovalComment:assert 'alt="a"b"' in cellassert 'src="https://cdn.example/x?a="b"' in cell+ def test_image_cell_constrains_width_but_serves_full_resolution(self):+ # The cell shows a width-constrained image whose src is the full-resolution+ # original, so GitHub opens it at full size when clicked — no <a> wrapper needed.+ cell = logic._image_cell("https://cdn.example/full", "after")+ assert cell == f'<img src="https://cdn.example/full" width="{logic._COMMENT_IMAGE_WIDTH}" alt="after">'+@pytest.mark.parametrize("identifier,expected",[@@ -2979,3 +2987,14 @@ class TestApprovalComment:assert url == "https://cdn.example/x"assert captured["content_hash"] == "h1"assert captured["expiration"] == 60 * 60 * 24 * 7 == 604800++ def test_comment_image_url_serves_full_resolution_not_thumbnail(self, repo, mocker):+ # Serve the original artifact, not the thumbnail, so clicking opens it full-size+ mocker.patch.object(logic, "ArtifactStorage", self._fake_storage())++ artifact = self._mk_artifact(repo, "full_h", with_thumbnail="thumb_h")+ url = logic._comment_image_url(repo, artifact)++ assert url is not None+ assert "full_h" in url+ assert "thumb_h" not in url