Skip to content

Phase 3: shared wire-contract foundation (#898) - #938

Merged
neuromechanist merged 2 commits into
feature/issue-896-epic-arch-hardeningfrom
feature/issue-898-phase3-contract
Jul 6, 2026
Merged

neuromechanist merged 2 commits into
feature/issue-896-epic-arch-hardeningfrom
feature/issue-898-phase3-contract

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Summary

The flagship of #896: a single, enforced source of truth for the wire shapes the CLI, website, data plane, and third parties (EEGDash) exchange. Foundation only — the known drift fixes (getCurrentUser, file_size, latest_version, /datasets/:id parity) land in #899.

  • shared/contract/ — zero-dependency-beyond-zod, no imports from src//backend/, so it lifts verbatim into a standalone @nemar/contract package later (937 tracks that). version.ts (canonical toVersionTag/versionTagSchema — kills the latest/latest_version + vv1.0.0 split), user.ts (the {user, token} /users/me envelope), dataset.ts (catalog/detail/search + a neuroschema-v0.3.0-conformant dataset schema; NEUROSCHEMA_VERSION single-sourced).
  • data-router.ts single-sources toVersionTag + NEUROSCHEMA_VERSION from the contract (re-exports toVersionTag so routes/data.ts is untouched).
  • CLI request<T> gains an optional Zod schema param: validates the response and throws on drift instead of silently casting to a malformed T.
  • neuroschema conformance is ENFORCED: a vendored, self-contained v0.3.0 bundle (build-vendor.mjs, 20 transitive schemas) + an ajv 2020-12 conformance test.
  • CI contract test (contract-live, TEST_API_URL-gated): live catalog/detail/search/users-me validated against the Zod schemas; data-plane metadata against the neuroschema bundle (warn-only until Phase 4: Fix known contract drift — file_size (#895), getCurrentUser, /datasets/:id parity (#864) #899 fixes drift).

Test plan

  • contract-schemas (10) + contract-neuroschema (5) pass; contract-live skips without TEST_API_URL.
  • Full backend unit suite (410) + CLI data-route/api-export-surface (167) green — single-sourcing changed nothing observable.
  • tsc (root + backend) + Biome clean. Schemas are .passthrough() + coercing, so they validate today's responses (green) while documenting the canonical shape.

Part of epic #896. Foundation for #899.

Epic #896 Phase 3 (#898). Foundation only; drift FIXES land in #899.
- shared/contract/ (zero-dep-beyond-zod, extraction-ready for @nemar/contract):
  version.ts (canonical toVersionTag/versionTagSchema), user.ts (the {user,
  token} /users/me envelope), dataset.ts (catalog/detail/search + neuroschema-
  conformant dataset schema; NEUROSCHEMA_VERSION single source).
- data-router.ts single-sources toVersionTag + NEUROSCHEMA_VERSION from the
  contract (re-exports toVersionTag so routes/data.ts is unaffected).
- CLI request<T> gains an optional Zod schema param: validates the response and
  fails loud on drift instead of silently casting (the getCurrentUser class).
- neuroschema conformance ENFORCED: vendored self-contained v0.3.0 bundle
  (build-vendor.mjs, 20 schemas) + ajv 2020-12 conformance test.
- CI contract test (contract-live, TEST_API_URL-gated) validates live catalog/
  detail/search/users-me against the Zod schemas; data-plane metadata against
  the neuroschema bundle (warn-only until #899 fixes drift).
- Tests: contract-schemas (10), contract-neuroschema (5). ajv added as devdep.
- CRITICAL: searchHitSchema keyed on dataset_id, but /datasets/search
  aliases d.dataset_id AS id and has no latest_version -> would have failed
  integration-dev CI on any non-empty search. Rewrote to the real SearchResult
  shape (id required, nullable raw columns, score/snippet). Added fixture tests.
- catalogItemSchema.id made optional (?mine=true branch omits the alias).
- datasetDetailSchema overrides file_size/modalities/tasks/authors/license to
  nullable (detail query is raw d.*, no COALESCE, unlike the list query).
- data-plane neuroschema live check is now fully warn-only (recording_modality
  can be [] pre-classification); #899 flips to hard-fail after the drift fix.
@neuromechanist

Copy link
Copy Markdown
Contributor Author

Review (sonnet) — findings addressed in b697a7a

  • [critical] searchHitSchema required dataset_id, but /datasets/search keys on id (d.dataset_id AS id) with no latest_version — would have deterministically failed integration-dev CI on any non-empty search. Rewrote to the real SearchResult shape + added fixture tests (the gap that let it slip).
  • [important] datasetDetailSchema now overrides file_size/modalities/tasks/authors/license to nullable (the /datasets/:id query is raw d.*, no COALESCE unlike the list query).
  • [important] catalogItemSchema.id made optional (?mine=true omits the AS id alias).
  • [moderate] data-plane neuroschema live check is now fully warn-only (recording_modality can be [] pre-classification); Phase 4: Fix known contract drift — file_size (#895), getCurrentUser, /datasets/:id parity (#864) #899 flips to hard-fail.
  • [suggestions] ApiError statusCode kept as response.status (validation runs only on 2xx, so no 401-branch collision; {issues} distinguishes it). strictVersionTagSchema kept as forward-looking surface. Reviewer confirmed clean: toVersionTag re-export byte-identical, request no-op when schema omitted, bundle regenerates identical from [email protected], ajv strict:false doesn't disable data constraints, ajv is devDep-only.

This branch was previously deployed

1 inactive deployment
npm — b697a7ad Deployed Jul 6, 2026 by neuromechanist via publish #1697
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant