Skip to content

Commit 2ab5aad

Browse files
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
1 parent 87b9b72 commit 2ab5aad

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

src/core/prompts/__tests__/custom-system-prompt.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { SYSTEM_PROMPT } from "../system"
22
import { defaultModeSlug, modes } from "../../../shared/modes"
33
import * as vscode from "vscode"
44
import * as fs from "fs/promises"
5+
import { toPosix } from "./utils"
56

67
// Mock the fs/promises module
78
jest.mock("fs/promises", () => ({
@@ -89,7 +90,7 @@ describe("File-Based Custom System Prompt", () => {
8990
const fileCustomSystemPrompt = "Custom system prompt from file"
9091
// When called with utf-8 encoding, return a string
9192
mockedFs.readFile.mockImplementation((filePath, options) => {
92-
if (filePath.toString().includes(`.roo/system-prompt-${defaultModeSlug}`) && options === "utf-8") {
93+
if (toPosix(filePath).includes(`.roo/system-prompt-${defaultModeSlug}`) && options === "utf-8") {
9394
return Promise.resolve(fileCustomSystemPrompt)
9495
}
9596
return Promise.reject({ code: "ENOENT" })
@@ -124,7 +125,7 @@ describe("File-Based Custom System Prompt", () => {
124125
// Mock the readFile to return content from a file
125126
const fileCustomSystemPrompt = "Custom system prompt from file"
126127
mockedFs.readFile.mockImplementation((filePath, options) => {
127-
if (filePath.toString().includes(`.roo/system-prompt-${defaultModeSlug}`) && options === "utf-8") {
128+
if (toPosix(filePath).includes(`.roo/system-prompt-${defaultModeSlug}`) && options === "utf-8") {
128129
return Promise.resolve(fileCustomSystemPrompt)
129130
}
130131
return Promise.reject({ code: "ENOENT" })

src/core/prompts/__tests__/responses-rooignore.test.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
import { formatResponse } from "../responses"
44
import { RooIgnoreController, LOCK_TEXT_SYMBOL } from "../../ignore/RooIgnoreController"
5-
import * as path from "path"
65
import { fileExistsAtPath } from "../../../utils/fs"
76
import * as fs from "fs/promises"
7+
import { toPosix } from "./utils"
88

99
// Mock dependencies
1010
jest.mock("../../../utils/fs")
@@ -82,7 +82,9 @@ describe("RooIgnore Response Formatting", () => {
8282
controller.validateAccess = jest.fn().mockImplementation((filePath: string) => {
8383
// Only allow files not matching these patterns
8484
return (
85-
!filePath.includes("node_modules") && !filePath.includes(".git") && !filePath.includes("secrets/")
85+
!filePath.includes("node_modules") &&
86+
!filePath.includes(".git") &&
87+
!toPosix(filePath).includes("secrets/")
8688
)
8789
})
8890

@@ -124,7 +126,9 @@ describe("RooIgnore Response Formatting", () => {
124126
controller.validateAccess = jest.fn().mockImplementation((filePath: string) => {
125127
// Only allow files not matching these patterns
126128
return (
127-
!filePath.includes("node_modules") && !filePath.includes(".git") && !filePath.includes("secrets/")
129+
!filePath.includes("node_modules") &&
130+
!filePath.includes(".git") &&
131+
!toPosix(filePath).includes("secrets/")
128132
)
129133
})
130134

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import * as fs from "fs/promises"
2+
import { PathLike } from "fs"
3+
4+
// Make a path take a unix-like form. Useful for making path comparisons.
5+
export function toPosix(filePath: PathLike | fs.FileHandle) {
6+
return filePath.toString().toPosix()
7+
}

0 commit comments

Comments
 (0)