Skip to content

fix: replace mock.module() with spyOn() to fix 149 test failures#153

Merged
anandgupta42 merged 2 commits intomainfrom
fix/test-mock-module-leak
Mar 15, 2026
Merged

fix: replace mock.module() with spyOn() to fix 149 test failures#153
anandgupta42 merged 2 commits intomainfrom
fix/test-mock-module-leak

Conversation

@anandgupta42
Copy link
Contributor

@anandgupta42 anandgupta42 commented Mar 15, 2026

What does this PR do?

Fixes 149 test failures caused by mock.module() in enhance-prompt.test.ts poisoning the global module cache. Bun's mock.module() replaces modules process-wide with no restore mechanism — when this test file mocked 7 core modules (@/util/log, @/session/message-v2, @/session/llm, etc.) with incomplete stubs, every subsequent test file got the broken stubs instead of real modules.

Root causes fixed:

  • Log mock missing Default property → 53 failures
  • MessageV2 mock was empty {} → ~70 failures
  • LLM mock missing hasToolCalls → 5 failures
  • Config mock missing Keybinds → remaining failures

Solution: Replace mock.module() with spyOn() for the 3 modules that need mocking (Config, Provider, LLM), restore them in afterAll. Remove the 4 unnecessary mocks (@/util/log, @/session/message-v2, @/agent/agent, @/session/schema) — real modules work fine in tests.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Issue for this PR

Closes #154

How did you verify your code works?

  • Ran full test suite before fix: 149 fail / 2157 tests
  • Ran full test suite after fix: 0 fail / 2381 tests (the 1 flaky pty timing test is pre-existing and unrelated)
  • Ran typecheck: all packages pass
  • Verified enhance-prompt tests still pass: 48/48

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • New and existing unit tests pass locally with my changes

🤖 Generated with Claude Code

…o prevent global module cache poisoning

`mock.module()` in bun replaces modules process-wide with no restore
mechanism. The enhance-prompt test file was mocking 7 core modules
(`@/util/log`, `@/session/message-v2`, `@/session/llm`, etc.) with
incomplete stubs, causing 149 test failures when the full suite runs.

Switch to `spyOn()` for the 3 modules that actually need mocking
(`Config`, `Provider`, `LLM`) and remove the 4 unnecessary mocks
entirely. Spies are restored in `afterAll`, preventing cross-file leaks.

Closes #17647

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

The `blacksmith-4vcpu-ubuntu-2404` self-hosted runner is unavailable,
causing the `check-duplicates` job to hang indefinitely waiting for a
runner. Switch to GitHub-hosted `ubuntu-latest`.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@anandgupta42 anandgupta42 merged commit 3721c88 into main Mar 15, 2026
8 checks passed
anandgupta42 added a commit that referenced this pull request Mar 17, 2026
* fix: replace `mock.module()` with `spyOn()` in enhance-prompt tests to prevent global module cache poisoning

`mock.module()` in bun replaces modules process-wide with no restore
mechanism. The enhance-prompt test file was mocking 7 core modules
(`@/util/log`, `@/session/message-v2`, `@/session/llm`, etc.) with
incomplete stubs, causing 149 test failures when the full suite runs.

Switch to `spyOn()` for the 3 modules that actually need mocking
(`Config`, `Provider`, `LLM`) and remove the 4 unnecessary mocks
entirely. Spies are restored in `afterAll`, preventing cross-file leaks.

Closes #17647

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: use `ubuntu-latest` runner for `pr-management` workflow

The `blacksmith-4vcpu-ubuntu-2404` self-hosted runner is unavailable,
causing the `check-duplicates` job to hang indefinitely waiting for a
runner. Switch to GitHub-hosted `ubuntu-latest`.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@anandgupta42 anandgupta42 deleted the fix/test-mock-module-leak branch March 17, 2026 01:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant