Skip to content

Fix two flaky tests (wiki-page id collision, legacy decrypt)#26

Merged
catherineluse merged 1 commit into
mainfrom
fix-flaky-tests
Jul 16, 2026
Merged

Fix two flaky tests (wiki-page id collision, legacy decrypt)#26
catherineluse merged 1 commit into
mainfrom
fix-flaky-tests

Conversation

@catherineluse

Copy link
Copy Markdown
Collaborator

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.tsAppDatabase.createWikiPage derives its id from Date.now(), so two wiki pages created in the same millisecond get the same id and the second insert fails with UNIQUE constraint failed: wiki_pages.id. The test now mocks Date.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, so rejects.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: updateWikiPagesFromChapter creates 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 make createWikiPage ids collision-proof.

Testing

Ran the two specs 20× consecutively — 0 failures. npm run lint, type-check, and full vitest run pass.

🤖 Generated with Claude Code

- 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]>
@vercel

vercel Bot commented Jul 16, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ai-beta-reader-frontend Ready Ready Preview, Comment Jul 16, 2026 6:07am

Request Review

@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@catherineluse
catherineluse merged commit d2798cf into main Jul 16, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants