Skip to content

refactor: eliminate mock.module() with DI, simplify test scripts#326

Merged
rjroy merged 5 commits intomainfrom
test/improve-coverage
Jan 17, 2026
Merged

refactor: eliminate mock.module() with DI, simplify test scripts#326
rjroy merged 5 commits intomainfrom
test/improve-coverage

Conversation

@rjroy
Copy link
Copy Markdown
Owner

@rjroy rjroy commented Jan 17, 2026

Summary

  • Replace all mock.module() calls with dependency injection pattern across backend test files
  • All 2,667 backend tests now run together in a single process (~11s)
  • Simplified test scripts: bun test and bun test --coverage

Changes

Phase 1: Sync Modules DI

  • Add SyncPipelineManagerDependencies interface for connector and normalizer injection
  • Update sync-pipeline.test.ts, sync-integration.test.ts, sync-handlers.test.ts

Phase 2: Session Manager DI

  • Add QueryFunction type and parameter to session functions
  • Update session-manager.test.ts to inject mock query function

Phase 3: File Watcher DI

  • Add FileWatcherDependencies interface for chokidar watch and fs readFile
  • Update file-watcher.test.ts to inject mock deps
  • Fix chokidar v5.0.0 type changes (WatchOptionsChokidarOptions)

Phase 4: WebSocket Handler DI

  • Add WebSocketHandlerDependencies interface to websocket-handler.ts
  • Create createTestHandler() wrapper for consistent mock injection
  • Update all 100+ test instantiations to use DI mocks

Phase 5: Handler Dependencies DI (completes the work)

  • Add HandlerDependencies interface to handlers/types.ts
  • Handler functions receive deps via ctx.deps instead of direct imports
  • Add isFileBrowserError() helper to avoid instanceof checks on mocked classes
  • Add createSearchIndex factory to WebSocketHandlerDependencies
  • Update handlers: home-handlers, browser-handlers, widget-handlers
  • Remove all 8 remaining mock.module() calls from websocket-handler.test.ts

Test Script Simplification

{
  "test": "LOG_LEVEL=silent bun test",
  "test:coverage": "LOG_LEVEL=silent bun test --coverage"
}

Removed all test:batch* commands - no longer needed.

Test plan

  • All 2,667 backend tests pass in single run
  • All 1,099 frontend tests pass
  • All 425 shared tests pass
  • Pre-commit hook passes (typecheck, lint, unit tests)
  • Coverage collection works with simplified script

🤖 Generated with Claude Code

@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 17, 2026

Codecov Report

❌ Patch coverage is 96.68508% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
backend/src/handlers/browser-handlers.ts 81.81% 2 Missing ⚠️
backend/src/websocket-handler.ts 97.91% 2 Missing ⚠️
backend/src/handlers/home-handlers.ts 90.90% 1 Missing ⚠️
backend/src/handlers/widget-handlers.ts 80.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@rjroy rjroy changed the title refactor: replace mock.module() with dependency injection for test isolation refactor: eliminate mock.module() with DI, simplify test scripts Jan 17, 2026
rjroy and others added 5 commits January 17, 2026 06:41
…olation

Replace mock.module() calls with dependency injection pattern across
backend test files to improve test isolation and enable future
simplification of test scripts.

Changes:
- Add DI to SyncPipelineManager for connector and normalizer injection
- Add DI to session manager functions for query function
- Add DI to FileWatcher for chokidar watch and fs readFile
- Add WebSocketHandlerDependencies interface to WebSocketHandler
- Create createTestHandler() wrapper for consistent mock injection
- Update chokidar types for v5.0.0 (WatchOptions → ChokidarOptions)
- Add re-exports to session-manager.ts for SessionMetadata, ConversationMessage

Reduces mock.module() calls in websocket-handler.test.ts from 11 to 8.
Remaining mock.module() calls are for modules imported by extracted
handlers (note-capture, file-browser, inspiration-manager, task-manager,
session-manager, vault-config, search-index, widgets).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
GitHub Actions doesn't have lcov installed. The coverage files are
generated separately and uploaded to codecov individually.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Replace remaining mock.module() calls with dependency injection:

- Add HandlerDependencies interface to handlers/types.ts
- Handler functions now receive deps via ctx.deps instead of
  direct imports
- Add isFileBrowserError() helper to avoid instanceof checks
  on mocked classes
- Add createSearchIndex factory to WebSocketHandlerDependencies
- Update handlers: home-handlers, browser-handlers, widget-handlers
- Update sync-handlers.test.ts to provide stub deps

With mock.module() eliminated, all 2667 backend tests now run
together in a single process without contamination.

Simplify backend/package.json test scripts:
- "test": Single command runs all tests
- "test:coverage": Single command with --coverage flag
- Remove all test:batch* commands

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* feat: add archive functionality for chats, projects, and areas (#323)

Add context menu option to archive directories to a dated archive folder.
Archivable items include the chats directory (under inbox), project
directories, and area directories. Archives are organized by YYYY-MM
based on the newest file modification date within the directory.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* test: add frontend tests for archive functionality

Add comprehensive test coverage for archive functionality:

FileTree.test.tsx:
- Archive button visibility for archivable directories (chats, projects, areas)
- Archive button hidden for non-archivable directories (inbox, archive, root)
- Confirmation dialog flow (display, confirm, cancel)
- Callback invocation on confirmation

BrowseMode.test.tsx:
- file_archived message triggers parent directory refresh

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Replace remaining mock.module() calls with dependency injection:

- Add HandlerDependencies interface to handlers/types.ts
- Handler functions now receive deps via ctx.deps instead of
  direct imports
- Add isFileBrowserError() helper to avoid instanceof checks
  on mocked classes
- Add createSearchIndex factory to WebSocketHandlerDependencies
- Update handlers: home-handlers, browser-handlers, widget-handlers
- Update sync-handlers.test.ts to provide stub deps

With mock.module() eliminated, all 2667 backend tests now run
together in a single process without contamination.

Simplify backend/package.json test scripts:
- "test": Single command runs all tests
- "test:coverage": Single command with --coverage flag
- Remove all test:batch* commands

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@rjroy rjroy force-pushed the test/improve-coverage branch from 32ee8ae to e20b88e Compare January 17, 2026 14:43
@rjroy rjroy merged commit d56c7ae into main Jan 17, 2026
2 checks passed
@rjroy rjroy deleted the test/improve-coverage branch January 17, 2026 14:45
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