Files
OmniRoute/tests/unit/memory/fts5-query-sanitize.test.ts
Egor 9f67e5cc74 fix(memory): sanitize FTS5 MATCH in vector hybrid search too
searchHybrid in vectorStore.ts runs its own raw FTS5 MATCH — the earlier
retrieval.ts fix missed it, so hybrid queries with punctuation still threw
'fts5: syntax error'. Extracted the sanitizer to src/lib/memory/ftsQuery.ts
(no import cycle) and applied it at all three MATCH sites; punctuation-only
queries now yield a non-matching '""' phrase instead of an error.
2026-07-31 10:29:15 +03:00

32 lines
1.1 KiB
TypeScript

import { describe, it } from "node:test";
import assert from "node:assert/strict";
import { toFts5MatchQuery } from "../../../src/lib/memory/retrieval";
describe("memory retrieval toFts5MatchQuery", () => {
it("keeps plain terms and joins with AND", () => {
assert.strictEqual(toFts5MatchQuery("hello world"), '"hello" AND "world"');
});
it("strips FTS5 syntax characters", () => {
assert.strictEqual(
toFts5MatchQuery("Чем занимается пользователь?"),
'"Чем" AND "занимается" AND "пользователь"'
);
});
it("strips quotes, colons, parentheses and dashes", () => {
assert.strictEqual(
toFts5MatchQuery('model "gpt-4o": (fast) OR NOT [x]'),
'"model" AND "gpt4o" AND "fast" AND "OR" AND "NOT" AND "x"'
);
});
it("keeps punctuation-only input as a non-matching quoted phrase", () => {
assert.strictEqual(toFts5MatchQuery("???! ..."), '""');
});
it("returns non-matching quoted phrase for empty input", () => {
assert.strictEqual(toFts5MatchQuery(""), '""');
});
});