Skip to content

Commit 6252c09

Browse files
committed
fix test bug and path resolution bug
1 parent dd62a55 commit 6252c09

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/services/ripgrep/__tests__/regex-search-files.gitignore.integration.spec.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,18 @@ vi.mock("child_process", () => {
6262

6363
// Ensure fs/promises and file utils are mockable from tests
6464
// Provide explicit mock factory so readdir/readFile are defined vi.fn()
65-
vi.mock("fs/promises", () => ({
66-
readdir: vi.fn(),
67-
readFile: vi.fn(),
68-
}))
65+
vi.mock("fs/promises", () => {
66+
const mockReaddir = vi.fn()
67+
const mockReadFile = vi.fn()
68+
return {
69+
readdir: mockReaddir,
70+
readFile: mockReadFile,
71+
default: {
72+
readdir: mockReaddir,
73+
readFile: mockReadFile,
74+
},
75+
}
76+
})
6977
vi.mock("../../../utils/fs")
7078
// Mock fs so BaseIgnoreController's realpathSync won't touch the real filesystem
7179
vi.mock("fs", () => ({

src/services/ripgrep/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,9 @@ function formatResults(fileResults: SearchFileResult[], cwd: string): string {
235235

236236
// Group results by file name
237237
fileResults.slice(0, MAX_RESULTS).forEach((file) => {
238-
const relativeFilePath = path.relative(cwd, file.file)
238+
// If file.file is already a relative path, use it as-is
239+
// Otherwise, make it relative to cwd
240+
const relativeFilePath = path.isAbsolute(file.file) ? path.relative(cwd, file.file) : file.file
239241
if (!groupedResults[relativeFilePath]) {
240242
groupedResults[relativeFilePath] = []
241243

0 commit comments

Comments
 (0)