diff --git a/src/core/prompts/__tests__/custom-system-prompt.spec.ts b/src/core/prompts/__tests__/custom-system-prompt.spec.ts index b2ae067a3a..60984f95e0 100644 --- a/src/core/prompts/__tests__/custom-system-prompt.spec.ts +++ b/src/core/prompts/__tests__/custom-system-prompt.spec.ts @@ -39,11 +39,30 @@ vi.mock("../../../utils/fs", () => ({ createDirectoriesForFile: vi.fn().mockResolvedValue([]), })) +vi.mock("../../../services/code-index/manager", () => ({ + CodeIndexManager: { + getInstance: vi.fn().mockReturnValue({ + isEnabled: false, + hasIndex: false, + }), + }, +})) + +vi.mock("os", () => ({ + default: { + type: vi.fn().mockReturnValue("Windows_NT"), + homedir: vi.fn().mockReturnValue("/home/test"), + }, + type: vi.fn().mockReturnValue("Windows_NT"), + homedir: vi.fn().mockReturnValue("/home/test"), +})) + +// Import path module to add toPosix to String prototype +import "../../../utils/path" import { SYSTEM_PROMPT } from "../system" import { defaultModeSlug, modes } from "../../../shared/modes" import * as vscode from "vscode" import * as fs from "fs/promises" -import { toPosix } from "./utils" // Get the mocked fs module const mockedFs = vi.mocked(fs) @@ -121,7 +140,11 @@ describe("File-Based Custom System Prompt", () => { const fileCustomSystemPrompt = "Custom system prompt from file" // When called with utf-8 encoding, return a string mockedFs.readFile.mockImplementation((filePath, options) => { - if (toPosix(filePath).includes(`.roo/system-prompt-${defaultModeSlug}`) && options === "utf-8") { + // Convert filePath to string and normalize path separators + const normalizedPath = + typeof filePath === "string" ? filePath.replace(/\\/g, "/") : filePath.toString().replace(/\\/g, "/") + + if (normalizedPath.includes(`.roo/system-prompt-${defaultModeSlug}`) && options === "utf-8") { return Promise.resolve(fileCustomSystemPrompt) } return Promise.reject({ code: "ENOENT" }) @@ -159,7 +182,11 @@ describe("File-Based Custom System Prompt", () => { // Mock the readFile to return content from a file const fileCustomSystemPrompt = "Custom system prompt from file" mockedFs.readFile.mockImplementation((filePath, options) => { - if (toPosix(filePath).includes(`.roo/system-prompt-${defaultModeSlug}`) && options === "utf-8") { + // Convert filePath to string and normalize path separators + const normalizedPath = + typeof filePath === "string" ? filePath.replace(/\\/g, "/") : filePath.toString().replace(/\\/g, "/") + + if (normalizedPath.includes(`.roo/system-prompt-${defaultModeSlug}`) && options === "utf-8") { return Promise.resolve(fileCustomSystemPrompt) } return Promise.reject({ code: "ENOENT" }) diff --git a/src/core/prompts/__tests__/responses-rooignore.spec.ts b/src/core/prompts/__tests__/responses-rooignore.spec.ts index ca0dcfbad5..7428c0db6a 100644 --- a/src/core/prompts/__tests__/responses-rooignore.spec.ts +++ b/src/core/prompts/__tests__/responses-rooignore.spec.ts @@ -2,11 +2,12 @@ import type { Mock } from "vitest" +// Import path module to add toPosix to String prototype +import "../../../utils/path" import { formatResponse } from "../responses" import { RooIgnoreController, LOCK_TEXT_SYMBOL } from "../../ignore/RooIgnoreController" import { fileExistsAtPath } from "../../../utils/fs" import * as fs from "fs/promises" -import { toPosix } from "./utils" // Mock dependencies vi.mock("../../../utils/fs") @@ -86,7 +87,7 @@ describe("RooIgnore Response Formatting", () => { return ( !filePath.includes("node_modules") && !filePath.includes(".git") && - !toPosix(filePath).includes("secrets/") + !filePath.toString().toPosix().includes("secrets/") ) }) @@ -130,7 +131,7 @@ describe("RooIgnore Response Formatting", () => { return ( !filePath.includes("node_modules") && !filePath.includes(".git") && - !toPosix(filePath).includes("secrets/") + !filePath.toString().toPosix().includes("secrets/") ) }) diff --git a/src/core/prompts/__tests__/utils.ts b/src/core/prompts/__tests__/utils.ts deleted file mode 100644 index f2ac4fec1e..0000000000 --- a/src/core/prompts/__tests__/utils.ts +++ /dev/null @@ -1,7 +0,0 @@ -import * as fs from "fs/promises" -import { PathLike } from "fs" - -// Make a path take a unix-like form. Useful for making path comparisons. -export function toPosix(filePath: PathLike | fs.FileHandle) { - return filePath.toString().toPosix() -}