fix(fetcher): guard HashStore.load against non-object stores (#238)#247
Merged
Conversation
load() did `JSON.parse(raw) as HashRecord` with no shape validation. A corrupt idempotency store that parses to null made getHash/setHash throw (null[key]); an array payload made setHash silently lose the write (the property is dropped by JSON.stringify); a primitive threw on assignment. Any of these silently breaks change detection — re-committing everything or skipping genuinely changed content. Validate that the parsed value is a non-null plain object (not null, not an array); otherwise treat it as an empty store, matching the existing invalid-JSON degrade path. Distinct from the setHash write-rejection tracked separately — this is the read/parse path. Adds hash-store.test.ts covering invalid-JSON, null, array, and primitive payloads plus a valid round-trip. Closes #238 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
HashStore.load()didJSON.parse(raw) as HashRecordwith no shape validation. A corrupt idempotency store silently breaks change detection:nullpayload →getHash/setHashthrow onnull[key][]payload →setHashsets a property thatJSON.stringify([])drops, silently losing the write42) → property assignment throws (strict mode)Any of these either crashes the fetcher or makes it re-commit/skip content incorrectly.
Fix
After parsing, verify the value is a non-null plain object (not
null, not an array); otherwise treat it as an empty store — the same safe degrade as the existing invalid-JSON path. (Distinct from thesetHashwrite-rejection tracked under #233; this is the read/parse path.)Tests
hash-store.test.ts(new): valid round-trip; degrades to empty (no throw, writes recover) for invalid JSON,null,[], and a primitive payload.Fetcher package: lint, typecheck, 166 tests green.
Closes #238