: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): name both required params on snapshot lookups (#94766)
posthog[bot]4ff2da90a2a7
diff --git a/products/visual_review/backend/presentation/views.py b/products/visual_review/backend/presentation/views.pyindex 7b842e062d87..1d240db4137d 100644--- a/products/visual_review/backend/presentation/views.py+++ b/products/visual_review/backend/presentation/views.py@@ -91,6 +91,38 @@ def _parse_uuid(value: str, field: str = "id") -> UUID:raise ValidationError({field: "Must be a valid UUID."})+# Both run-scoped snapshot lookups need a run id AND a snapshot identifier. Clients that+# read only the prose kept sending one of the two, so the pair is described in one place+# and each side names the other as required.+_RUN_ID_PATH_PARAMETER = OpenApiParameter(+ "id",+ OpenApiTypes.UUID,+ OpenApiParameter.PATH,+ required=True,+ description=(+ "UUID of the visual review run to look the snapshot up from. This is a run id, not the "+ "`id` of a snapshot inside that run. The run supplies the repo and run type to search, so "+ "the `identifier` query parameter is required alongside it."+ ),+)++_SNAPSHOT_IDENTIFIER_PARAMETER = OpenApiParameter(+ "identifier",+ str,+ required=True,+ description=(+ "Identifier of the snapshot to look up, for example a Storybook story id plus theme. Read "+ "it from the `identifier` field of a snapshot in the run. It is a name rather than a UUID, "+ "and it is required in addition to the run id in the path."+ ),+)++_MISSING_IDENTIFIER_DETAIL = (+ "The identifier query parameter is required. Pass the `identifier` of the snapshot you want, "+ "which you can read from the run's snapshot list."+)++class SnapshotsPagination(LimitOffsetPagination):"""Adds quarantined_count to the paginated snapshots envelope so a client canshow "N quarantined hidden" without a second request. The action sets@@ -594,7 +626,10 @@ class RunViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):return Response(SnapshotSerializer(instance=snapshot).data)@extend_schema(- parameters=[OpenApiParameter("identifier", str, required=True, description="Snapshot identifier")],+ parameters=[+ _RUN_ID_PATH_PARAMETER,+ _SNAPSHOT_IDENTIFIER_PARAMETER,+ ],responses={200: ToleratedHashEntrySerializer(many=True)},)@action(detail=True, methods=["get"], url_path="tolerated-hashes")@@ -602,7 +637,7 @@ class RunViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):"""List known tolerated hashes for a snapshot identifier."""identifier = request.query_params.get("identifier")if not identifier:- return Response({"detail": "identifier query param required"}, status=status.HTTP_400_BAD_REQUEST)+ return Response({"detail": _MISSING_IDENTIFIER_DETAIL}, status=status.HTTP_400_BAD_REQUEST)try:run = api.get_run(_parse_uuid(pk), team_id=self.team_id)except api.RunNotFoundError:@@ -631,7 +666,10 @@ class RunViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):return Response(AddSnapshotsResultSerializer(instance=result).data)@extend_schema(- parameters=[OpenApiParameter("identifier", str, required=True, description="Snapshot identifier")],+ parameters=[+ _RUN_ID_PATH_PARAMETER,+ _SNAPSHOT_IDENTIFIER_PARAMETER,+ ],responses={200: SnapshotHistoryEntrySerializer(many=True)},)@action(detail=True, methods=["get"], url_path="snapshot-history")@@ -639,7 +677,7 @@ class RunViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):"""Recent change history for a snapshot identifier across runs."""identifier = request.query_params.get("identifier")if not identifier:- return Response({"detail": "identifier query param required"}, status=status.HTTP_400_BAD_REQUEST)+ return Response({"detail": _MISSING_IDENTIFIER_DETAIL}, status=status.HTTP_400_BAD_REQUEST)try:run = api.get_run(_parse_uuid(pk), team_id=self.team_id)diff --git a/products/visual_review/backend/tests/test_presentation.py b/products/visual_review/backend/tests/test_presentation.pyindex 50e80366ca3f..454d63f58bf8 100644--- a/products/visual_review/backend/tests/test_presentation.py+++ b/products/visual_review/backend/tests/test_presentation.py@@ -677,6 +677,26 @@ class TestMalformedUuidReturns400(VisualReviewTeamScopedTestMixin, APIBaseTest):assert response.status_code == status.HTTP_400_BAD_REQUEST, response.json()+class TestSnapshotLookupRequiresIdentifier(VisualReviewTeamScopedTestMixin, APIBaseTest):+ databases = PRODUCT_DATABASES++ # The guard runs before the run lookup, so these need no seeded run.+ RUN_ID = "3f1c9f0e-2b7a-4a5f-9c1d-8e6b2a4f7d31"++ @parameterized.expand(+ [+ ("snapshot_history", "snapshot-history"),+ ("tolerated_hashes", "tolerated-hashes"),+ ]+ )+ def test_missing_identifier_returns_400(self, _name: str, action: str) -> None:+ response = self.client.get(+ f"/api/projects/{self.team.id}/visual_review/runs/{self.RUN_ID}/{action}/",+ )++ assert response.status_code == status.HTTP_400_BAD_REQUEST, response.json()++class TestRunFinalizePersonalAPIKeyScopes(VisualReviewTeamScopedTestMixin, APIBaseTest):databases = PRODUCT_DATABASESCONFIG_AUTO_LOGIN = Falsediff --git a/products/visual_review/frontend/generated/api.schemas.ts b/products/visual_review/frontend/generated/api.schemas.tsindex 86a057ea04b1..0facfd32d537 100644--- a/products/visual_review/frontend/generated/api.schemas.ts+++ b/products/visual_review/frontend/generated/api.schemas.ts@@ -665,7 +665,7 @@ export type VisualReviewRunsListParams = {export type VisualReviewRunsSnapshotHistoryListParams = {/**- * Snapshot identifier+ * Identifier of the snapshot to look up, for example a Storybook story id plus theme. Read it from the `identifier` field of a snapshot in the run. It is a name rather than a UUID, and it is required in addition to the run id in the path.*/identifier: string/**@@ -695,7 +695,7 @@ export type VisualReviewRunsSnapshotsListParams = {export type VisualReviewRunsToleratedHashesListParams = {/**- * Snapshot identifier+ * Identifier of the snapshot to look up, for example a Storybook story id plus theme. Read it from the `identifier` field of a snapshot in the run. It is a name rather than a UUID, and it is required in addition to the run id in the path.*/identifier: string/**diff --git a/products/visual_review/mcp/tools.yaml b/products/visual_review/mcp/tools.yamlindex db6fd5cb75cf..8d424346a8d1 100644--- a/products/visual_review/mcp/tools.yaml+++ b/products/visual_review/mcp/tools.yaml@@ -308,9 +308,24 @@ tools:idempotent: truetitle: Snapshot change historydescription: >- List recent change history for a snapshot `identifier` across previous runs in the same repo. Useful for- diagnosing flaky snapshots — if the same identifier flips between changed and clean across runs, it is a- candidate for tolerated hashes or quarantine. Requires `identifier` query parameter.+ List recent change history for one snapshot across previous runs in the same repo. Useful for diagnosing+ flaky snapshots — if the same identifier flips between changed and clean across runs, it is a candidate for+ tolerated hashes or quarantine. Both parameters are required, and one snapshot from+ `visual-review-runs-snapshots-list` gives you both: pass its `run_id` as `id`, and its `identifier` as+ `identifier`. Passing the snapshot's own `id` as `id` does not work, and neither parameter can be left out.+ param_overrides:+ id:+ description: >+ UUID of the visual review run to look the snapshot up from — a run id, not the `id` of a snapshot+ inside the run. Use the snapshot's `run_id`, or a run id from `visual-review-runs-list`. Required,+ and `identifier` is required alongside it.+ aliases:+ - run_id+ identifier:+ description: >+ Identifier of the snapshot to trace, for example a Storybook story id plus theme. Copy the+ `identifier` field of a snapshot in the run — it is a name, not a UUID. Required in addition to+ `id`; without it the call is rejected rather than returning history for the whole run.feature_flag: visual-reviewvisual-review-runs-snapshots-list:operation: visual_review_runs_snapshots_list@@ -364,7 +379,22 @@ tools:idempotent: truetitle: List tolerated hashesdescription: >- List known tolerated alternate hashes for a snapshot `identifier` in the run's repo. Tolerated hashes- catalog acceptable rendering variants (e.g. anti-aliasing noise) so future runs don't flag them as changes.- Requires `identifier` query parameter.+ List known tolerated alternate hashes for one snapshot in the run's repo. Tolerated hashes catalog+ acceptable rendering variants (e.g. anti-aliasing noise) so future runs don't flag them as changes. This+ covers a single snapshot, not the whole run or repo. Both parameters are required, and one snapshot from+ `visual-review-runs-snapshots-list` gives you both: pass its `run_id` as `id`, and its `identifier` as+ `identifier`.+ param_overrides:+ id:+ description: >+ UUID of the visual review run whose repo holds the tolerated hashes — a run id, not the `id` of a+ snapshot inside the run. Use the snapshot's `run_id`, or a run id from `visual-review-runs-list`.+ Required, and `identifier` is required alongside it.+ aliases:+ - run_id+ identifier:+ description: >+ Identifier of the snapshot whose tolerated hashes you want, for example a Storybook story id plus+ theme. Copy the `identifier` field of a snapshot in the run — it is a name, not a UUID. Required in+ addition to `id`; there is no way to list every tolerated hash in the repo from this tool.feature_flag: visual-reviewdiff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.jsonindex 2eea0968a4d1..ba13bfe72884 100644--- a/services/mcp/schema/generated-tool-definitions.json+++ b/services/mcp/schema/generated-tool-definitions.json@@ -11939,7 +11939,7 @@"feature_flag": "visual-review"},"visual-review-runs-snapshot-history-list": {- "description": "List recent change history for a snapshot `identifier` across previous runs in the same repo. Useful for diagnosing flaky snapshots — if the same identifier flips between changed and clean across runs, it is a candidate for tolerated hashes or quarantine. Requires `identifier` query parameter.",+ "description": "List recent change history for one snapshot across previous runs in the same repo. Useful for diagnosing flaky snapshots — if the same identifier flips between changed and clean across runs, it is a candidate for tolerated hashes or quarantine. Both parameters are required, and one snapshot from `visual-review-runs-snapshots-list` gives you both: pass its `run_id` as `id`, and its `identifier` as `identifier`. Passing the snapshot's own `id` as `id` does not work, and neither parameter can be left out.","category": "Visual review","feature": "visual_review","summary": "Snapshot change history",@@ -11984,7 +11984,7 @@"feature_flag": "visual-review"},"visual-review-runs-tolerated-hashes-list": {- "description": "List known tolerated alternate hashes for a snapshot `identifier` in the run's repo. Tolerated hashes catalog acceptable rendering variants (e.g. anti-aliasing noise) so future runs don't flag them as changes. Requires `identifier` query parameter.",+ "description": "List known tolerated alternate hashes for one snapshot in the run's repo. Tolerated hashes catalog acceptable rendering variants (e.g. anti-aliasing noise) so future runs don't flag them as changes. This covers a single snapshot, not the whole run or repo. Both parameters are required, and one snapshot from `visual-review-runs-snapshots-list` gives you both: pass its `run_id` as `id`, and its `identifier` as `identifier`.","category": "Visual review","feature": "visual_review","summary": "List tolerated hashes",diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.jsonindex ff97e2daa112..8868969b969f 100644--- a/services/mcp/schema/tool-definitions-all.json+++ b/services/mcp/schema/tool-definitions-all.json@@ -12567,7 +12567,7 @@"feature_flag": "visual-review"},"visual-review-runs-snapshot-history-list": {- "description": "List recent change history for a snapshot `identifier` across previous runs in the same repo. Useful for diagnosing flaky snapshots — if the same identifier flips between changed and clean across runs, it is a candidate for tolerated hashes or quarantine. Requires `identifier` query parameter.",+ "description": "List recent change history for one snapshot across previous runs in the same repo. Useful for diagnosing flaky snapshots — if the same identifier flips between changed and clean across runs, it is a candidate for tolerated hashes or quarantine. Both parameters are required, and one snapshot from `visual-review-runs-snapshots-list` gives you both: pass its `run_id` as `id`, and its `identifier` as `identifier`. Passing the snapshot's own `id` as `id` does not work, and neither parameter can be left out.","category": "Visual review","feature": "visual_review","summary": "Snapshot change history",@@ -12612,7 +12612,7 @@"feature_flag": "visual-review"},"visual-review-runs-tolerated-hashes-list": {- "description": "List known tolerated alternate hashes for a snapshot `identifier` in the run's repo. Tolerated hashes catalog acceptable rendering variants (e.g. anti-aliasing noise) so future runs don't flag them as changes. Requires `identifier` query parameter.",+ "description": "List known tolerated alternate hashes for one snapshot in the run's repo. Tolerated hashes catalog acceptable rendering variants (e.g. anti-aliasing noise) so future runs don't flag them as changes. This covers a single snapshot, not the whole run or repo. Both parameters are required, and one snapshot from `visual-review-runs-snapshots-list` gives you both: pass its `run_id` as `id`, and its `identifier` as `identifier`.","category": "Visual review","feature": "visual_review","summary": "List tolerated hashes",diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex e9622dae09b6..2f38033d4816 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -101073,7 +101073,7 @@ export namespace Schemas {export type VisualReviewRunsSnapshotHistoryListParams = {/**- * Snapshot identifier+ * Identifier of the snapshot to look up, for example a Storybook story id plus theme. Read it from the `identifier` field of a snapshot in the run. It is a name rather than a UUID, and it is required in addition to the run id in the path.*/identifier: string;/**@@ -101103,7 +101103,7 @@ export namespace Schemas {export type VisualReviewRunsToleratedHashesListParams = {/**- * Snapshot identifier+ * Identifier of the snapshot to look up, for example a Storybook story id plus theme. Read it from the `identifier` field of a snapshot in the run. It is a name rather than a UUID, and it is required in addition to the run id in the path.*/identifier: string;/**diff --git a/services/mcp/src/generated/visual_review/api.ts b/services/mcp/src/generated/visual_review/api.tsindex dedb6f457ec7..011c522e2824 100644--- a/services/mcp/src/generated/visual_review/api.ts+++ b/services/mcp/src/generated/visual_review/api.ts@@ -213,7 +213,11 @@ export const VisualReviewRunsFinalizeCreateBody = () => zod.object({* Recent change history for a snapshot identifier across runs.*/export const VisualReviewRunsSnapshotHistoryListParams = () => zod.object({- id: zod.string(),+ id: zod+ .string()+ .describe(+ 'UUID of the visual review run to look the snapshot up from. This is a run id, not the `id` of a snapshot inside that run. The run supplies the repo and run type to search, so the `identifier` query parameter is required alongside it.'+ ),project_id: zod.string().describe(@@ -222,7 +226,11 @@ export const VisualReviewRunsSnapshotHistoryListParams = () => zod.object({})export const VisualReviewRunsSnapshotHistoryListQueryParams = () => zod.object({- identifier: zod.string().describe('Snapshot identifier'),+ identifier: zod+ .string()+ .describe(+ 'Identifier of the snapshot to look up, for example a Storybook story id plus theme. Read it from the `identifier` field of a snapshot in the run. It is a name rather than a UUID, and it is required in addition to the run id in the path.'+ ),limit: zod.number().optional().describe('Number of results to return per page.'),offset: zod.number().optional().describe('The initial index from which to return the results.'),})@@ -274,7 +282,11 @@ export const VisualReviewRunsTolerateCreateBody = () => zod.object({* List known tolerated hashes for a snapshot identifier.*/export const VisualReviewRunsToleratedHashesListParams = () => zod.object({- id: zod.string(),+ id: zod+ .string()+ .describe(+ 'UUID of the visual review run to look the snapshot up from. This is a run id, not the `id` of a snapshot inside that run. The run supplies the repo and run type to search, so the `identifier` query parameter is required alongside it.'+ ),project_id: zod.string().describe(@@ -283,7 +295,11 @@ export const VisualReviewRunsToleratedHashesListParams = () => zod.object({})export const VisualReviewRunsToleratedHashesListQueryParams = () => zod.object({- identifier: zod.string().describe('Snapshot identifier'),+ identifier: zod+ .string()+ .describe(+ 'Identifier of the snapshot to look up, for example a Storybook story id plus theme. Read it from the `identifier` field of a snapshot in the run. It is a name rather than a UUID, and it is required in addition to the run id in the path.'+ ),limit: zod.number().optional().describe('Number of results to return per page.'),offset: zod.number().optional().describe('The initial index from which to return the results.'),})diff --git a/services/mcp/src/tools/generated/visual_review.ts b/services/mcp/src/tools/generated/visual_review.tsindex 5fbfa86487e8..996b8a91bde7 100644--- a/services/mcp/src/tools/generated/visual_review.ts+++ b/services/mcp/src/tools/generated/visual_review.ts@@ -418,8 +418,18 @@ const visualReviewRunsRetrieve = (): ToolBase<const VisualReviewRunsSnapshotHistoryListSchema = () => {const VisualReviewRunsSnapshotHistoryListParams = orvalSchemas.VisualReviewRunsSnapshotHistoryListParams()const VisualReviewRunsSnapshotHistoryListQueryParams = orvalSchemas.VisualReviewRunsSnapshotHistoryListQueryParams()- return VisualReviewRunsSnapshotHistoryListParams.omit({ project_id: true }).extend(- VisualReviewRunsSnapshotHistoryListQueryParams.shape+ return z.preprocess(+ normalizeParamAliases({ id: ['run_id'] }),+ VisualReviewRunsSnapshotHistoryListParams.omit({ project_id: true })+ .extend(VisualReviewRunsSnapshotHistoryListQueryParams.shape)+ .extend({+ id: VisualReviewRunsSnapshotHistoryListParams.shape['id'].describe(+ "UUID of the visual review run to look the snapshot up from — a run id, not the `id` of a snapshot inside the run. Use the snapshot's `run_id`, or a run id from `visual-review-runs-list`. Required, and `identifier` is required alongside it."+ ),+ identifier: VisualReviewRunsSnapshotHistoryListQueryParams.shape['identifier'].describe(+ 'Identifier of the snapshot to trace, for example a Storybook story id plus theme. Copy the `identifier` field of a snapshot in the run — it is a name, not a UUID. Required in addition to `id`; without it the call is rejected rather than returning history for the whole run.'+ ),+ }))}@@ -509,8 +519,18 @@ const visualReviewRunsTolerateCreate = (): ToolBase<const VisualReviewRunsToleratedHashesListSchema = () => {const VisualReviewRunsToleratedHashesListParams = orvalSchemas.VisualReviewRunsToleratedHashesListParams()const VisualReviewRunsToleratedHashesListQueryParams = orvalSchemas.VisualReviewRunsToleratedHashesListQueryParams()- return VisualReviewRunsToleratedHashesListParams.omit({ project_id: true }).extend(- VisualReviewRunsToleratedHashesListQueryParams.shape+ return z.preprocess(+ normalizeParamAliases({ id: ['run_id'] }),+ VisualReviewRunsToleratedHashesListParams.omit({ project_id: true })+ .extend(VisualReviewRunsToleratedHashesListQueryParams.shape)+ .extend({+ id: VisualReviewRunsToleratedHashesListParams.shape['id'].describe(+ "UUID of the visual review run whose repo holds the tolerated hashes — a run id, not the `id` of a snapshot inside the run. Use the snapshot's `run_id`, or a run id from `visual-review-runs-list`. Required, and `identifier` is required alongside it."+ ),+ identifier: VisualReviewRunsToleratedHashesListQueryParams.shape['identifier'].describe(+ 'Identifier of the snapshot whose tolerated hashes you want, for example a Storybook story id plus theme. Copy the `identifier` field of a snapshot in the run — it is a name, not a UUID. Required in addition to `id`; there is no way to list every tolerated hash in the repo from this tool.'+ ),+ }))}diff --git a/services/mcp/tests/unit/visual-review-snapshot-lookup-params.test.ts b/services/mcp/tests/unit/visual-review-snapshot-lookup-params.test.tsnew file mode 100644index 000000000000..cde2e7b57127--- /dev/null+++ b/services/mcp/tests/unit/visual-review-snapshot-lookup-params.test.ts@@ -0,0 +1,36 @@+import { describe, expect, it } from 'vitest'++import { GENERATED_TOOLS } from '@/tools/generated/visual_review'++// Both run-scoped snapshot lookups need a run id AND a snapshot identifier. Production+// traces show agents holding one snapshot row and sending only part of that pair: its+// `run_id` key instead of `id`, or `id` alone with no `identifier`. The alias covers the+// first; the second must keep failing rather than quietly widening to the whole run.+describe('visual review snapshot lookup params', () => {+ const RUN_ID = '3f1c9f0e-2b7a-4a5f-9c1d-8e6b2a4f7d31'++ describe.each([['visual-review-runs-snapshot-history-list'], ['visual-review-runs-tolerated-hashes-list']])(+ '%s',+ (toolName) => {+ const schema = GENERATED_TOOLS[toolName]!().schema++ it.each([+ ['id', { id: RUN_ID, identifier: 'Button--default' }],+ ['run_id', { run_id: RUN_ID, identifier: 'Button--default' }],+ ])('accepts the run id as %s', (_label, input) => {+ const result = schema.safeParse(input)+ expect(result.success).toBe(true)+ const data = result.data as Record<string, unknown>+ expect(data.id).toBe(RUN_ID)+ expect(data).not.toHaveProperty('run_id')+ })++ it.each([+ ['identifier is omitted', { id: RUN_ID }],+ ['the run id is omitted', { identifier: 'Button--default' }],+ ])('rejects the call when %s', (_label, input) => {+ expect(schema.safeParse(input).success).toBe(false)+ })+ }+ )+})