Refactor: validate build-time override file with a zod schema#234
Merged
Conversation
Replaces the hand-rolled recursive walker in
extension/scripts/load-default-overrides.ts with a strict zod schema
built dynamically from RULE_DEFAULTS + RULE_OPTION_DEFAULTS. Behavioral
contracts from ADR-0016 / ADR-0017 / spec 0011 FR-4 are preserved:
unknown top-level keys, unknown sub-rule paths, object values for rules
without declared options, and mistyped leaves all fail the build with a
path-qualified message.
Error format moves from the bucketed "unknown keys: …; non-boolean
values for: …" summary to one issue per line (" - <path>: <message>"),
with the underlying ZodError attached as the thrown Error's cause. Each
issue carries a precise dotted path (e.g.
encoded-payload-redact.subRules.hex.minLength), and the union-aware
flattener prefers the branch whose deepest leaf reaches furthest into
the tree so the object-shape error wins over the boolean-branch
"expected boolean" noise.
zod was already a devDep (used by data/site-rules.schema.ts); no
runtime bundle impact.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Summary
extension/scripts/load-default-overrides.tswith a strict zod schema built dynamically fromRULE_DEFAULTS+RULE_OPTION_DEFAULTS. zod was already a devDep (used byextension/data/site-rules.schema.ts); no runtime bundle impact.{ enabled, ... }sub-rule positions still normalizes to{ enabled: <boolean> }.unknown keys: …; non-boolean values for: …summary to one issue per line (- <path>: <message>), with the underlyingZodErrorattached ascause. The union-aware flattener prefers the branch whose deepest leaf reaches furthest into the tree, so the actionable object-shape error wins over the boolean-branch "expected boolean" noise.End-to-end with a deliberately-broken file:
No ADR / spec / install-doc changes — every reference to the validator describes behavior we preserve. ADR-0016 §"Decision Outcome" still applies verbatim: the validator walks the declared option-shape tree recursively rather than hard-coding
subRules, so future rules can declare other option groups without touching the loader.Test plan
bun run jest scripts/__tests__/load-default-overrides.test.ts— 32 / 32 pass (assertions updated to the new format).bun run jest— full extension suite, 1954 / 1954 pass.bun run check(biome + eslint) — clean.bun run typecheck— clean.bun run knip— clean.bun run build --defaults data/defaults-overrides.example.json— committed example file still loads, "Applying 9 build-time default override(s)" message intact.🤖 Generated with Claude Code