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
This commit is contained in:
Diarmid Mackenzie 2025-03-23 06:14:42 +00:00 committed by GitHub
parent 87b9b72b32
commit 2ab5aad183
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 17 additions and 5 deletions

View file

@ -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" })

View file

@ -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/")
)
})

View file

@ -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()
}