Skip to content

Commit 2452a47

Browse files
committed
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)
1 parent 44640b9 commit 2452a47

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/tools/skill/tools.test.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
import { describe, it, expect, beforeEach, mock, spyOn } from "bun:test"
2+
import * as fs from "node:fs"
23
import { createSkillTool } from "./tools"
34
import { SkillMcpManager } from "../../features/skill-mcp-manager"
45
import type { LoadedSkill } from "../../features/opencode-skill-loader/types"
56
import type { Tool as McpTool } from "@modelcontextprotocol/sdk/types.js"
67

8+
const originalReadFileSync = fs.readFileSync.bind(fs)
9+
710
mock.module("node:fs", () => ({
8-
readFileSync: () => `---
11+
...fs,
12+
readFileSync: (path: string, encoding?: string) => {
13+
if (typeof path === "string" && path.includes("/skills/")) {
14+
return `---
915
description: Test skill description
1016
---
11-
Test skill body content`,
17+
Test skill body content`
18+
}
19+
return originalReadFileSync(path, encoding as BufferEncoding)
20+
},
1221
}))
1322

1423
function createMockSkillWithMcp(name: string, mcpServers: Record<string, unknown>): LoadedSkill {

0 commit comments

Comments
 (0)