-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Migrate mock.module() to spyOn() in @archon/core test files #966
Copy link
Copy link
Open
Labels
P2Medium priority - Backlog, when time permitsMedium priority - Backlog, when time permitsarea: orchestratorMain conversation orchestrationMain conversation orchestrationchoreMaintenance (refactoring, CI, dependencies)Maintenance (refactoring, CI, dependencies)effort/mediumFew files, one domain or module, some coordination neededFew files, one domain or module, some coordination neededtestingTest coverage and testing infrastructureTest coverage and testing infrastructure
Metadata
Metadata
Assignees
Labels
P2Medium priority - Backlog, when time permitsMedium priority - Backlog, when time permitsarea: orchestratorMain conversation orchestrationMain conversation orchestrationchoreMaintenance (refactoring, CI, dependencies)Maintenance (refactoring, CI, dependencies)effort/mediumFew files, one domain or module, some coordination neededFew files, one domain or module, some coordination neededtestingTest coverage and testing infrastructureTest coverage and testing infrastructure
Problem
@archon/corehas 28 test files, many of which usemock.module()to replace shared modules (database connection, logger, config). Since bun'smock.module()permanently replaces modules in the process-wide cache andmock.restore()does NOT undo it (oven-sh/bun#7823), these mocks pollute across test files.Current Workaround
#509 split
@archon/core's test script into 5 separatebun testinvocations to give each batch its own process. This works but is fragile — adding new test files could introduce new pollution chains.Proposed Fix
Migrate the worst
mock.module()polluters to usespyOn()instead, which IS properly restored bymock.restore(). This would allow@archon/coreto run all tests in a singlebun testinvocation.Rules
spyOn()for internal modules that other test files also import directlymock.module()only for external SDKs (claude-agent-sdk, codex-sdk) that no other test file tests directlymock.module()a module path that another test file alsomock.module()s with a different implementationKey files to migrate
Highest priority (mock shared modules used by many files):
store-adapter.test.ts— mocks../db/workflows,../db/workflow-events,../db/codebasescleanup-service.test.ts— mocks@archon/git,../db/isolation-environments,../db/conversationsorchestrator.test.ts— mocks 14+ modules including../db/*,../handlers/*,../clients/*command-handler.test.ts— mocks../db/conversations,../db/codebases,../db/sessionsLower priority (mock
./connectionwhich is only used within db/ files):db/*.test.tsfiles — mock./connectionwith pool/dialectAcceptance criteria
bun test src/inpackages/core/passes with 0 failures (single invocation)"test": "bun test src/"