Просмотр исходного кода

Fix regression test to use proper test helpers

Use insertTestDocument and createTestCollection helpers
to match existing test patterns.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Brendan McCord 4 месяцев назад
Родитель
Сommit
aea494bb24
1 измененных файлов с 21 добавлено и 21 удалено
  1. 21 21
      src/store.test.ts

+ 21 - 21
src/store.test.ts

@@ -1860,36 +1860,36 @@ describe("LlamaCpp Integration", () => {
   // The fix uses a two-step approach: vector query first, then separate JOINs.
   test("searchVec uses two-step query to avoid sqlite-vec JOIN hang", async () => {
     const store = await createTestStore();
+    const collectionName = await createTestCollection();
 
-    // Add test document with embedding
-    await store.addDocument("collection", "test.md", "Test content for vector search");
-    await store.updateIndex();
-
-    // Generate embedding for the test doc
-    const llm = (await import("./llm.js")).getDefaultLlamaCpp();
-    const embedding = await llm.embed("Test content for vector search");
-    if (embedding) {
-      // Manually insert vector to test the query path
-      const hash = hashContent("Test content for vector search");
-      store.db.prepare(`
-        INSERT OR REPLACE INTO content_vectors (hash, seq, pos) VALUES (?, 0, 0)
-      `).run(hash);
-      store.db.prepare(`
-        INSERT OR REPLACE INTO vectors_vec (hash_seq, embedding) VALUES (?, ?)
-      `).run(`${hash}_0`, new Float32Array(embedding.embedding));
-    }
+    const hash = "regression_test_hash";
+    await insertTestDocument(store.db, collectionName, {
+      name: "regression-doc",
+      hash,
+      body: "Test content for vector search regression",
+      filepath: "/test/regression.md",
+      displayPath: "regression.md",
+    });
+
+    // Create vector table and insert a test vector
+    store.ensureVecTable(768);
+    const embedding = Array(768).fill(0).map(() => Math.random());
+    store.db.prepare(`INSERT INTO content_vectors (hash, seq, pos, model, embedded_at) VALUES (?, 0, 0, 'test', ?)`).run(hash, new Date().toISOString());
+    store.db.prepare(`INSERT INTO vectors_vec (hash_seq, embedding) VALUES (?, ?)`).run(`${hash}_0`, new Float32Array(embedding));
 
     // This should complete quickly (not hang) due to the two-step fix
+    // The old code with JOINs in the sqlite-vec query would hang indefinitely
     const startTime = Date.now();
     const results = await store.searchVec("test content", "embeddinggemma", 5);
     const elapsed = Date.now() - startTime;
 
-    // If the query took more than 10 seconds, something is wrong
-    // (the hang bug would cause it to never return)
-    expect(elapsed).toBeLessThan(10000);
+    // If the query took more than 5 seconds, something is wrong
+    // (the hang bug would cause it to never return at all)
+    expect(elapsed).toBeLessThan(5000);
+    expect(results.length).toBeGreaterThan(0);
 
     await cleanupTestDb(store);
-  }, 30000);
+  });
 
   test("expandQuery returns original plus expanded queries", async () => {
     const store = await createTestStore();