Skip to content

ci(typescript): ts-rs binding drift guard (task #62) - #1626

Merged
joelteply merged 1 commit into
canaryfrom
ci/ts-rs-binding-drift-guard
Jun 15, 2026
Merged

joelteply merged 1 commit into
canaryfrom
ci/ts-rs-binding-drift-guard

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Summary

Implements task #62: substrate-doctrine CI guard against ts-rs binding drift. The substrate has Rust types annotated with #[derive(TS)] and #[ts(export_to = "../../../protocol/typescript/...")]. cargo test regenerates those .ts files as a side effect. When an author adds a field or variant to a Rust type but forgets to commit the regenerated .ts, the wire shape drifts silently:

  • Mac/Linux dev: cargo test regenerates locally, looks fine, ships PR without the .ts in the diff.
  • Reviewer: sees only the Rust change, approves.
  • Downstream TS consumer at runtime: hits the new variant / missing field; no compile-time guard fires.

Today's session had a near-miss on continuum #1624 (Mac Intel classify_silicon fix) — TargetSilicon gained MacIntelMetal but the regenerated protocol/typescript/governor/TargetSilicon.ts was not in the initial push. I had to amend. This guard makes that mistake impossible to land.

Changes

.github/workflows/ts-rs-binding-drift-guard.yml:

ts-rs binding drift detected. Some Rust types were modified but their
regenerated TypeScript bindings (in protocol/typescript/) were not
committed.

Fix: run cargo test locally to regenerate, then:
  git add protocol/typescript/
  git commit --amend --no-edit
  git push --force-with-lease

Composes

Test plan

  • CI green on this PR (no Rust changes ⇒ no regeneration ⇒ no drift).
  • Future PR that modifies a #[derive(TS)] Rust type without committing the regenerated .ts gets a red gate with the fix recipe.
  • After ci(rust): cargo test -p continuum-core --lib on every PR #1616 lands, both the unit-test gate AND this drift gate run on every PR — substrate hygiene by default.

🤖 Generated with Claude Code

The substrate has Rust types with `#[derive(TS)]` + `#[ts(export_to =
"../../../protocol/typescript/...")]` attributes. `cargo test`
regenerates those .ts files as a side effect of running per-type
`export_bindings_*` tests.

When an author adds a new field or variant to a Rust type but forgets
to commit the regenerated .ts file, the wire shape drifts silently:

  - Mac/Linux dev: cargo test regenerates locally, looks fine, ships
    PR without the .ts in the diff.
  - Reviewer: sees only the Rust change, approves.
  - Downstream TS consumer at runtime: hits the new variant / missing
    field; no compile-time guard fires (the .ts file is stale).

Today's session had a near-miss on continuum #1624 (Mac Intel
classify_silicon fix): TargetSilicon gained the MacIntelMetal variant
but the regenerated `protocol/typescript/governor/TargetSilicon.ts`
was not in the initial push. Had to amend.

Adds `.github/workflows/ts-rs-binding-drift-guard.yml`:
  - triggers on PRs touching Cargo, rust-toolchain, core/**, or
    protocol/typescript/** (a TS edit needs the gate too — it must
    match the Rust source);
  - picks up Rust 1.95 from rust-toolchain.toml (#1614);
  - runs ONLY the `export_bindings_*` tests (cheap — same skip
    patterns as #1616's CI gate so GPU/env-var tests don't sink it);
  - then `git diff --exit-code protocol/typescript/`. Non-empty diff
    means the test run regenerated bindings that the PR did NOT
    commit. Fail with a verbatim fix-recipe in the error log.

Composes with:
  - #1614 toolchain pin (Rust version)
  - #1616 unit-test CI gate (same skip patterns)
  - #1624 (the near-miss this workflow would have caught at CI)

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@joelteply
joelteply merged commit e4e4018 into canary Jun 15, 2026
3 checks passed
@joelteply
joelteply deleted the ci/ts-rs-binding-drift-guard branch June 15, 2026 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant