refactor: eliminate mock.module() with DI, simplify test scripts#326
Merged
refactor: eliminate mock.module() with DI, simplify test scripts#326
Conversation
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
…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>
32ee8ae to
e20b88e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
mock.module()calls with dependency injection pattern across backend test filesbun testandbun test --coverageChanges
Phase 1: Sync Modules DI
SyncPipelineManagerDependenciesinterface for connector and normalizer injectionsync-pipeline.test.ts,sync-integration.test.ts,sync-handlers.test.tsPhase 2: Session Manager DI
QueryFunctiontype and parameter to session functionssession-manager.test.tsto inject mock query functionPhase 3: File Watcher DI
FileWatcherDependenciesinterface for chokidar watch and fs readFilefile-watcher.test.tsto inject mock depsWatchOptions→ChokidarOptions)Phase 4: WebSocket Handler DI
WebSocketHandlerDependenciesinterface towebsocket-handler.tscreateTestHandler()wrapper for consistent mock injectionPhase 5: Handler Dependencies DI (completes the work)
HandlerDependenciesinterface tohandlers/types.tsctx.depsinstead of direct importsisFileBrowserError()helper to avoid instanceof checks on mocked classescreateSearchIndexfactory toWebSocketHandlerDependencieshome-handlers,browser-handlers,widget-handlersmock.module()calls fromwebsocket-handler.test.tsTest 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
🤖 Generated with Claude Code