BC5 readiness: TypeScript live wire-capture canary
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);mockResponsesconditionally 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.tsloads only mock tests;live-runner.test.tsloads only live tests, skips entirely withoutBASECAMP_LIVE=1. - Wire capture (
wire-capture.ts): wrapsglobalThis.fetch— single chokepoint for bothopenapi-fetch(page 1) and thefetchPageclosure (page 2+). SDK behavior unchanged. - Schema validation (
schema-validator.ts): ajv + ajv-formats.additionalPropertiespermissive (forward-compat doesn't break canary);requiredstrict;$refresolved againstopenapi.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 forTODOSET_ID,TODOLIST_ID,TODO_ID. - Dispatch coverage gate (
live-dispatch.ts):assertDispatchCoverage()fires inbeforeAll. 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_DIRis set, per-test snapshots write to<dir>/<backend>/wire/<test>.jsonfor downstream replay (PR 3) and pairwise comparison (PR 4). make conformance-typescript-live: opt-in target; not invoked bymake check.- CONTRIBUTING.md "Live canary": env vars, snapshot dir layout, fixture/dispatch pairing rule.
Acceptance bar
Per the scope guard:
- Mode-gated —
BASECAMP_LIVEunset → 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.tsskipped,runner.test.ts63 mock tests pass + 5 pre-existing TS_SDK_SKIPS. -
BASECAMP_LIVE=1 npx vitest run live-runner.test.ts(no token) — fails fast inbeforeAllwith a clear missing-env-var error. - Coverage gate: temporarily added
NoSuchOperationto 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-liveagainst 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-compatorchestrator + 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, andfixtureIdswith mode‑specific requirements; newconformance/tests/live-my-surface.json(~10 read endpoints). - TypeScript live runner wraps
globalThis.fetch, validates withajv+ajv-formats, unions extras in the run summary, and persists snapshots toLIVE_RECORD_DIR/<backend>/wire/*.json; gated byBASECAMP_LIVE=1withBASECAMP_TOKEN/BASECAMP_ACCOUNT_ID;BASECAMP_HOSTis origin‑only and the runner appends/{accountId};make conformance-typescript-livetarget 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 tomode: "mock"at load time.
- Conformance schema adds
-
Bug Fixes
- Validator: rewrites local
$reftoopenapi.json#/…, resolves multi‑level$refchains, 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.skipfor 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-urito 3.1.4 to clear advisories.
- Validator: rewrites local