Skip to content

Commit e90da70

Browse files
test(tools): make SearchFilesTool path assertions platform-agnostic (#169)
The searchFilesTool spec mocked the `path` builtin (resolve -> join("/")). Under Windows CI's singleFork pool that override could be lost across files, leaving real `path.resolve` to emit backslash paths and fail the "/"-based assertions (a Windows-only failure). Drop the fragile `path` mock and derive the expected resolved path from the real `path.resolve` so the assertions hold on every platform.
1 parent a0bb8b6 commit e90da70

1 file changed

Lines changed: 9 additions & 14 deletions

File tree

src/core/tools/__tests__/searchFilesTool.spec.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,11 @@ import { searchFilesTool, SearchFilesTool } from "../SearchFilesTool"
1616
import { regexSearchFiles } from "../../../services/ripgrep"
1717
import { isPathOutsideWorkspace } from "../../../utils/pathUtils"
1818

19-
vi.mock("path", async () => {
20-
const originalPath = await vi.importActual("path")
21-
return {
22-
default: originalPath,
23-
...originalPath,
24-
resolve: vi.fn().mockImplementation((...args: string[]) => args.join("/")),
25-
}
26-
})
19+
// NOTE: we intentionally do NOT mock the `path` builtin. Mocking it globally is
20+
// fragile under Windows CI's singleFork pool (the override can be lost across files,
21+
// leaving the real `path.resolve` to produce backslash paths and fail "/"-based
22+
// assertions — a Windows-only flake). Assertions below derive the expected resolved
23+
// path with the real `path.resolve`, so they hold on every platform.
2724

2825
vi.mock("../../../services/ripgrep", () => ({
2926
regexSearchFiles: vi.fn(),
@@ -113,10 +110,9 @@ describe("SearchFilesTool", () => {
113110

114111
await searchFilesTool.execute({ path: "src", regex: "matching" }, mockTask as any, callbacks)
115112

116-
// path.resolve is mocked to join args, so cwd + "src" = "/test/workspace/src"
117113
expect(mockedRegexSearchFiles).toHaveBeenCalledWith(
118-
"/test/workspace",
119-
"/test/workspace/src",
114+
mockTask.cwd,
115+
path.resolve(mockTask.cwd, "src"),
120116
"matching",
121117
undefined,
122118
mockTask.rooIgnoreController,
@@ -135,10 +131,9 @@ describe("SearchFilesTool", () => {
135131
callbacks,
136132
)
137133

138-
// path.resolve is mocked to join args, so cwd + "src" = "/test/workspace/src"
139134
expect(mockedRegexSearchFiles).toHaveBeenCalledWith(
140-
"/test/workspace",
141-
"/test/workspace/src",
135+
mockTask.cwd,
136+
path.resolve(mockTask.cwd, "src"),
142137
"test",
143138
"*.ts",
144139
mockTask.rooIgnoreController,

0 commit comments

Comments
 (0)