Skip to content

Commit 6296649

Browse files
fixed test cases for windows
1 parent f74f907 commit 6296649

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

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

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,31 @@ describe("LibSQLVectorStore", () => {
2323

2424
afterAll(async () => {
2525
await vectorStore.deleteCollection()
26-
if (fs.existsSync(testBasePath)) {
27-
fs.rmSync(testBasePath, { recursive: true, force: true })
26+
await vectorStore.close()
27+
28+
// On Windows, file handles might not be released immediately.
29+
// Retry fs.rmSync a few times with a delay.
30+
let attempts = 0
31+
const maxAttempts = 5
32+
const delayMs = 200
33+
34+
while (attempts < maxAttempts) {
35+
try {
36+
if (fs.existsSync(testBasePath)) {
37+
fs.rmSync(testBasePath, { recursive: true, force: true })
38+
}
39+
break
40+
} catch (error: any) {
41+
if (error.code === "EBUSY" || error.code === "EPERM") {
42+
attempts++
43+
console.warn(
44+
`Attempt ${attempts} to remove ${testBasePath} failed due to file lock. Retrying in ${delayMs}ms...`,
45+
)
46+
await new Promise((resolve) => setTimeout(resolve, delayMs))
47+
} else {
48+
throw error
49+
}
50+
}
2851
}
2952
})
3053

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ export class LibSQLVectorStore implements IVectorStore {
210210
await this.executeWriteOperationWithRetry(async () => {
211211
const statements = points.map((point) => {
212212
const vectorStr = JSON.stringify(point.vector)
213+
const normalizedFilePath = path.normalize(point.payload.filePath)
213214
return {
214215
sql: `
215216
INSERT INTO ${this.tableName} (id, vector, filePath, codeChunk, startLine, endLine)
@@ -224,12 +225,12 @@ export class LibSQLVectorStore implements IVectorStore {
224225
args: [
225226
point.id,
226227
vectorStr,
227-
point.payload.filePath,
228+
normalizedFilePath,
228229
point.payload.codeChunk,
229230
point.payload.startLine,
230231
point.payload.endLine,
231232
vectorStr,
232-
point.payload.filePath,
233+
normalizedFilePath,
233234
point.payload.codeChunk,
234235
point.payload.startLine,
235236
point.payload.endLine,
@@ -390,4 +391,17 @@ export class LibSQLVectorStore implements IVectorStore {
390391
public async collectionExists(): Promise<boolean> {
391392
return this.tableExists()
392393
}
394+
395+
public async close(): Promise<void> {
396+
if (this.client) {
397+
try {
398+
await this.client.close()
399+
this.client = null
400+
console.log("LibSQL client closed.")
401+
} catch (error) {
402+
console.error("Failed to close LibSQL client:", error)
403+
throw error
404+
}
405+
}
406+
}
393407
}

0 commit comments

Comments
 (0)