Skip to content

chore(contracts): check committed SahajCloud copies for drift on a schedule - #417

Closed
Ardnived wants to merge 6 commits into
mainfrom
chore/contract-drift-check
Closed

Ardnived wants to merge 6 commits into
mainfrom
chore/contract-drift-check

Conversation

@Ardnived

@Ardnived Ardnived commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Adds .github/workflows/contract-drift.yml (daily cron plus workflow_dispatch). It runs the new pnpm check:contracts (scripts/check-contract-drift.mjs), which diffs the four committed SahajCloud copies against upstream without writing to the tree, and prints one row per contract with its re-sync command (also in the step summary).
    • src/lib/shape/atlas-url-contract.json: sync-atlas-contract.mjs in its existing check mode (public raw file).
    • src/config/translations.en.json: sync-translations.mjs in its existing check mode (production API, needs a key).
    • src/types/payload/payload-types.ts and response-types.ts: what pnpm types:cms would write, fetched to a temp dir and diffed. The path/URL pairs live in the new scripts/fetch-cms-types.mjs, which types:cms runs and the checker imports, so the two cannot address different files.
  • Drift fails the run and opens or updates ONE contract-drift issue, filed with SYDEVS_BOT_PAT like production-smoke.yml; later red runs comment, nothing auto-closes it. It is not a PR check and not in ci.yml, so an unrelated upstream merge cannot turn a PR red. Nothing is committed.
  • sync-translations.mjs now exits 2 (not 1) when production cannot be read, so drift (1) and a fault (2) are distinguishable. strip-payload-augmentation.mjs takes an optional file argument. The header of sync-atlas-contract.mjs and docs/testing.md, docs/environment.md, AGENTS.md no longer say nothing runs these.
  • Left out: types:openapi. openapi.json is gitignored, so there is no committed copy to drift (and it needs a separate Basic-auth secret).

Secrets

The lane passes ATLAS_API_KEY and VITE_SAHAJCLOUD_API_KEY under their own names, and resolveKey in sync-translations.mjs picks between them — so the fallback still has to pass that script's production-origin guard. With neither secret present the row shows skipped (visible, not green-as-read). ATLAS_API_KEY (a production sahaj-atlas-client key) does not exist yet. The fallback key is still unverified against the translations global.

Test results

  • The lean gate (lint, typecheck, test:run): 171 files, 2091 tests. /security-review over the branch diff: no findings.
  • Run locally: all four copies clean (exit 0); a deliberate edit to payload-types.ts, response-types.ts and the contract JSON each reported DRIFT (exit 1), then reverted. pnpm types:cms reproduces both committed copies byte for byte through the new fetcher.
  • The translations path was exercised with a stand-in key, not the real secret: against .env's production origin it reaches production and reports the refusal as an ERROR row; with the origin pointed at localhost the guard refuses the key instead of sending it. Whether the real VITE_SAHAJCLOUD_API_KEY reads the translations global is still what the first manual run will show.

Notes for reviewer

Overlaps in part with contractSync in claude-workflow, which re-runs types:cms on a producer merge. This is the backstop for the cases that does not cover: atlas-url-contract.json, which contractSync does not list for this repo at all; translations.en.json, which is CMS data with no producer commit; and the two misses audit-contracts itself names — a push straight to main, or a sync PR closed unmerged. contractSync opens a PR; nothing verifies that PR landed.

The per-edit selection ceiling in scripts/select-unit-specs.test.ts ratchets 22 → 23 for check-contract-drift.test.ts's readRepoSource read. Timed first: 5.0s widest, 6.0s i18n.ts, medians of three on 4 cores, against a 12s budget.

🤖 Generated with Claude Code

…hedule

Nothing ran sync:atlas-contract, sync:translations or types:cms until a
human remembered to. A daily contract-drift workflow (also by hand) now runs
`pnpm check:contracts`, which diffs the four committed copies against
upstream without writing anything and prints one row per contract. Drift
fails that run and opens or updates one `contract-drift` issue, filed as the
bot like production-smoke. It is never a PR check, so an unrelated upstream
merge cannot turn a PR red.

- sync-translations exits 2, not 1, when production cannot be read, so the
  checker can tell drift from a fault.
- strip-payload-augmentation takes an optional file, to normalise a temp
  copy.
- The translations check is reported as skipped, visibly, when neither
  ATLAS_API_KEY nor VITE_SAHAJCLOUD_API_KEY exists as a secret.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 16, 2026 •

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 Updated (UTC)
✅ Deployment successful!
View logs
sahajatlas-design 4b92d31 Nov 16 2026, 11:10 PM

@Ardnived
Ardnived marked this pull request as ready for review November 16, 2026 22:39
@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 16, 2026
@sydevs-bot

sydevs-bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

🤖 no session running

recent dispatches
  • 22:46Z address-review · attempt 1 · session · done
  • 22:46Z address-review · attempt 1 · session
  • 22:39Z review-pr · attempt 1 · session · done
  • 22:39Z review-pr · 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 16, 2026

@sydevs-bot sydevs-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧐 Adversarial review

The lane is well built. The question is its size: of the four contracts it watches, two already have an owner in claude-workflow's contractSync, and a third is one data edit from that same mechanism. Only translations.en.json is CMS data that produces no commit upstream, so only it needs a clock at all. The body names the overlap and calls the rest a backstop for a missed dispatcher event — an event nobody has counted. The exit-code contract (0 / 1 / 2) is consistent end to end across all three scripts, and the lane is correctly kept out of ci.yml.

Findings

  • should-fix — scope: three of four rows are covered or coverable by contractSync; only translations needs a schedule (contract-drift.yml:15).
  • should-fix — the YAML key fallback bypasses resolveKey's production-origin guard (contract-drift.yml:43).
  • should-fix — the spec shadows readRepoSource to dodge a pinned ceiling docs/testing.md says to ratchet (check-contract-drift.test.ts:9).
  • consider — tail() returns the head, and drops the stderr lines that explain a failure (check-contract-drift.mjs:73).
  • consider — parseCmsTypeSources regex-parses a shell one-liner (check-contract-drift.mjs:41).

What was checked

Read whole on the branch: check-contract-drift.mjs, check-contract-drift.test.ts, contract-drift.yml, sync-translations.mjs and sync-atlas-contract.mjs. Ladder walked on each new piece: parseCmsTypeSources, exitCodeFor, renderReport, tail, the workflow. Consumer side followed into claude-workflow/loop-config.json contractSync and into production-smoke.yml, whose issue-filing step this one mirrors faithfully. Action versions match the other three workflows. sync-atlas-contract.mjs already exits 2 on an unreachable upstream, so its new header is accurate.

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


Generated by Claude Code

Comment thread .github/workflows/contract-drift.yml Resolved
Comment thread .github/workflows/contract-drift.yml Resolved
Comment thread scripts/check-contract-drift.test.ts Resolved
Comment thread scripts/check-contract-drift.mjs Resolved
Comment thread scripts/check-contract-drift.mjs Resolved
@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 16, 2026
@sydevs-bot sydevs-bot moved this from Working to Pending in SYDevelopers Technical Roadmap Nov 16, 2026
@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 16, 2026
@sydevs-bot sydevs-bot moved this from Pending to Working in SYDevelopers Technical Roadmap Nov 16, 2026
`ATLAS_API_KEY: ${{ secrets.ATLAS_API_KEY || secrets.VITE_SAHAJCLOUD_API_KEY }}`
promoted the fallback into the name `resolveKey` returns at its first line, so
the guard that accepts `VITE_SAHAJCLOUD_API_KEY` only when `VITE_SAHAJCLOUD_URL`
is production never ran. A key minted against another CMS would have been sent to
`cloud.sydevelopers.com`, which is what gets one rotated in a hurry.

Each secret now arrives under its own name and `sync-translations.mjs` decides.
`skipped` therefore needs both to be the empty string. `ci-workflows.test.ts`
would own the assertion, but the YAML block it belongs beside is still here.

Verified locally: with the fallback key and `.env`'s production origin the
translations row reaches production and reports its refusal; with the origin
pointed at localhost the guard refuses the key instead.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjVz9eEn2pQR44udu67
`tail` returned `all.slice(0, lines)` — the head. For `diff -u` that was the
right content under the wrong name. For a sync script that exited 2 it also cut
the end of stderr, which is where the reason for the failure is, so every error
row in the drift issue could lose the one line a reader needs.

Two named helpers now, picked by status. The spec was watched failing against
the old single trim before this landed.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjVz9eEn2pQR44udu67
`parseCmsTypeSources` read the upstream URLs out of the `types:cms` shell
one-liner by regex, so it held only while the token order stayed
`curl <one flag> -o <path> <url>`. Reorder those flags and it returns nothing:
error, exit 2, a red drift lane and no issue filed — a failure mode the lane
exists to prevent, reached by editing an unrelated command.

`scripts/fetch-cms-types.mjs` now holds the path/URL pairs and does the
download, and `types:cms` runs it. The drift check imports the same constant,
so the two cannot address different files. `fetch-openapi.mjs` is the
precedent for a fetch that is a script rather than a command line.

Verified: `pnpm types:cms` reproduces both committed copies byte for byte, and
a deliberate edit to `response-types.ts` still reports DRIFT and exits 1.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjVz9eEn2pQR44udu67
`check-contract-drift.test.ts` shadowed `readRepoSource` with its own
`readFileSync(resolve(__dirname, '..', path))` to keep off the dependent count
`select-unit-specs.test.ts` ratchets. That is a third spelling of one read, two
files from `ci-workflows.test.ts`, which #289 and #302 exist to prevent — and
`docs/testing.md` names the answer when the ceiling has no headroom: time the
hook and ratchet, never dodge it.

So the spec uses the real helper, and the ceiling goes 22 → 23. Timed first,
medians of three on 4 cores: 5.0s for the widest edit and 6.0s for
`src/config/i18n.ts`, against a 12-second budget.

The workflow-YAML assertions move to `ci-workflows.test.ts`, which already owns
that kind and reads through the helper, leaving this spec on the script alone.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjVz9eEn2pQR44udu67
The generated-types rule told a reader to add a curl line inside the
`types:cms` command. That command is one script call now, and a download added
anywhere but `CMS_TYPE_SOURCES` is fetched without the drift check watching it.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjVz9eEn2pQR44udu67
@sydevs-bot

Copy link
Copy Markdown
Contributor

Four built, one rebutted, on claude/relay-417-4b92d31.

Docs: data-layer.md still said to add a curl to types:cms — 4b92d31. .claude/workflow.json says the same; protected path, so an attended edit.

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


Generated by Claude Code

@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 16, 2026
@sydevs-bot sydevs-bot moved this from Working to Awaiting in SYDevelopers Technical Roadmap Nov 16, 2026
@sydevs-bot
sydevs-bot enabled auto-merge November 16, 2026 23:12
@Ardnived

Copy link
Copy Markdown
Contributor Author

Closing in favour of a single sync mechanism: the review loop's contractSync and audit-contracts already open sync PRs for the copied contracts. The one gap this PR found (SahajAtlasWeb's atlas-url-contract.json wasn't listed in contractSync) is fixed in the loop config instead: sydevs/claude-workflow#269.

@Ardnived Ardnived closed this Nov 17, 2026
auto-merge was automatically disabled November 17, 2026 17:48

Pull request was closed

@sydevs-bot sydevs-bot moved this from Awaiting to Done in SYDevelopers Technical Roadmap Nov 17, 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