Skip to content

Migrate mock.module() to spyOn() in @archon/core test files #966

@Wirasm

Description

@Wirasm

Migrated from dynamous-community/remote-coding-agent#511 — Archon active development has moved to coleam00/Archon. Original issue retained as historical reference.


Problem

@archon/core has 28 test files, many of which use mock.module() to replace shared modules (database connection, logger, config). Since bun's mock.module() permanently replaces modules in the process-wide cache and mock.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 separate bun test invocations 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 use spyOn() instead, which IS properly restored by mock.restore(). This would allow @archon/core to run all tests in a single bun test invocation.

Rules

  • Use spyOn() for internal modules that other test files also import directly
  • Keep mock.module() only for external SDKs (claude-agent-sdk, codex-sdk) that no other test file tests directly
  • Never mock.module() a module path that another test file also mock.module()s with a different implementation

Key files to migrate

Highest priority (mock shared modules used by many files):

  • store-adapter.test.ts — mocks ../db/workflows, ../db/workflow-events, ../db/codebases
  • cleanup-service.test.ts — mocks @archon/git, ../db/isolation-environments, ../db/conversations
  • orchestrator.test.ts — mocks 14+ modules including ../db/*, ../handlers/*, ../clients/*
  • command-handler.test.ts — mocks ../db/conversations, ../db/codebases, ../db/sessions

Lower priority (mock ./connection which is only used within db/ files):

  • All db/*.test.ts files — mock ./connection with pool/dialect

Acceptance criteria

  • bun test src/ in packages/core/ passes with 0 failures (single invocation)
  • Core test script can be simplified back to "test": "bun test src/"

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium priority - Backlog, when time permitsarea: orchestratorMain conversation orchestrationchoreMaintenance (refactoring, CI, dependencies)effort/mediumFew files, one domain or module, some coordination neededtestingTest coverage and testing infrastructure

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions