Skip to content

Validate catalog and detail responses against the shared contract outside tests #1207

Closed

Description

@neuromechanist

Problem

`catalogItemSchema` and `datasetDetailSchema` in `shared/contract/dataset.ts` carry cross-field invariants via `superRefine` (for example `zarr_index_url` only when `zarr_status` is ready, and `zarr_verified_at` requiring a verify status), and `test/contract-schemas.test.ts` plus `backend/test/catalog-has-zarr.test.ts` exercise them thoroughly. But no route ever parses a live response with these schemas, so a production regression in a derive path (for instance a future write that sets `zarr_index_url` directly instead of deriving it) would ship data the contract calls invalid and only surface when a consumer's own parse throws.

Raised by the type-design review of #1206. It is a pre-existing architectural gap, not something the epic introduced, so it is filed rather than fixed there.

Proposed work

  • A response-validation hook for `GET /datasets` and `GET /datasets/:id` that parses with the shared schemas when `ENVIRONMENT` is `development` or `test` and logs (never fails) a violation in production.
  • A sampled production mode (for example one in N responses) if the parse cost matters at catalog page sizes.
  • A test proving a deliberately invalid row is caught by the hook in the dev environment.

Activity

  1. neuromechanist commented on Sep 3, 2026

    @neuromechanist
    ContributorAuthor

    Additional data point from the #1206 fix pass: the detail route serves SELECT d.*, so id arrives numeric while datasetDetailSchema declares a string. The new callback-to-detail round-trip test in the backend suite has to stringify id before parsing and names this issue in a comment. A response-validation hook would have caught it.

  2. neuromechanist commented on Sep 3, 2026

    @neuromechanist
    ContributorAuthor

    Fixed in #1224 (dev commit 082a1bd); ships with the next dev to main release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions