fix: make better-sqlite3 optional in tests and doctor#398
Conversation
better-sqlite3 is an optional peer dependency, so tests that require it should be skipped when it's not installed. This allows the test suite to pass in CI environments that don't have better-sqlite3. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The doctor command now considers it a success if ANY SQLite adapter (better-sqlite3 or node:sqlite) is working, rather than requiring all of them. Missing adapters are shown as warnings instead of failures. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
| const driverOk = availability.betterSqlite3 || availability.nodeSqlite; | ||
| const failed = results.some((r) => { | ||
| if (r.name === 'better-sqlite3' || r.name === 'node:sqlite') { | ||
| return !driverOk; | ||
| } | ||
| return !r.ok; | ||
| }); |
There was a problem hiding this comment.
🔴 Doctor exit code logic change breaks existing test expecting failure when one driver is missing
The new failed logic at lines 561-567 treats individual driver check failures as non-fatal when at least one driver is available (driverOk = true). However, the existing test 'shows remediation for node:sqlite on older Node versions' in src/cli/commands/doctor.test.ts:185-198 expects process.exitCode to be 1 when node:sqlite is unavailable (Node 18) but better-sqlite3 IS available (via mock).
Root Cause and Impact
With the old code (const failed = results.some((r) => !r.ok)), when node:sqlite returned ok: false, the overall result was failed = true and process.exitCode = 1.
With the new code, the logic is:
const driverOk = availability.betterSqlite3 || availability.nodeSqlite;
const failed = results.some((r) => {
if (r.name === 'better-sqlite3' || r.name === 'node:sqlite') {
return !driverOk; // false when at least one driver works
}
return !r.ok;
});In the test scenario:
checkBetterSqlite3()succeeds via mock →betterSqlite3: truecheckNodeSqlite()fails (Node 18) →nodeSqlite: falsedriverOk = true || false = true- For the
node:sqliteresult: returns!driverOk = false(not a failure) - No other checks fail →
failed = false→process.exitCode = 0 - But
src/cli/commands/doctor.test.ts:197assertsexpect(process.exitCode).toBe(1)
Impact: The existing doctor test suite will fail, breaking CI. The test file was not updated to match the new behavior.
Prompt for agents
The doctor.ts logic change at lines 561-567 makes individual driver failures non-fatal when at least one driver is available. This is the intended behavior per the PR description, but the existing test in src/cli/commands/doctor.test.ts at line 197 still expects process.exitCode to be 1 when only node:sqlite is unavailable. Update the test at src/cli/commands/doctor.test.ts lines 185-198 to expect process.exitCode to be 0 instead of 1, and update the test description to reflect that the doctor should pass with warnings when at least one driver is available. You may also want to add assertions checking for the 'warnings' status message.
Was this helpful? React with 👍 or 👎 to provide feedback.
Summary
Problem
The staging build was failing with two test failures related to
better-sqlite3not being installed:packages/storage/src/dlq-adapter.test.ts- direct import of better-sqlite3 failedsrc/cli/index.test.ts > CLI > doctor- doctor command exited with error code 1Since
better-sqlite3is an optional peer dependency (withnode:sqliteas an alternative), the tests and doctor command should handle its absence gracefully.Changes
1.
packages/storage/src/dlq-adapter.test.ts2.
src/cli/commands/doctor.tsTest plan
🤖 Generated with Claude Code