Skip to content

ci(contracts): fail the gate when the generated types or the English mirror drift from SahajCloud - #310

Closed
sydevs-bot wants to merge 3 commits into
mainfrom
claude/ci-contract-drift-gate
Closed

sydevs-bot wants to merge 3 commits into
mainfrom
claude/ci-contract-drift-gate

Conversation

@sydevs-bot

@sydevs-bot sydevs-bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

For a developer: the Lint, Typecheck & Unit job now ends with two blocking steps. One regenerates server/payload-types.ts from SahajCloud main, the other regenerates lib/translations.en.json from production SahajCloud. Each step fails when the committed file differs. Before the diff runs, the job summary lists every drifted key by name: a translation key path, or a type member such as WmWebTranslationsBlocksGeneralStrings.wisdom_sidetext. Nothing changes for a visitor or an editor.

⚠ This PR's own gate is red, and once it merges every PR's gate stays red until all three of these happen: sydevs/SahajCloud#1218 merges and is deployed; blocks.general.wisdom_sidetext has published English in production SahajCloud (the sync drops blank strings); and the re-sync (pnpm types:cms + pnpm sync:translations) lands on main. The user accepted this. A red contract step does not hide anything else: the other gate steps run before it and report as usual.

Current drift, measured with the exact step scripts on this branch rebased onto main c4a7927 on 2026-11-19:

server/payload-types.ts against pnpm types:cms (SahajCloud main): 7 lines removed, nothing added.

lib/translations.en.json against PUBLIC__SAHAJCLOUD_URL=https://cloud.sydevelopers.com pnpm sync:translations (API client 40, 162 strings): +6/−7 lines.

  • Only in the committed file: blocks.general.wisdom_sidetext ("Ancient Wisdom") and common.a11y.opens_in_new_tab ("%{label} (opens in new tab)"). Nothing on main reads the second one.
  • Only in the generated file: common.a11y.menu ("Menu").
  • Different value: lecture.a11y.untitled_heading, "Untitled talk" → "Untitled Lecture".
  • Layout: three committed lines are indented by hand (footer_navigation, primary_navigation, skip_to_main). The generator would re-indent them.

What changed and why

  • F3b: nothing compared either generated file with its producer. On main, typecheck and every test read the committed copy, and tests/guards/translation-keys.test.ts reads only the mirror. That is how wisdom_sidetext, hand-added to both files in 3a318d8 (fix(textbox): the OrnateTextBox header fails AA over the warm band #269), passed every check while the deployed /heart-chakra rendered the key path itself.

    • Step "SahajCloud types match SahajCloud main" (.github/workflows/ci.yml): runs pnpm types:cms, then the summary, then git diff --exit-code server/payload-types.ts.
    • Step "English mirror matches production SahajCloud": does the same with pnpm sync:translations. PUBLIC__SAHAJCLOUD_URL=https://cloud.sydevelopers.com and SAHAJCLOUD_API_KEY (a repository secret the smoke job already uses) are set in that step's env only. Its if: !cancelled() && steps.contract-types.outcome != 'skipped' means it runs even when the types step failed, so one red run names both drifts.
  • Summary script, scripts/contract-drift.ts. It compares the git index (what git diff compares against) with the regenerated working-tree file. It writes the per-key summary to $GITHUB_STEP_SUMMARY and adds an ::error file=… annotation.

    • JSON is compared as dotted key paths.
    • Types are compared through the TypeScript compiler API, by declaration and member path. Nested object literals fold to {…}, so a change is reported once, on the member that changed. A change to a doc comment alone is listed separately. Children of an added or removed parent are not listed again. Lists stop at 40 entries.
    • A difference in layout alone is never called a match.
    • Run time is about 1.5 s on the 11.5k-line types file.
    • Pinned by scripts/contract-drift.test.ts (18 tests). These include the real 2026-11-19 drift shapes, and an end-to-end case in a temporary git repo that checks the index against the working tree and the annotation present or absent. Mutation checks: dropping withoutImpliedChildren fails 1 test, removing the {…} folding fails 3, removing the doc separation fails 1.
  • Decision: placement. The spec said "after pnpm test:run". Both steps sit at the end of gate, after check:wrangler, which is still after test:run. One upstream change reddens every open PR at once. If these steps sat directly after test:run, that failure would also skip ladle:build and check:wrangler on every PR.

  • Decision: secrets. GitHub withholds Actions secrets from a fork's PR and from Dependabot's. On those runs only the translations step skips, with a ::warning:: and a line in the summary. The types step needs no secret and still runs. An empty secret on any other run fails the step, because a deleted secret must not switch the check off unnoticed (the spirit of ci(preview): move the Ladle site to Workers and fail on no preview #184: a skip must never look like a pass).

  • Retries, each bounded (review nit, applied). Each generator gets 4 tries, 5, 10 and 15 s apart, and each try is now wrapped in timeout 60. Neither generator sets a timeout of its own: types:cms is a bare curl -fsSL, and sync-translations calls fetch with no signal. Without the bound, a stalled transfer ran into the job's 15-minute timeout instead of ending on the "not drift" message.

    • Measured against a local listener that accepts connections and never answers: 4 connections, about 270 s, the network ::error, and no orphaned curl.
    • The types failure message now also says that a curl 404 means the upstream path moved, which a re-run cannot fix.
    • The loop lives in the step, not in package.json, which several open PRs edit.
  • Only git diff decides (review nit, applied). GitHub runs run: blocks with bash -e, so a summary script that failed to load (tsx or typescript not resolving, a syntax error) ended the step red before the diff ran, even on a matching file. Each summary call now falls through to a ::warning::. Measured with the script moved aside and a matching file staged: exit 1 before the change, exit 0 after. Three specs in scripts/contract-drift.test.ts pin the workflow:

    • every CONTRACTS file has its own git diff --exit-code line
    • both fetches are run under timeout
    • both summary calls end in ||

    Against the workflow as it was before this change, the last two fail.

  • Review finding, applied: the PR body uses current main. The implementer measured on 5ee6ded. Since then chore(contracts): re-sync copied contracts from SahajCloud #292 and chore(contracts): re-sync copied contracts from SahajCloud #306 (both contract re-syncs), feat(preview): stream unsaved lecture edits into the preview panel #290 and feat(player): move VideoPlayer from Vidstack to Video.js 10 #285 have merged. The branch is rebased onto c4a7927, and the drift above was measured there. On 41079b2, before chore(contracts): re-sync copied contracts from SahajCloud #306 merged, the same step also reported the feat(events): tidy the event form, send signups to the manager only SahajCloud#1198 Event changes, which shows that the gate catches an unsynced upstream merge.

  • Docs.

    • docs/cloudflare-previews-ci.md gets a new section, "The contract gate". It covers what fails, the wisdom_sidetext incident, and the one fix (land the producer first, then regenerate). It warns that one upstream change reddens every open PR and that each PR then needs Update branch, because a re-run reuses its original merge commit. It also covers retries and time bounds, the fork skip, and why the steps sit last.
    • AGENTS.md gets a 4-line pointer under "Commands package.json does not show".
    • docs/rules/rest-api.md and the header of scripts/sync-translations.mjs no longer say the sync is "not run in CI".

Not in this PR

  • The re-sync itself. It waits for feat(translations): declare a key's English in the schema, reconciled on boot SahajCloud#1218 and its published English. Until then the gate is red by design.
  • .claude/workflow.json generatedFiles. It lists only server/payload-types.ts. Adding ^lib/translations\.en\.json$ would make the workflow skills treat the mirror the way CI now does. .claude/ is a protected path, so this is left for a person to edit.
  • A run on GitHub. The steps were parsed (YAML) and syntax-checked (bash -n), then run locally as bash -e with real network and the real key: the match path, the drift path, the fork-skip path, the missing-secret path, the stall path and the broken-summary path. This PR's CI run is their first run on GitHub.
  • No new translation keys are needed.

Reconciled with open PRs

git merge-tree of this branch (on c4a7927) against every open PR branch is clean. This PR does not touch package.json, server/payload-types.ts or lib/translations.en.json.

Test results

.claude/skills/pr-prep/check.sh --full on the rebased branch (c4a7927 + 3 commits):

  • Lint: 0 errors, 1,087 warnings. The two new TypeScript files add none.

  • tsc --noEmit: passed.

  • Vitest: 132 files, 1,293 / 1,293 tests passed, including 18 in scripts/contract-drift.test.ts.

  • pnpm build (client + server): passed.

  • The other CI gate steps, run locally: pnpm ladle:build passed, pnpm check:wrangler (offline dry run) passed, and node scripts/a11y-summary.mjs passed.

  • The new contract steps, run locally exactly as CI runs them:

    • types: exit 1, ::error file=server/payload-types.ts,title=SahajCloud contract drift::…, summary Only in the committed file (1): WmWebTranslationsBlocksGeneralStrings.wisdom_sidetext
    • translations: exit 1, ::error file=lib/translations.en.json,…, with the four keys and the layout note listed above.

    Both are red as intended.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Mg9rjZcE8bs5uRJ6dsg6kw

A red `git diff --exit-code` on server/payload-types.ts or
lib/translations.en.json says only that the file moved. A reviewer needs to
know which contract moved: the translation key path, or the type member.

scripts/contract-drift.ts compares the file in the git index (what
`git diff` compares against) with what the generator just wrote, and puts
the result in the job summary: keys only in the committed file, only in the
generated one, with a different value, and (for the types) with only a
different doc comment. Types are read with the TypeScript compiler API and
keyed by declaration and member path (`TableOfContentsHeadings[].occurrence`),
folding a nested object to `{…}` so a change inside it is reported once, on
the member that changed. A file that differs only in layout is never called
a match. It only reports and always exits 0, so a crash in it cannot redden
a step whose files match; the diff stays the verdict.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjZcE8bs5uRJ6dsg6kw
Nothing compared server/payload-types.ts or lib/translations.en.json with
their producer. Typecheck and every test read the committed copy, so
`blocks.general.wisdom_sidetext`, hand-added to both ahead of
sydevs/SahajCloud#1218, passed every check while the deployed /heart-chakra
rendered the key path itself.

The gate job now ends with two steps. One runs `pnpm types:cms` (SahajCloud
main), the other `pnpm sync:translations` (production SahajCloud); each
summarizes the drifted keys, then `git diff --exit-code` fails on any
difference. They run last so that a SahajCloud change, which reddens every
open PR at once, cannot also skip the Ladle build and the wrangler check, and
the translations step runs even when the types step failed so one run names
both drifts. Each fetch gets four tries and fails with a message saying it is
not drift.

The mirror step needs SAHAJCLOUD_API_KEY. GitHub withholds it from a fork's
pull request and from Dependabot's, where that one step skips with a
warning. Anywhere else an empty secret fails the step, since a deleted secret
would otherwise switch the check off unnoticed.

This is blocking on purpose: main itself fails it until SahajCloud#1218
merges, its English is published, and the re-sync lands.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjZcE8bs5uRJ6dsg6kw
Neither generator sets a timeout: `types:cms` is a bare `curl -fsSL` and
sync-translations calls `fetch` with no signal, whose defaults allow 300 s
for headers alone. A stalled transfer was never retried; it ran into the
gate's 15-minute timeout instead of ending on the "not drift" message. Each
try is now `timeout 60`, so four stalled tries end in about 4.5 minutes with
that message (measured against a listener that never answers: 270 s, four
connections, no orphaned curl).

The summary script promises it never fails the job, but GitHub runs `run:`
blocks with `bash -e`, so a load failure (tsx or typescript not resolving, a
syntax error) ended the step red before `git diff --exit-code` ran, even on a
file that matches. The call now falls through to a warning. Measured with the
script moved aside and a matching file staged: exit 1 before, exit 0 after.

The types step's failure message also names a curl 404 as a moved upstream
path, which a re-run cannot fix. A spec pins the workflow to these shapes and
to one `git diff --exit-code` per contract file.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjZcE8bs5uRJ6dsg6kw
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
wemeditate-web 15072f4 Commit Preview URL

Branch Preview URL
Nov 19 2026, 10:53 PM

@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 19, 2026
@sydevs-bot

sydevs-bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 no session running
CI fix 1

recent dispatches
  • 22:55Z fix-ci · attempt 1 · session · done
  • 22:55Z fix-ci · attempt 1 · session

Written by the sydevs dispatcher. Sessions never edit this comment.

@sydevs-bot sydevs-bot moved this from Awaiting to Working in SYDevelopers Technical Roadmap Nov 19, 2026
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Nothing to fix this pass. The red Lint, Typecheck & Unit is this PR's own two contract steps, failing as the body says they will.

Every earlier step passed: pnpm lint, pnpm typecheck, pnpm test:run, pnpm ladle:build, pnpm check:wrangler.

  • SahajCloud types match SahajCloud main — exit 1 on WmWebTranslationsBlocksGeneralStrings.wisdom_sidetext.
  • English mirror matches production SahajCloud — exit 1 on blocks.general.wisdom_sidetext, common.a11y.opens_in_new_tab, common.a11y.menu, lecture.a11y.untitled_heading and three hand-indented lines.

sydevs/SahajCloud#1218 is still open, so the blocker stands. Re-syncing either file drops the hand-typed wisdom_sidetext and breaks tsc in four files — #306 re-typed it on main for that reason. The gate goes green once #1218 merges and deploys with published English, and a re-sync lands on main.

Pushed nothing.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@Ardnived

Copy link
Copy Markdown
Contributor

Superseded by #320 and sydevs/claude-workflow#283. Instead of comparing every PR with SahajCloud main, the shared contract check fails only a PR that changes a copied contract (types or the English mirror) to something its source doesn't produce. That avoids reddening every open PR on each upstream merge, firing fix-ci on bot PRs, and failing the merge queue. Rationale: sydevs/claude-workflow docs/why.md#a-contract-check-checks-what-a-pr-changes.

@Ardnived Ardnived closed this Nov 20, 2026
@sydevs-bot sydevs-bot moved this from Awaiting to Done in SYDevelopers Technical Roadmap Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

3 participants