BC5 readiness: TypeScript live wire-capture canary

Merged
JE
4mo ago
+1690-11

Stacked on #293. Merge target: bc5-readiness-spec-foundations. Will be re-targeted to main once #293 lands.

Summary

The TypeScript runner becomes the canonical wire-capturer for the SDK's compatibility canary. It dispatches each live test through the SDK's typed surface, intercepts the raw HTTP response at the global fetch chokepoint, and validates the body against the OpenAPI response schema.

Strictly the TS layer of the multi-language canary plan: cross-language replay and pairwise BC4↔BC5 comparison are deferred to follow-up PRs.

What lands

  • Schema extension (conformance/schema.json): mode: "mock" | "live" (default mock); mockResponses conditionally required; liveAssertions[] with four assertion types; fixtureIds[] for placeholder resolution.
  • Live fixture (conformance/tests/live-my-surface.json): 10 operations covering the read surface BC5 forward-compat additions touch (GetMyNotifications, GetTodoset, GetMyProfile, etc.).
  • Mode gating: runner.test.ts loads only mock tests; live-runner.test.ts loads only live tests, skips entirely without BASECAMP_LIVE=1.
  • Wire capture (wire-capture.ts): wraps globalThis.fetch — single chokepoint for both openapi-fetch (page 1) and the fetchPage closure (page 2+). SDK behavior unchanged.
  • Schema validation (schema-validator.ts): ajv + ajv-formats. additionalProperties permissive (forward-compat doesn't break canary); required strict; $ref resolved against openapi.json. Per-page validation; extras union across pages and surface in the run summary.
  • Fixture-ID resolution (fixtures.ts): env-var → discovery → cache ladder (§5d). BASECAMP_BC4_PROJECT_ID → BASECAMP_PROJECT_ID → ListProjects → first project, same for TODOSET_ID, TODOLIST_ID, TODO_ID.
  • Dispatch coverage gate (live-dispatch.ts): assertDispatchCoverage() fires in beforeAll. Any operation in the fixture without a dispatch case fails the run with a pointer to where to add the mapping.
  • Snapshot persistence: when LIVE_RECORD_DIR is set, per-test snapshots write to <dir>/<backend>/wire/<test>.json for downstream replay (PR 3) and pairwise comparison (PR 4).
  • make conformance-typescript-live: opt-in target; not invoked by make check.
  • CONTRIBUTING.md "Live canary": env vars, snapshot dir layout, fixture/dispatch pairing rule.

Acceptance bar

Per the scope guard:

  • Mode-gated — BASECAMP_LIVE unset → mock only; set → live only.
  • Captures raw response bytes/headers at the global fetch boundary.
  • Validates with Ajv against the generated OpenAPI schema (per page, with extras-observed reporting).
  • Deterministic fixture naming — snapshots are namespaced by BASECAMP_BACKEND.
  • Runs against BC4 or BC5 without doing pairwise comparison yet.
  • Cross-language replay and BC4/BC5 diffing remain out.

Test plan

  • make conformance-typescript (default, no live env) — live-runner.test.ts skipped, runner.test.ts 63 mock tests pass + 5 pre-existing TS_SDK_SKIPS.
  • BASECAMP_LIVE=1 npx vitest run live-runner.test.ts (no token) — fails fast in beforeAll with a clear missing-env-var error.
  • Coverage gate: temporarily added NoSuchOperation to the fixture; runner refused to start with: Live runner is missing dispatch cases for: NoSuchOperation. Add a DispatchFn to LIVE_OPERATIONS in live-dispatch.ts. Reverted before commit.
  • Manual: BASECAMP_LIVE=1 BASECAMP_TOKEN=... BASECAMP_ACCOUNT_ID=... BASECAMP_HOST=... LIVE_RECORD_DIR=tmp/live-canary/bc4 BASECAMP_BACKEND=bc4 make conformance-typescript-live against a real BC4 sandbox. (Requires sandbox creds — reviewer to confirm or defer to follow-up.)

Out of scope (later PRs)

  • PR 3: cross-language wire-replay decoders (Ruby/Python/Go/Kotlin).
  • PR 4: pairwise BC4↔BC5 comparison + make check-bc5-compat orchestrator + scheduled CI.
  • PR 5: API gap detector tooling (scripts/detect-api-gaps.sh).

Summary by cubic

Adds a TypeScript live wire-capture canary that validates raw API responses against the OpenAPI schema, collapses same‑URL retries, pre‑resolves fixtures, and writes snapshots for replay. Live runs are opt‑in; offline runners load only mock tests.

  • New Features

    • Conformance schema adds mode (mock/live), liveAssertions, and fixtureIds with mode‑specific requirements; new conformance/tests/live-my-surface.json (~10 read endpoints).
    • TypeScript live runner wraps globalThis.fetch, validates with ajv + ajv-formats, unions extras in the run summary, and persists snapshots to LIVE_RECORD_DIR/<backend>/wire/*.json; gated by BASECAMP_LIVE=1 with BASECAMP_TOKEN/BASECAMP_ACCOUNT_ID; BASECAMP_HOST is origin‑only and the runner appends /{accountId}; make conformance-typescript-live target and CONTRIBUTING docs added.
    • Dispatch coverage gate uses Object.hasOwn; fixture IDs resolve via env → discovery → cache and are pre‑resolved before capture; Go/Ruby/Python/Kotlin filter to mode: "mock" at load time.
  • Bug Fixes

    • Validator: rewrites local $ref to openapi.json#/…, resolves multi‑level $ref chains, finds non‑200 2xx schemas (e.g., 201), treats bodyless 2xx (204‑only ops) as success and flags bodies there as drift, and collects extras recursively through arrays/objects.
    • Live runner: fixes required‑field checks through arrays with repeated segments, uses testCtx.skip for missing fixtures, keeps discovery traffic out of snapshots, and collapses consecutive same‑URL retries so only the final attempt is recorded.
    • Offline tests cover the validator, wire‑capture, and dispatch gate paths; dependencies bump transitive fast-uri to 3.1.4 to clear advisories.