Skip to content

fix: make better-sqlite3 optional in tests and doctor#398

Merged
khaliqgant merged 2 commits into
stagingfrom
fix/optional-better-sqlite3
Feb 10, 2026
Merged

fix: make better-sqlite3 optional in tests and doctor#398
khaliqgant merged 2 commits into
stagingfrom
fix/optional-better-sqlite3

Conversation

@khaliqgant
Copy link
Copy Markdown
Member

@khaliqgant khaliqgant commented Feb 10, 2026

Summary

  • Skip DLQ SQLite tests when better-sqlite3 is unavailable
  • Doctor command passes when ANY SQLite adapter works (not requiring all)

Problem

The staging build was failing with two test failures related to better-sqlite3 not being installed:

  1. packages/storage/src/dlq-adapter.test.ts - direct import of better-sqlite3 failed
  2. src/cli/index.test.ts > CLI > doctor - doctor command exited with error code 1

Since better-sqlite3 is an optional peer dependency (with node:sqlite as an alternative), the tests and doctor command should handle its absence gracefully.

Changes

1. packages/storage/src/dlq-adapter.test.ts

  • Dynamically import better-sqlite3 and check availability
  • Skip SQLiteDLQAdapter tests when better-sqlite3 is not installed
  • InMemoryDLQAdapter tests continue to run regardless

2. src/cli/commands/doctor.ts

  • Doctor now passes if ANY SQLite adapter (better-sqlite3 OR node:sqlite) is available
  • Missing adapters are shown as warnings, not failures
  • Exit code 0 when at least one adapter works

Test plan

  • Storage tests pass locally (SQLite tests run when better-sqlite3 available)
  • CI passes on staging (SQLite tests skip when better-sqlite3 unavailable)
  • Doctor command exits 0 when only node:sqlite is available

🤖 Generated with Claude Code


Open with Devin

Agent Relay and others added 2 commits February 10, 2026 12:23
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>
@khaliqgant khaliqgant merged commit 190611b into staging Feb 10, 2026
1 check passed
@khaliqgant khaliqgant deleted the fix/optional-better-sqlite3 branch February 10, 2026 12:29
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

View 4 additional findings in Devin Review.

Open in Devin Review

Comment on lines +561 to +567
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;
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 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: true
  • checkNodeSqlite() fails (Node 18) → nodeSqlite: false
  • driverOk = true || false = true
  • For the node:sqlite result: returns !driverOk = false (not a failure)
  • No other checks fail → failed = falseprocess.exitCode = 0
  • But src/cli/commands/doctor.test.ts:197 asserts expect(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.
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

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.

1 participant