-
Notifications
You must be signed in to change notification settings - Fork 2.5k
fix: resolve Windows test timeout in custom-system-prompt.spec.ts #7977
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
538f47b
01722c7
ca7de99
72b8c6f
e7dea2b
2eba8a1
20e8099
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,11 +39,12 @@ vi.mock("../../../utils/fs", () => ({ | |
| createDirectoriesForFile: vi.fn().mockResolvedValue([]), | ||
| })) | ||
|
|
||
| // 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 +122,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 = | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we extract this duplicated normalization logic into a helper function within the test file? I see the same code on lines 168-169. Something like: const normalizeFilePath = (filePath: string | Buffer): string => {
return typeof filePath === "string"
? filePath.replace(/\/g, "/")
: filePath.toString('utf-8').replace(/\/g, "/")
}Also, should we specify the encoding when calling |
||
| 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 +164,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" }) | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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/") | ||||||||||||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this intentional? I notice we're still using
Suggested change
|
||||||||||||||||
| ) | ||||||||||||||||
| }) | ||||||||||||||||
|
|
||||||||||||||||
|
|
@@ -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/") | ||||||||||||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same issue here - we're still using |
||||||||||||||||
| ) | ||||||||||||||||
| }) | ||||||||||||||||
|
|
||||||||||||||||
|
|
||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,2 @@ | ||
| 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() | ||
| } | ||
| // This file is no longer needed as we're using String.prototype.toPosix() directly | ||
cte marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
cte marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // from src/utils/path module which is imported in the test files | ||
Uh oh!
There was an error while loading. Please reload this page.