Skip to content

test: add cache-hit path tests for client/modules/search.ts - #2328

Merged
felladrin merged 1 commit into
mainfrom
test-cache-hit-path
Aug 10, 2026
Merged

test: add cache-hit path tests for client/modules/search.ts#2328
felladrin merged 1 commit into
mainfrom
test-cache-hit-path

Conversation

@felladrin

Copy link
Copy Markdown
Owner

Split off from #2130.

We test performSearch, but nothing asserts that a repeated query is served from the IndexedDB cache and skips the network fetch — that's the module's headline feature and it's currently uncovered.

What changed

  • client/setupTests.ts — Wired fake-indexeddb/auto so Dexie-based cache tests exercise the real IndexedDB code paths instead of silently erroring into catch blocks.
  • package.json — Added fake-indexeddb to devDependencies.
  • client/modules/search.test.ts — New Cache Hit Path describe block with 7 tests.

Tests added

Test What it proves
Repeated text query served from cache Second searchText call skips fetch; log entry and textHits counter confirm the cache-hit branch.
Repeated image query served from cache Same for searchImages with imageHits counter.
Different queries → separate entries Two distinct queries each hit the network.
Different limits → separate entries Same query, different limit values produce separate cache keys.
TTL expiry forces refetch updateCacheConfig({ ttl: 0 }) between calls triggers a second fetch.
Caching disabled skips cache enabled: false makes both calls hit the network.
Text/image stores independent Same query through searchText and searchImages produces 2 fetches; a third call to the image store hits the cache.

Verification

  • 364 tests pass across 40 files.
  • Lint clean (Biome, TypeScript, knip, jscpd, architectural linter).
  • Reviewed by Claude (3 rounds) — approved with no blockers.

Wire fake-indexeddb/auto in setupTests.ts so Dexie-based cache tests
exercise the real IndexedDB code paths instead of silently erroring
into catch blocks.

Add 7 tests covering the cache-hit path previously uncovered:
- Repeated text/image queries served from cache without second fetch
- Different queries and limits produce separate cache entries
- TTL expiry forces refetch
- Caching disabled skips the cache
- Text and image stores are independent
@felladrin felladrin changed the title test: add cache-hit path tests for client/modules/search.ts (#2169) test: add cache-hit path tests for client/modules/search.ts Aug 10, 2026
@felladrin
felladrin marked this pull request as ready for review August 10, 2026 21:05
@felladrin
felladrin merged commit 00a32a7 into main Aug 10, 2026
7 checks passed
@felladrin
felladrin deleted the test-cache-hit-path branch August 10, 2026 21:05
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