test(db-base): cover withRetry, corruption predicate, and cleanup helpers#292
Merged
mksglu merged 1 commit intomksglu:nextfrom Apr 16, 2026
Merged
Conversation
Owner
|
Hi @sebastianbreguel Nice work. Can you please continue that with exist test files instead of create a new one. |
…p paths Adds unit tests for pure utilities in src/db-base.ts that back the SQLITE_BUSY retry wrapping (mksglu#263, mksglu#243) and corruption recovery path behind mksglu#244/mksglu#218 incidents. - withRetry: first-try success, retry-on-busy, rethrow non-busy, empty delays, exhaustion message, non-Error throws, delay honored. - isSQLiteCorruptionError: all four documented signatures + negatives. - renameCorruptDB: main-only, all sidecars, missing files. - cleanOrphanedWALFiles: orphan removed, live DB preserved. - deleteDBFiles: unconditional cleanup of main/-wal/-shm. - defaultDBPath: pid embedding, prefix, tmpdir scoping. 31 tests, all green. No changes to src/.
aba143a to
86278b8
Compare
Contributor
Author
|
Hi @mksglu, thanks for the feedback! Done — moved all 31 db-base tests into the existing |
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.
Why
src/db-base.ts(493L) carries the SQLite primitives behind several recent incident fixes —withRetry(#263 wrappedindexPlainText/indexJSON/searchTrigram, #243 concurrent inserts),isSQLiteCorruptionError+renameCorruptDB(recovery path for #244 heavy-load death and #218 multi-session contention), and the WAL/cleanup helpers touched by #103 lifecycle guard and #249 marketplace-install fallout. Until now the module was only exercised indirectly viaSessionDBintegration tests.This PR is pure regression-guard coverage for the pure, framework-free utilities. No changes to
src/.What's covered
withRetry(11 tests) — first-try success, retry-on-busy (Error), retry on"database is locked"string shape (bun:sqlite), rethrow of non-busy errors, rethrow of generic errors, non-Errorthrows (string, busy-shaped vs not), exhaustion with descriptiveafter N retriesmessage,attempts = delays.length + 1invariant, empty-delays short-circuit, and actual wall-clock delay verification (50ms lower bound).isSQLiteCorruptionError(6 tests) — all four documented signatures (SQLITE_CORRUPT,SQLITE_NOTADB,database disk image is malformed,file is not a database), embedded in longer stack traces, and negative cases (SQLITE_BUSY,ENOENT, empty string).renameCorruptDB(4 tests) — main-file quarantine with.corrupt-<ts>suffix, sidecar-wal/-shmrename when present, graceful no-op when sidecars or main file are missing.cleanOrphanedWALFiles(3 tests) — sidecars removed only when the main DB is gone, sidecars preserved when DB still exists, tolerates empty dirs.deleteDBFiles(3 tests) — unconditional removal of all three files, tolerant of partial/full absence.defaultDBPath(4 tests) — pid embedding, custom prefix, default prefix, tmpdir scoping.Test plan
npx vitest run tests/db-base.test.ts→ 31/31 green, 66msnext: same pre-existing 5 flakes intests/hooks/integration.test.ts(SyntaxError: Unexpected end of JSON inputfrom subprocess stdout) — not introduced here.src/changed.Single-concern PR; no runtime changes, no perf claims.