Skip to content

Commit 85cec2e

Browse files
committed
refactor: address review comments - improve path normalization
- Keep check for './' after normalization as path.posix.normalize('./') returns './' - Use actual Node.js path.posix implementation in tests instead of custom mock - Apply path.posix.normalize to cleanedPrefix for consistency All 381 code-index tests pass
1 parent 8e42821 commit 85cec2e

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

src/services/code-index/vector-store/__tests__/qdrant-client.spec.ts

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,14 @@ vitest.mock("../../../../i18n", () => ({
2121
return key // Just return the key for other cases
2222
},
2323
}))
24-
vitest.mock("path", () => ({
25-
...vitest.importActual("path"),
26-
sep: "/",
27-
posix: {
28-
normalize: (p: string) => {
29-
// Simple implementation of posix.normalize for testing
30-
// Remove redundant slashes and handle . and .. segments
31-
return (
32-
p
33-
.split("/")
34-
.filter((segment) => segment !== "" && segment !== ".")
35-
.join("/") || "."
36-
)
37-
},
38-
},
39-
}))
24+
vitest.mock("path", async () => {
25+
const actual = await vitest.importActual("path")
26+
return {
27+
...actual,
28+
sep: "/",
29+
posix: actual.posix,
30+
}
31+
})
4032

4133
const mockQdrantClientInstance = {
4234
getCollection: vitest.fn(),

src/services/code-index/vector-store/qdrant-client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,15 +377,15 @@ export class QdrantVectorStore implements IVectorStore {
377377
if (directoryPrefix) {
378378
// Check if the path represents current directory
379379
const normalizedPrefix = path.posix.normalize(directoryPrefix.replace(/\\/g, "/"))
380-
if (normalizedPrefix === "." || normalizedPrefix === "" || normalizedPrefix === "./") {
380+
if (normalizedPrefix === "." || normalizedPrefix === "./" || normalizedPrefix === "") {
381381
// Don't create a filter - search entire workspace
382382
filter = undefined
383383
} else {
384384
// Remove leading "./" from paths like "./src" to normalize them
385385
const cleanedPrefix = normalizedPrefix.startsWith("./")
386386
? normalizedPrefix.slice(2)
387387
: normalizedPrefix
388-
const segments = cleanedPrefix.split("/").filter(Boolean)
388+
const segments = path.posix.normalize(cleanedPrefix).split("/").filter(Boolean)
389389
if (segments.length > 0) {
390390
filter = {
391391
must: segments.map((segment, index) => ({

0 commit comments

Comments
 (0)