From a217610ae42876b43a5757824fa343cef606603b Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Thu, 1 Jan 2026 22:05:39 +0900 Subject: [PATCH] Fix Bun mock.module() leak between test files preventing ralph-loop tests from passing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- src/hooks/auto-slash-command/index.test.ts | 27 ++++------------------ src/hooks/think-mode/index.test.ts | 8 +------ 2 files changed, 6 insertions(+), 29 deletions(-) diff --git a/src/hooks/auto-slash-command/index.test.ts b/src/hooks/auto-slash-command/index.test.ts index 42edb13..ac8033b 100644 --- a/src/hooks/auto-slash-command/index.test.ts +++ b/src/hooks/auto-slash-command/index.test.ts @@ -1,33 +1,16 @@ -import { describe, expect, it, beforeEach, mock } from "bun:test" +import { describe, expect, it, beforeEach, mock, spyOn } from "bun:test" import type { AutoSlashCommandHookInput, AutoSlashCommandHookOutput, } from "./types" -const logMock = mock(() => {}) +// Import real shared module to avoid mock leaking to other test files +import * as shared from "../../shared" -mock.module("../../shared", () => ({ - log: logMock, - parseFrontmatter: (content: string) => ({ data: {}, body: content }), - resolveCommandsInText: async (text: string) => text, - resolveFileReferencesInText: async (text: string) => text, - sanitizeModelField: (model: unknown) => model, - getClaudeConfigDir: () => "/mock/.claude", -})) +// Spy on log instead of mocking the entire module +const logMock = spyOn(shared, "log").mockImplementation(() => {}) -mock.module("../../shared/file-utils", () => ({ - isMarkdownFile: () => false, -})) -mock.module("../../features/opencode-skill-loader", () => ({ - discoverAllSkills: () => [], -})) - -mock.module("fs", () => ({ - existsSync: () => false, - readdirSync: () => [], - readFileSync: () => "", -})) const { createAutoSlashCommandHook } = await import("./index") diff --git a/src/hooks/think-mode/index.test.ts b/src/hooks/think-mode/index.test.ts index 0579122..8d319d7 100644 --- a/src/hooks/think-mode/index.test.ts +++ b/src/hooks/think-mode/index.test.ts @@ -1,12 +1,6 @@ -import { describe, expect, it, beforeEach, mock } from "bun:test" +import { describe, expect, it, beforeEach } from "bun:test" import type { ThinkModeInput } from "./types" -const logMock = mock(() => {}) - -mock.module("../../shared", () => ({ - log: logMock, -})) - const { createThinkModeHook, clearThinkModeState } = await import("./index") /**