Freshness gates: regenerate-and-diff for TS, Ruby, and Go generated output

Merged
JE
4mo ago
+370-8

What

Adds non-mutating regenerate-and-diff freshness gates for the three SDKs whose make check entry was coverage/typecheck-only, mirroring the existing check-swift-service-drift.sh / check-python-service-drift.sh:

  • scripts/check-typescript-service-drift.sh — the whole src/generated/ tree (stripped OpenAPI, schema, metadata, path-mapping, generated services)
  • scripts/check-ruby-service-drift.sh — metadata.json, types.rb, generated services (base_service.rb excluded as hand-written)
  • scripts/check-go-generated-drift.sh — client.gen.go after the normalize-go-deprecation-godoc.sh pass; distinct from check-service-drift.sh (operation-level coverage) and check-wrapper-drift (field-level)

Wired into root make check (Go standalone in the drift cluster; TS/Ruby as deps of ts-check/rb-check, like py-check-drift) plus each SDK's CI job. The Ruby CI step runs only on the canonical 3.3 matrix entry since generated output is Ruby-version independent.

Why

Each of these make check entries was coverage/typecheck-only, so a committed generated artifact could silently drift from the current generator/spec without failing make check. These gates close that hole for TS, Ruby, and Go, matching what Swift/Python already had.

Design notes

All three are fully non-mutative — they regenerate entirely into temp locations and never touch the committed working tree. That gives both make -j race-safety (a gate can't rewrite a tree while a sibling check target reads it) and correct extra-file detection (regenerating into an empty tree makes stale committed files surface as drift). How each redirects generation out-of-tree:

  • Ruby generators accept --output/stdout → emit straight to a temp dir.
  • Go's oapi-codegen honors its config output: and ignores -o, so the gate writes a throwaway config whose output: points at a temp file.
  • TS's pipeline resolves output paths from the generator scripts' own location (import.meta __dirname), so the gate assembles a throwaway project outside the repo — the real scripts, a symlinked node_modules, and a copy of openapi.json placed where the pipeline's ../openapi.json resolves — and runs the committed npm run generate + generate-services verbatim there (robust to pipeline changes).

Timestamps: Ruby metadata.json/types.rb and TS metadata.ts embed a wall-clock generated stamp; those single lines are canonicalized before diffing so a re-run isn't mistaken for drift. Go and the other TS artifacts are deterministic and compared verbatim. Generator stderr is preserved and printed on failure.

Kotlin stays a CI-only exception: kt-check-drift remains an operation-level coverage check at root, while its authoritative regenerate-and-diff runs in the test-kotlin CI job. Documented in the Makefile; promoting it to a root-invocable non-mutating gate is a follow-up.

No SDK-source changes.

Verification

  • 3 gates exit 0 on clean main; non-mutative (working tree untouched after every run)
  • Negative proofs: content drift, extra file at services/ and at the generated-tree root, timestamp-only change ignored, failure-path (broken openapi.json) exits 1 with diagnostics and leaves the tree untouched
  • make check → green; make -j check → green (full 5-language conformance)
  • shellcheck clean; actionlint clean

Context

Part of the post-0.9.0 retry-contract follow-up program — the ship-now item, independent of the held retry-behavior work.


Summary by cubic

Adds non-mutating regenerate-and-diff freshness gates for TypeScript, Ruby, and Go generated code to prevent drift. Runs in temp dirs, detects missing and extra files (including non-.rb artifacts in Ruby services), is safe under parallel make, and now guards missing Ruby artifacts and asserts Go output redirection.

  • New Features

    • TypeScript: scripts/check-typescript-service-drift.sh regenerates the entire src/generated/ tree and diffs; normalizes the generated stamp in metadata.ts.
    • Ruby: scripts/check-ruby-service-drift.sh regenerates metadata.json, types.rb, and snapshots the whole generated/services/ tree for diffing (excludes hand-written base_service.rb); normalizes timestamps; detects missing files cleanly.
    • Go: scripts/check-go-generated-drift.sh regenerates client.gen.go via a temp oapi-codegen config, asserts the output: redirect before running, applies normalize-go-deprecation-godoc.sh, and uses separate logs per phase.
  • CI and Makefile

    • New targets: ts-check-drift, rb-check-drift, go-check-generated-drift; wired into ts-check, rb-check, and root make check.
    • CI runs the new gates for TS, Ruby (only on 3.3), and Go; Kotlin unchanged (regen-and-diff remains CI-only).