Harden WarningRegistry against a malformed registry file#13
Open
jgamblin wants to merge 3 commits into
Open
Conversation
A Diagnostics result constructs a WarningRegistry, and WarningRegistry.read threw on unparseable or wrong-shaped registry JSON. Because validation builds a Diagnostics for every result, a corrupt warnings.json turned every validation call — including otherwise-successful ones — into a thrown exception. - read() now fails soft: on a JSON parse error or invalid shape it warns on stderr and returns no warnings, so validation is never taken down by a bad registry file. - addWarning() refuses to run when the existing file could not be read, so a corrupt registry is never silently overwritten and its contents destroyed. - Add smoke-test coverage for malformed JSON, wrong-shape content, and the no-clobber guard (with console.warn captured). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- Warn at most once per registry path (module-level set) so a corrupt default registry does not emit one identical stderr line per validated record during batch validation. - Tests: assert the wrong-shape case also surfaces a console.warn, and exercise the no-clobber addWarning guard against both malformed-JSON and wrong-shape files (with a byte-for-byte before/after check). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The warn-once dedupe set was never cleared, so a registry that was corrupt, repaired, then re-corrupted within one process would silently swallow the second corruption. Clear the dedupe entry on a successful (or missing-file) read, so each distinct corruption episode is reported exactly once. Add a corrupt -> repair -> re-corrupt test proving the recurrence warns again. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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
A
Diagnosticsresult constructs aWarningRegistry(src/diagnostic/diagnostics.ts), andWarningRegistry.read()threw on unparseable or wrong-shaped registry JSON. Because validation builds aDiagnosticsfor every result, a corruptwarnings.jsonturned every validation call — including otherwise-successful ones — into a thrown exception. This makes the registry fail soft so a bad file can no longer take down validation.This PR is a targeted robustness fix to
src/registry/warnings.tsplus smoke-test coverage. No validation semantics change; behavior for a valid or missing registry is unchanged.Changes
read()fails soft. On a JSON parse error or invalid shape it now warns on stderr and returns no warnings, instead of throwing. Validation is never taken down by a malformed registry file.addWarning()refuses to clobber. If the existing file could not be read,addWarning()throws rather than overwriting it, so a corrupt registry's contents are never silently destroyed.scripts/test-local.mjs): malformed JSON, valid-JSON-of-the-wrong-shape (both assert the stderr warning is surfaced), the no-clobberaddWarningguard against both corrupt forms (with a byte-for-byte before/after check), and a corrupt → repair → re-corrupt recurrence test.console.warnis captured so output stays clean.npm run test:localpasses.Notes
src/registry/warnings.tsandscripts/test-local.mjs, neither of which Add CI workflow and node --test suite #12 modifies, so the two can merge in any order.Diagnosticsfield. Both are deliberate for the fail-soft goal; happy to surface the load error programmatically instead/as well if preferred.🤖 Generated with Claude Code