From 2ab5aad1830f96e8a60cc09ad23a274805f9353f Mon Sep 17 00:00:00 2001 From: Diarmid Mackenzie Date: Sun, 23 Mar 2025 06:14:42 +0000 Subject: [PATCH] Fixes for prompts suite unit tests on windows (#1879) * Fixes for prompts suite unit tests on windows * unixLike -> toPosix Fix naming, and re-use code that already provides this function --- .../prompts/__tests__/custom-system-prompt.test.ts | 5 +++-- src/core/prompts/__tests__/responses-rooignore.test.ts | 10 +++++++--- src/core/prompts/__tests__/utils.ts | 7 +++++++ 3 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 src/core/prompts/__tests__/utils.ts diff --git a/src/core/prompts/__tests__/custom-system-prompt.test.ts b/src/core/prompts/__tests__/custom-system-prompt.test.ts index 812caffbaf..977ab051a0 100644 --- a/src/core/prompts/__tests__/custom-system-prompt.test.ts +++ b/src/core/prompts/__tests__/custom-system-prompt.test.ts @@ -2,6 +2,7 @@ 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" // Mock the fs/promises module jest.mock("fs/promises", () => ({ @@ -89,7 +90,7 @@ 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 (filePath.toString().includes(`.roo/system-prompt-${defaultModeSlug}`) && options === "utf-8") { + if (toPosix(filePath).includes(`.roo/system-prompt-${defaultModeSlug}`) && options === "utf-8") { return Promise.resolve(fileCustomSystemPrompt) } return Promise.reject({ code: "ENOENT" }) @@ -124,7 +125,7 @@ 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 (filePath.toString().includes(`.roo/system-prompt-${defaultModeSlug}`) && options === "utf-8") { + if (toPosix(filePath).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.test.ts b/src/core/prompts/__tests__/responses-rooignore.test.ts index 37b3050dd0..46f1bec438 100644 --- a/src/core/prompts/__tests__/responses-rooignore.test.ts +++ b/src/core/prompts/__tests__/responses-rooignore.test.ts @@ -2,9 +2,9 @@ import { formatResponse } from "../responses" import { RooIgnoreController, LOCK_TEXT_SYMBOL } from "../../ignore/RooIgnoreController" -import * as path from "path" import { fileExistsAtPath } from "../../../utils/fs" import * as fs from "fs/promises" +import { toPosix } from "./utils" // Mock dependencies jest.mock("../../../utils/fs") @@ -82,7 +82,9 @@ describe("RooIgnore Response Formatting", () => { controller.validateAccess = jest.fn().mockImplementation((filePath: string) => { // Only allow files not matching these patterns return ( - !filePath.includes("node_modules") && !filePath.includes(".git") && !filePath.includes("secrets/") + !filePath.includes("node_modules") && + !filePath.includes(".git") && + !toPosix(filePath).includes("secrets/") ) }) @@ -124,7 +126,9 @@ describe("RooIgnore Response Formatting", () => { controller.validateAccess = jest.fn().mockImplementation((filePath: string) => { // Only allow files not matching these patterns return ( - !filePath.includes("node_modules") && !filePath.includes(".git") && !filePath.includes("secrets/") + !filePath.includes("node_modules") && + !filePath.includes(".git") && + !toPosix(filePath).includes("secrets/") ) }) diff --git a/src/core/prompts/__tests__/utils.ts b/src/core/prompts/__tests__/utils.ts new file mode 100644 index 0000000000..f2ac4fec1e --- /dev/null +++ b/src/core/prompts/__tests__/utils.ts @@ -0,0 +1,7 @@ +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() +}