Skip to content

Commit 32ffeb4

Browse files
committed
fix: Normalize Qdrant URL pathname to remove trailing slashes
revised in accordance with the suggestions from @daniel-lxs * #5033 (comment) * Normalize Qdrant URL pathname * #5033 (comment) * More robust test cases
1 parent 6450215 commit 32ffeb4

File tree

2 files changed

+80
-1
lines changed

2 files changed

+80
-1
lines changed

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

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,85 @@ describe("QdrantVectorStore", () => {
400400
})
401401
expect((vectorStoreWithHttpsPrefix as any).qdrantUrl).toBe("https://qdrant.ashbyfam.com/api")
402402
})
403+
404+
it("should normalize URL pathname by removing trailing slash for prefix", () => {
405+
const vectorStoreWithTrailingSlash = new QdrantVectorStore(
406+
mockWorkspacePath,
407+
"http://localhost:6333/api/",
408+
mockVectorSize,
409+
)
410+
expect(QdrantClient).toHaveBeenLastCalledWith({
411+
host: "localhost",
412+
https: false,
413+
port: 6333,
414+
prefix: "/api", // Trailing slash should be removed
415+
apiKey: undefined,
416+
headers: {
417+
"User-Agent": "Roo-Code",
418+
},
419+
})
420+
expect((vectorStoreWithTrailingSlash as any).qdrantUrl).toBe("http://localhost:6333/api/")
421+
})
422+
423+
it("should handle multiple path segments correctly for prefix", () => {
424+
const vectorStoreWithMultiSegment = new QdrantVectorStore(
425+
mockWorkspacePath,
426+
"http://localhost:6333/api/v1/qdrant",
427+
mockVectorSize,
428+
)
429+
expect(QdrantClient).toHaveBeenLastCalledWith({
430+
host: "localhost",
431+
https: false,
432+
port: 6333,
433+
prefix: "/api/v1/qdrant",
434+
apiKey: undefined,
435+
headers: {
436+
"User-Agent": "Roo-Code",
437+
},
438+
})
439+
expect((vectorStoreWithMultiSegment as any).qdrantUrl).toBe("http://localhost:6333/api/v1/qdrant")
440+
})
441+
442+
it("should handle complex URL with multiple segments, trailing slash, query params, and fragment", () => {
443+
const complexUrl = "https://example.com/ollama/api/v1/?key=value#pos"
444+
const vectorStoreComplex = new QdrantVectorStore(
445+
mockWorkspacePath,
446+
complexUrl,
447+
mockVectorSize,
448+
)
449+
expect(QdrantClient).toHaveBeenLastCalledWith({
450+
host: "example.com",
451+
https: true,
452+
port: 443,
453+
prefix: "/ollama/api/v1", // Trailing slash removed, query/fragment ignored
454+
apiKey: undefined,
455+
headers: {
456+
"User-Agent": "Roo-Code",
457+
},
458+
})
459+
expect((vectorStoreComplex as any).qdrantUrl).toBe(complexUrl)
460+
})
461+
462+
it("should ignore query parameters and fragments when determining prefix", () => {
463+
const vectorStoreWithQueryParams = new QdrantVectorStore(
464+
mockWorkspacePath,
465+
"http://localhost:6333/api/path?key=value#fragment",
466+
mockVectorSize,
467+
)
468+
expect(QdrantClient).toHaveBeenLastCalledWith({
469+
host: "localhost",
470+
https: false,
471+
port: 6333,
472+
prefix: "/api/path", // Query params and fragment should be ignored
473+
apiKey: undefined,
474+
headers: {
475+
"User-Agent": "Roo-Code",
476+
},
477+
})
478+
expect((vectorStoreWithQueryParams as any).qdrantUrl).toBe(
479+
"http://localhost:6333/api/path?key=value#fragment",
480+
)
481+
})
403482
})
404483

405484
describe("initialize", () => {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export class QdrantVectorStore implements IVectorStore {
5757
host: urlObj.hostname,
5858
https: useHttps,
5959
port: port,
60-
prefix: urlObj.pathname === "/" ? undefined : urlObj.pathname,
60+
prefix: urlObj.pathname === "/" ? undefined : urlObj.pathname.replace(/\/$/, ""),
6161
apiKey,
6262
headers: {
6363
"User-Agent": "Roo-Code",

0 commit comments

Comments
 (0)