Fix two flaky tests (wiki-page id collision, legacy decrypt)#26
Merged
Conversation
- database.spec: createWikiPage derives its id from Date.now(), so two wiki pages created in the same millisecond collided (UNIQUE constraint failed). Mock Date.now() to increase strictly so ids are unique. - encryption.spec: a wrong password usually throws but can occasionally decode CryptoJS garbage to a non-empty string, so rejects.toThrow() was flaky. Assert the deterministic invariant instead: it must never return the original plaintext. Verified with 20 consecutive runs, 0 failures. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This was referenced Jul 16, 2026
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
Two tests added in the recent coverage work (#21, #23) are non-deterministic and intermittently fail CI on
main. This makes them reliable.database.spec.ts—AppDatabase.createWikiPagederives its id fromDate.now(), so two wiki pages created in the same millisecond get the same id and the second insert fails withUNIQUE constraint failed: wiki_pages.id. The test now mocksDate.now()to increase strictly, giving each row a unique id.encryption.spec.ts— decrypting a legacy CryptoJS backup with the wrong password usually throws (bad padding / malformed UTF-8) but can occasionally decode garbage to a non-empty string, sorejects.toThrow()was flaky. The test now asserts the deterministic invariant: a wrong password must never return the original plaintext.Note on the source
The
Date.now()-based wiki id is also a latent source smell:updateWikiPagesFromChaptercreates pages in a tight loop, so real same-millisecond collisions are possible. Out of scope here (test-only fix), but worth a follow-up to makecreateWikiPageids collision-proof.Testing
Ran the two specs 20× consecutively — 0 failures.
npm run lint,type-check, and fullvitest runpass.🤖 Generated with Claude Code