altimate-code icon indicating copy to clipboard operation
altimate-code copied to clipboard

fix: `mock.module()` in enhance-prompt tests poisons global module cache, breaking 149 tests

Open anandgupta42 opened this issue 8 months ago • 0 comments

Problem

test/altimate/enhance-prompt.test.ts uses mock.module() to replace 7 core infrastructure modules (@/util/log, @/session/message-v2, @/session/llm, @/config/config, @/agent/agent, @/session/schema, @/provider/provider) with incomplete stubs.

Bun's mock.module() replaces modules globally for the entire process with no restore mechanism. This causes 149 test failures when running the full test suite (bun test), because the mocked stubs (e.g., Log without Default, empty MessageV2) are used by all subsequent test files instead of the real modules.

All 149 tests pass individually; they only fail when run together.

Root cause

  • mock.module("@/util/log") replaces Log with a stub missing Default → 53 failures
  • mock.module("@/session/message-v2") replaces MessageV2 with {} → ~70 failures
  • mock.module("@/session/llm") replaces LLM with a minimal stub → 5 failures
  • mock.module("@/config/config") replaces Config → remaining failures

Fix

Replace mock.module() with spyOn() — spies override specific methods on the real module objects and can be cleaned up via mockRestore() in afterAll. The 4 unnecessary mocks are removed entirely since the real modules work fine in the test environment.

anandgupta42 avatar Mar 15 '26 19:03 anandgupta42