BC5 readiness: cross-language wire-replay decoders

Merged
JE
4mo ago
+2421-18

Summary

Companion to #294 (TS canonical wire-capture canary). Adds wire-replay mode to the Ruby, Python, Go, and Kotlin runners so they consume the canonical wire snapshots TS captures against a live backend, decode each page through their SDK, and walk the raw JSON for required-field + extras detection. Swift remains excluded from the live canary surface.

The architecture pairs with §5e/5f of the BC5-readiness plan: TS is the only live HTTP runner; everyone else replays from disk. Decode-result snapshots land at <dir>/<backend>/decode/<lang>/ with schema_version: 1.

Per the cross-SDK omnibus pattern, this is one PR with one commit per SDK plus a TS amendment commit (operation field on snapshots) and one infrastructure commit (Make targets + CONTRIBUTING + gitignore).

What ships

  • TS amendment — wire snapshots now carry operation at the top level so replay runners dispatch without re-parsing the live fixture. Backwards compatible at the type level; runtime gates fail loud if a pre-PR3 snapshot shows up.
  • Ruby replay runner — decoder boundary is the SDK's actual production path (JSON.parse + normalize_person_ids).
  • Python replay runner — decoder boundary is json.loads + _normalize_person_ids. Same code path every SDK request runs in production.
  • Go replay runner — decoder boundary is the typed generated.<Op>ResponseContent types from go/pkg/generated. Mode-gate prepended to existing main(); mock-mode body untouched.
  • Kotlin replay runner — decoder boundary is @Serializable data classes via the same Json { ignoreUnknownKeys = true } the mock runner uses. Separate :conformance:runReplay Gradle task; existing :conformance:run untouched. Four ops decode through JsonElement because typed MyAssignment / Notification models don't yet exist (TODO noted).
  • Schema walkers — hand-rolled per-language ports of conformance/runner/typescript/schema-validator.ts's required + extras algorithm. No new library dependencies in any language; using json_schemer/jsonschema/santhosh-tekuri/networknt would create divergent extras semantics across runners.
  • Three startup gates per runner: decoder coverage, snapshot completeness, snapshot recognition. Missing top-level operation is a hard failure pointing at re-running the TS canary.
  • Make targets: conformance-{ruby,python,go,kotlin}-replay, each with required-env preflight (WIRE_REPLAY_DIR, BASECAMP_BACKEND). None run as part of make check.
  • CONTRIBUTING.md gains a "Wire replay (cross-language)" subsection covering the two-stage flow and the five files to update when adding a new operation.

Verification

Cross-language walker parity confirmed end-to-end against synthetic snapshots covering all 10 ops in live-my-surface.json:

$ for lang in ruby python go kotlin; do
    jq -s '[.[].pages[].missing_required] | flatten | sort | unique' \
      tmp/canary/bc4/decode/$lang/*.json > /tmp/missing-$lang.json
  done
$ diff /tmp/missing-ruby.json /tmp/missing-python.json   # empty
$ diff /tmp/missing-ruby.json /tmp/missing-go.json       # empty
$ diff /tmp/missing-ruby.json /tmp/missing-kotlin.json   # empty

The synthetic GetProject {} body produces byte-identical missing_required ([app_url, created_at, id, name, status, updated_at, url]) across all four languages.

schema_version lock:

$ jq -s '[.[].schema_version] | unique' tmp/canary/bc4/decode/*/*.json
[1]

All four mock baselines preserved exactly: Ruby 59, Python 64, Go 68, Kotlin 58 (counts match those documented in #294's plan).

Coverage gate failure modes verified by injection (missing decoder, missing snapshot, unknown operation, pre-PR3 snapshot lacking operation field) — each emits an actionable message pointing at the right side to fix (TS dispatch, fixture, or this runner).

Test plan

  • make conformance-ruby shows 59/0/9
  • make conformance-python shows 64/0/4
  • make conformance-go shows 68/0/0
  • make conformance-kotlin shows 58/0/10
  • make conformance-typescript passes (TS amendment is back-compat)
  • WIRE_REPLAY_DIR=<dir> BASECAMP_BACKEND=bc4 make conformance-<lang>-replay for each language fails preflight when env unset, succeeds against TS-captured snapshots
  • All four runners reject pre-PR3 snapshots (no operation field) with a clear "Re-run the TS live canary" message

Sequencing

PR 4 (pairwise BC4↔BC5 comparison + check-bc5-compat orchestrator + scheduled CI) consumes both the TS canary's <backend>/wire/ snapshots and these decode-result snapshots; it lands separately.


Summary by cubic

Adds cross-language wire-replay for Ruby, Python, Go, and Kotlin using TS-captured snapshots with a top‑level operation. Runners decode via production SDK paths, walk JSON to flag missing required fields and extras, and write per‑test results to support BC5 readiness.

  • New Features

    • TS live runner now persists operation on wire snapshots; it remains authoritative in the payload.
    • Ruby/Python/Go/Kotlin replay runners read <dir>/<backend>/wire/*.json, decode via production SDK paths, and write to <dir>/<backend>/decode/<lang>/ with schema_version: 1. Walkers emit missing_required (slash paths) and extras_seen (dot paths). Kotlin decodes four My*/notifications ops as JsonElement.
    • Make targets: conformance-{ruby,python,go,kotlin}-replay (Kotlin also via :conformance:runReplay). CONTRIBUTING documents the two‑stage flow.
  • Bug Fixes

    • Faithful empty‑body handling: Ruby now errors on empty bodyText; Python/Go distinguish missing vs empty bodyText so empty bodies trigger decode errors.
    • Gates and diagnostics: all runners surface snapshot read/parse errors; Python flags malformed UTF‑8; Kotlin treats blank env as missing, defensively reads non‑primitive operation/bodyText, narrows decoder catch to Exception, and sorts snapshot files. All runners reject snapshots with missing/empty pages or pages_count mismatches.
    • Response schema lookup precedence aligned across TS and all walkers: prefer 200–204, then any other 2xx, then default.