fix: replace mock.module() with spyOn() to fix 149 test failures#153
Merged
anandgupta42 merged 2 commits intomainfrom Mar 15, 2026
Merged
fix: replace mock.module() with spyOn() to fix 149 test failures#153anandgupta42 merged 2 commits intomainfrom
anandgupta42 merged 2 commits intomainfrom
Conversation
…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>
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
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
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>
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.
What does this PR do?
Fixes 149 test failures caused by
mock.module()inenhance-prompt.test.tspoisoning the global module cache. Bun'smock.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:
Logmock missingDefaultproperty → 53 failuresMessageV2mock was empty{}→ ~70 failuresLLMmock missinghasToolCalls→ 5 failuresConfigmock missingKeybinds→ remaining failuresSolution: Replace
mock.module()withspyOn()for the 3 modules that need mocking (Config,Provider,LLM), restore them inafterAll. Remove the 4 unnecessary mocks (@/util/log,@/session/message-v2,@/agent/agent,@/session/schema) — real modules work fine in tests.Type of change
Issue for this PR
Closes #154
How did you verify your code works?
Checklist
🤖 Generated with Claude Code