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:
@@ -1,14 +1,23 @@
|
||||
import { describe, it, expect, beforeEach, mock, spyOn } from "bun:test"
|
||||
import * as fs from "node:fs"
|
||||
import { createSkillTool } from "./tools"
|
||||
import { SkillMcpManager } from "../../features/skill-mcp-manager"
|
||||
import type { LoadedSkill } from "../../features/opencode-skill-loader/types"
|
||||
import type { Tool as McpTool } from "@modelcontextprotocol/sdk/types.js"
|
||||
|
||||
const originalReadFileSync = fs.readFileSync.bind(fs)
|
||||
|
||||
mock.module("node:fs", () => ({
|
||||
readFileSync: () => `---
|
||||
...fs,
|
||||
readFileSync: (path: string, encoding?: string) => {
|
||||
if (typeof path === "string" && path.includes("/skills/")) {
|
||||
return `---
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user