fix(tests): resolve mock.module leakage breaking ralph-loop tests

The node:fs mock in skill/tools.test.ts was replacing the entire module,
causing fs functions to be undefined for tests running afterwards.
Fixed by preserving original fs functions and only intercepting skill paths.

🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode)
This commit is contained in:
YeonGyu-Kim
2026-01-02 00:23:46 +09:00
parent 44640b985d
commit 2452a4789d

View File

@@ -1,14 +1,23 @@
import { describe, it, expect, beforeEach, mock, spyOn } from "bun:test" import { describe, it, expect, beforeEach, mock, spyOn } from "bun:test"
import * as fs from "node:fs"
import { createSkillTool } from "./tools" import { createSkillTool } from "./tools"
import { SkillMcpManager } from "../../features/skill-mcp-manager" import { SkillMcpManager } from "../../features/skill-mcp-manager"
import type { LoadedSkill } from "../../features/opencode-skill-loader/types" import type { LoadedSkill } from "../../features/opencode-skill-loader/types"
import type { Tool as McpTool } from "@modelcontextprotocol/sdk/types.js" import type { Tool as McpTool } from "@modelcontextprotocol/sdk/types.js"
const originalReadFileSync = fs.readFileSync.bind(fs)
mock.module("node:fs", () => ({ mock.module("node:fs", () => ({
readFileSync: () => `--- ...fs,
readFileSync: (path: string, encoding?: string) => {
if (typeof path === "string" && path.includes("/skills/")) {
return `---
description: Test skill description description: Test skill description
--- ---
Test skill body content`, Test skill body content`
}
return originalReadFileSync(path, encoding as BufferEncoding)
},
})) }))
function createMockSkillWithMcp(name: string, mcpServers: Record<string, unknown>): LoadedSkill { function createMockSkillWithMcp(name: string, mcpServers: Record<string, unknown>): LoadedSkill {