Skip to content

Commit a217610

Browse files
committed
Fix Bun mock.module() leak between test files preventing ralph-loop tests from passing
Replace mock.module() with spyOn() in auto-slash-command test to prevent shared module mocking from leaking to other test files. Remove unused mock.module() from think-mode test. This ensures test isolation so ralph-loop tests pass in both isolation and full suite runs. 🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode)
1 parent b377571 commit a217610

File tree

2 files changed

+9
-32
lines changed

2 files changed

+9
-32
lines changed

src/hooks/auto-slash-command/index.test.ts

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,16 @@
1-
import { describe, expect, it, beforeEach, mock } from "bun:test"
1+
import { describe, expect, it, beforeEach, mock, spyOn } from "bun:test"
22
import type {
33
AutoSlashCommandHookInput,
44
AutoSlashCommandHookOutput,
55
} from "./types"
66

7-
const logMock = mock(() => {})
8-
9-
mock.module("../../shared", () => ({
10-
log: logMock,
11-
parseFrontmatter: (content: string) => ({ data: {}, body: content }),
12-
resolveCommandsInText: async (text: string) => text,
13-
resolveFileReferencesInText: async (text: string) => text,
14-
sanitizeModelField: (model: unknown) => model,
15-
getClaudeConfigDir: () => "/mock/.claude",
16-
}))
17-
18-
mock.module("../../shared/file-utils", () => ({
19-
isMarkdownFile: () => false,
20-
}))
21-
22-
mock.module("../../features/opencode-skill-loader", () => ({
23-
discoverAllSkills: () => [],
24-
}))
25-
26-
mock.module("fs", () => ({
27-
existsSync: () => false,
28-
readdirSync: () => [],
29-
readFileSync: () => "",
30-
}))
7+
// Import real shared module to avoid mock leaking to other test files
8+
import * as shared from "../../shared"
9+
10+
// Spy on log instead of mocking the entire module
11+
const logMock = spyOn(shared, "log").mockImplementation(() => {})
12+
13+
3114

3215
const { createAutoSlashCommandHook } = await import("./index")
3316

src/hooks/think-mode/index.test.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
import { describe, expect, it, beforeEach, mock } from "bun:test"
1+
import { describe, expect, it, beforeEach } from "bun:test"
22
import type { ThinkModeInput } from "./types"
33

4-
const logMock = mock(() => {})
5-
6-
mock.module("../../shared", () => ({
7-
log: logMock,
8-
}))
9-
104
const { createThinkModeHook, clearThinkModeState } = await import("./index")
115

126
/**

0 commit comments

Comments
 (0)