Skip to content

test(cacheable-request): replace sqlite3 test dependency with mock store#1668

Merged
jaredwray merged 2 commits into
mainfrom
claude/sqlite3-cacheable-usage-zxux9p
Jun 27, 2026
Merged

test(cacheable-request): replace sqlite3 test dependency with mock store#1668
jaredwray merged 2 commits into
mainfrom
claude/sqlite3-cacheable-usage-zxux9p

Conversation

@jaredwray

Copy link
Copy Markdown
Owner

Please check if the PR fulfills these requirements

  • Followed the Contributing guidelines and Code of Conduct
  • Tests for the changes have been added (for bug fixes/features) with 100% code coverage.

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

Test/build maintenance — removes an unnecessary native dependency.

cacheable-request pulled in sqlite3 and @keyv/sqlite as devDependencies solely to exercise two cache-connection error paths in its tests (CacheError emission and automaticFailover fallback). sqlite3 is a heavy native (node-gyp) module: it required an allowBuilds entry in pnpm-workspace.yaml and carried two copies in the lockfile (6.0.1 directly + 5.1.7 transitively via @keyv/sqlite).

This PR replaces the two new KeyvSqlite("sqlite://non/existent/database.sqlite") usages with a small in-test mock Keyv store whose operations reject with a SQLITE_CANTOPEN-coded error. The mock reproduces the exact paths the SQLite adapter exercised:

  • emits a CacheError when the cache store fails on get()
  • falls back to a network request when automaticFailover is enabled and the store fails

The error-event path was already covered separately by an existing test that uses a plain new Keyv() instance, so no coverage is lost.

Note: SQLite remains a fully supported storage adapter for users of cacheable-request (via @keyv/sqlite). This only removes it as an internal dev/test dependency.

Changes

  • Replace the two KeyvSqlite test usages with a createUnopenableStore() mock in cacheable-request-instance.test.ts
  • Drop @keyv/sqlite and sqlite3 devDependencies and the testdb.sqlite path from the clean script
  • Remove the sqlite3 allowBuilds entry from pnpm-workspace.yaml and the testdb.sqlite line from .gitignore
  • Regenerate pnpm-lock.yaml

Verification

  • pnpm --filter cacheable-request lint passes with no fixes applied
  • All 22 tests in cacheable-request-instance.test.ts pass, including the two former-SQLite tests
  • The only other failure observed locally (cache.test.ts > "return with url and port") is a pre-existing network timeout to the external host mockhttp.org:8080 — it is unreachable in sandboxed environments and does not touch any removed dependency

🤖 Generated with Claude Code

https://claude.ai/code/session_011PoyCZFLpx5BXNih6jNiaQ


Generated by Claude Code

cacheable-request pulled in sqlite3 and @keyv/sqlite as devDependencies
solely to exercise two cache-connection error paths in its tests
(CacheError emission and automaticFailover fallback). sqlite3 is a heavy
native module: it needed an allowBuilds entry and carried two copies in
the lockfile (6.0.1 directly + 5.1.7 transitively via @keyv/sqlite).

Replace the two KeyvSqlite("sqlite://non/existent/database.sqlite") usages
with a lightweight in-test mock store whose operations reject with a
SQLITE_CANTOPEN-coded error. This preserves the exact coverage (the error
event path was already covered separately via a plain Keyv instance)
without a native dependency. SQLite remains a fully supported storage
adapter for users of the library.

- Drop @keyv/sqlite and sqlite3 devDependencies and the testdb.sqlite
  path from the clean script
- Remove the sqlite3 allowBuilds entry and the testdb.sqlite .gitignore line
- Regenerate pnpm-lock.yaml

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011PoyCZFLpx5BXNih6jNiaQ

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request removes the native SQLite dependencies (sqlite3 and @keyv/sqlite) from the cacheable-request package and replaces them with a mock unopenable store in tests to simulate database connection failures without a native driver. The review feedback suggests making the mock store's operations asynchronous to more accurately simulate a real database-backed Keyv store, and refactoring the error creation to avoid using the any type.

Comment thread packages/cacheable-request/test/cacheable-request-instance.test.ts
@codecov

codecov Bot commented Jun 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (caf0a60) to head (1871cc1).

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1668   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           29        29           
  Lines         3504      3504           
  Branches       810       808    -2     
=========================================
  Hits          3504      3504           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Address review feedback on the unopenable mock store: make its operations
async so they reject a Promise (mirroring a real async Keyv adapter), and
use Object.assign to attach the SQLITE_CANTOPEN code instead of an `any`
cast. No behavior or coverage change.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011PoyCZFLpx5BXNih6jNiaQ
@jaredwray jaredwray merged commit 2d9ba73 into main Jun 27, 2026
12 checks passed
@jaredwray jaredwray deleted the claude/sqlite3-cacheable-usage-zxux9p branch June 27, 2026 18:51
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