mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-27 01:41:40 +00:00
fix(test): stabilize memory vector dedupe assertion
This commit is contained in:
@@ -87,15 +87,6 @@ describe("memory vector dedupe", () => {
|
||||
).db;
|
||||
db.exec("CREATE TABLE IF NOT EXISTS chunks_vec (id TEXT PRIMARY KEY, embedding BLOB)");
|
||||
|
||||
const sqlSeen: string[] = [];
|
||||
const originalPrepare = db.prepare.bind(db);
|
||||
db.prepare = (sql: string) => {
|
||||
if (sql.includes("chunks_vec")) {
|
||||
sqlSeen.push(sql);
|
||||
}
|
||||
return originalPrepare(sql);
|
||||
};
|
||||
|
||||
(
|
||||
manager as unknown as { ensureVectorReady: (dims?: number) => Promise<boolean> }
|
||||
).ensureVectorReady = async () => true;
|
||||
@@ -110,12 +101,21 @@ describe("memory vector dedupe", () => {
|
||||
}
|
||||
).indexFile(entry, { source: "memory" });
|
||||
|
||||
const deleteIndex = sqlSeen.findIndex((sql) =>
|
||||
sql.includes("DELETE FROM chunks_vec WHERE id = ?"),
|
||||
);
|
||||
const insertIndex = sqlSeen.findIndex((sql) => sql.includes("INSERT INTO chunks_vec"));
|
||||
expect(deleteIndex).toBeGreaterThan(-1);
|
||||
expect(insertIndex).toBeGreaterThan(-1);
|
||||
expect(deleteIndex).toBeLessThan(insertIndex);
|
||||
db.exec(`
|
||||
CREATE TRIGGER IF NOT EXISTS fail_if_vector_row_not_deleted
|
||||
BEFORE INSERT ON chunks_vec
|
||||
WHEN EXISTS (SELECT 1 FROM chunks_vec WHERE id = NEW.id)
|
||||
BEGIN
|
||||
SELECT RAISE(FAIL, 'vector row not deleted before insert');
|
||||
END;
|
||||
`);
|
||||
|
||||
await expect(
|
||||
(
|
||||
manager as unknown as {
|
||||
indexFile: (entry: unknown, options: { source: "memory" }) => Promise<void>;
|
||||
}
|
||||
).indexFile(entry, { source: "memory" }),
|
||||
).resolves.toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user