ci(catalog): fail build if catalog.generated.ts is stale vs source JSON (issue #19) - #21
Merged
Conversation
Closes #19. - scripts/gen-catalog.mjs: - Export buildForSource() so the stale-check can re-emit the expected body without running the full regen. - Stable stringify: sort entries by id, sort object keys, sha256-fingerprint the result, write as a comment header line. - Entry point at the bottom still produces the on-disk files when run directly. - scripts/check-catalog-stale.mjs: - For each source: rebuild the expected body via buildForSource(), compare byte-for-byte against the on-disk catalog.generated.ts. - Exits 0 if everything is in sync, 1 otherwise. - Reports each stale source with its heading and an actionable hint: "Run: npm run gen:catalog". - Distinguishes "missing file" from "out of sync" cases. - Regenerated catalog.generated.ts files now carry "fingerprint: <sha256-prefix> (entries: N)" in the header. Commit-time diff stays friendly (git diff shows the new entries + the new fingerprint line).
- package.json: catalog:check script - .github/workflows/ci.yml: app job runs catalog:check immediately after npm ci, before typecheck. This is the failing-fast layer for the fingerprint loop above — if a PR edits catalog.source.json without running npm run gen:catalog, CI surfaces it with a direct error message and the fix in one line. The prebuild hook remains for developer convenience (so local builds still auto-regen), but the CI check is authoritative.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #19.
Problem
The catalog flow is:
src/main/{providers,gateways}/catalog.source.jsonnpm run gen:catalogStep 2 is easy to forget. Without it the app and CLI ship a stale catalog — types drift silently, new entries never reach the wizard.
The
prebuildhook covers local builds but:npm run typecheck/npm run lintgen-catalog.mjsitself errorsbuildstep succeeding firstSolution
A direct, byte-for-byte comparison runs in CI before typecheck. If the source JSON has changed but the generated TS hasn't, CI fails with a one-line fix.
Changes
scripts/gen-catalog.mjs (refactor)
SOURCESarray andbuildForSource(source)for reuse by the checkerscripts/check-catalog-stale.mjs (new)
SOURCES:catalog.generated.ts(or detect ENOENT separately)buildForSource(source)0if everything matches,1otherwisenpm + CI wiring
package.jsonaddscatalog:checkscript.github/workflows/ci.ymlrunsnpm run catalog:checkimmediately afternpm ci, beforetypecheck. The prebuild hook remains as a developer convenience.Verification
Local CI:
npm run catalog:check✓npm run typecheck✓npm run lint✓npm run test:extractor✓ (carryover from feat(gateway): suggest URL from clipboard on Gateway step (issue #18) #20)npm run build✓bun build src/index.ts --compile✓ (CLI Mach-O arm64)Out of scope
==comparison catches any drift; the comment is for humans/git-diffs)gen:catalogfrom CI (intentional — keep developer step explicit so the diff is reviewable)