Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

test: follow the #5824 vector statement into search/vector-statement.ts

garrytanb065afd8d659
diff --git a/test/fixtures/goldens/rls-scope-inventory.json b/test/fixtures/goldens/rls-scope-inventory.json
index 51240daf15..f1ea1818c4 100644
--- a/test/fixtures/goldens/rls-scope-inventory.json
+++ b/test/fixtures/goldens/rls-scope-inventory.json
@@ -3291,10 +3291,11 @@
"listStaleChunks": 1,
"listStalePagesForExtraction": 1,
"readPageSnapshot": 1,
+ "runVectorAttempt": 1,
"searchKeyword": 1,
"searchKeywordChunks": 1,
"searchTitles": 1,
- "searchVector": 2
+ "searchVector": 1
},
"helper": "withScopedReadTransaction",
"scoping": {
@@ -3335,6 +3336,7 @@
"executeRaw": "none",
"executeRawDirect": "none",
"expireFact": "none",
+ "explainVectorSearch": "via:runVectorAttempt",
"findAnomalies": "none",
"findByTitleFuzzy": "none",
"findCandidateDuplicates": "none",
@@ -3446,6 +3448,7 @@
"rlsScopeBindingEnabled": "none",
"runMigration": "none",
"runUnsafe": "none",
+ "runVectorAttempt": "direct",
"searchKeyword": "direct",
"searchKeywordChunks": "direct",
"searchTakes": "none",
@@ -3478,6 +3481,7 @@
"upsertChunks": "via:_upsertChunksOnce",
"upsertEventProjection": "none",
"upsertFile": "none",
+ "vectorIterativeScanSupported": "none",
"withReservedConnection": "none",
"withScopedReadTransaction": "none",
"writeContradictionsRun": "none"
diff --git a/test/helpers/source-surface.ts b/test/helpers/source-surface.ts
index 9b0df3f199..f89bd7dfe7 100644
--- a/test/helpers/source-surface.ts
+++ b/test/helpers/source-surface.ts
@@ -100,7 +100,7 @@ export const SOURCE_SURFACES = {
},
migrate: { files: ['src/core/migrate.ts'], dirs: ['src/core/schema-migrations'] },
'pglite-engine': { files: ['src/core/pglite-engine.ts'], dirs: ['src/core/engine-sql'] },
- 'postgres-engine': { files: ['src/core/postgres-engine.ts'], dirs: ['src/core/engine-sql'] },
+ 'postgres-engine': { files: ['src/core/postgres-engine.ts', 'src/core/search/vector-statement.ts'], dirs: ['src/core/engine-sql'] },
doctor: { files: ['src/commands/doctor.ts'], dirs: ['src/commands/doctor'] },
} satisfies Record<string, SurfaceDef>;
diff --git a/test/postgres-engine.test.ts b/test/postgres-engine.test.ts
index 251c672a3a..ce2e24f437 100644
--- a/test/postgres-engine.test.ts
+++ b/test/postgres-engine.test.ts
@@ -25,6 +25,9 @@ import { describe, test, expect } from 'bun:test';
import { surfaceFileSource } from './helpers/source-surface.ts';
const SRC = surfaceFileSource('postgres-engine', 'src/core/postgres-engine.ts');
+// #5824: the vector statement (SQL text, date bounds, timeout constant) is
+// built in search/vector-statement.ts, shared with PGLite and doctor.
+const VECTOR_STATEMENT_SRC = surfaceFileSource('postgres-engine', 'src/core/search/vector-statement.ts');
describe('postgres-engine / search path timeout isolation', () => {
test('no bare `SET statement_timeout` statement survives', () => {
@@ -77,10 +80,11 @@ describe('postgres-engine / search path timeout isolation', () => {
test('both search methods use SET LOCAL for the timeout', () => {
const keyword = extractMethod(SRC, 'searchKeyword');
- const vector = extractMethod(SRC, 'searchVector');
+ const attempt = stripComments(SRC).split('private runVectorAttempt(')[1]!.split('async getEmbeddingsByChunkIds(')[0]!;
expect(keyword).toMatch(/SET\s+LOCAL\s+statement_timeout/);
- expect(vector).toMatch(/set_config\('statement_timeout', \$\{String\(remainingVectorBudget\(deadline\)\)\}, true\)/);
- expect(vector).toContain('withVectorSettings');
+ expect(VECTOR_STATEMENT_SRC).toContain("export const SET_STATEMENT_TIMEOUT_SQL = `SELECT set_config('statement_timeout', $1, true)`;");
+ expect(attempt).toMatch(/tx\.unsafe\(SET_STATEMENT_TIMEOUT_SQL, \[String\(remainingVectorBudget\(deadline\)\)\]\)/);
+ expect(attempt).toContain('withVectorSettings');
});
test('connect() with poolSize honors resolvePrepare (PgBouncer regression guard)', () => {
@@ -117,13 +121,22 @@ describe('postgres-engine / search date filtering', () => {
const expectedDateExpr = 'COALESCE(p.effective_date, p.updated_at, p.created_at)';
const staleDatePredicate = /COALESCE\(p\.updated_at,\s*p\.created_at\)\s*[<>]\s*\$/;
- for (const methodName of ['searchKeyword', 'searchKeywordChunks', 'searchVector']) {
+ for (const methodName of ['searchKeyword', 'searchKeywordChunks']) {
const fn = stripComments(extractMethod(SRC, methodName));
expect(countOccurrences(fn, expectedDateExpr)).toBe(2);
expect(fn).not.toMatch(staleDatePredicate);
}
});
+
+ test('vector search spells the same effective_date-first fallback per column (#5824)', () => {
+ const builder = stripComments(VECTOR_STATEMENT_SRC);
+ expect(builder).toContain('`AND (p.effective_date ${op} ${bound} OR (p.effective_date IS NULL AND (p.updated_at ${op} ${bound} OR (p.updated_at IS NULL AND p.created_at ${op} ${bound}))))`');
+ expect(builder).toMatch(/opts\?\.afterDate\) filters\.push\(dateBound\(/);
+ expect(builder).toMatch(/opts\?\.beforeDate\) filters\.push\(dateBound\(/);
+ expect(builder).not.toMatch(/COALESCE\(p\.updated_at,\s*p\.created_at\)/);
+ expect(stripComments(extractMethod(SRC, 'searchVector'))).toContain('buildVectorSearchStatement(');
+ });
});
function stripComments(s: string): string {
diff --git a/test/postgres-rls-scope-inventory.test.ts b/test/postgres-rls-scope-inventory.test.ts
index fb32003e5d..3d99dce7c8 100644
--- a/test/postgres-rls-scope-inventory.test.ts
+++ b/test/postgres-rls-scope-inventory.test.ts
@@ -19,8 +19,10 @@
*
* Reconciliation with the plan's "23 scoped sites": the source has 23 lines
* naming `withScopedReadTransaction` = 1 definition + 22 call sites, in 21
- * methods (searchVector has 2); evidence delivery's getChunkWindows adds one
- * (23 call sites, 22 methods). The golden pins the exact numbers.
+ * methods (searchVector had 2); evidence delivery's getChunkWindows adds one,
+ * and #5824 moves searchVector's ANN-attempt call into runVectorAttempt
+ * (shared with explainVectorSearch): 23 call sites, 23 methods. The golden
+ * pins the exact numbers.
*/
import { describe, expect, test } from 'bun:test';
@@ -149,7 +151,7 @@ describe('EO4 RLS scope inventory (master)', () => {
const callSites = Object.values(capture.ast).reduce((a, m) => a + m.directCallSites, 0);
expect(callSites).toBe(23);
- expect(Object.values(capture.ast).filter((m) => m.directCallSites > 0).length).toBe(22);
+ expect(Object.values(capture.ast).filter((m) => m.directCallSites > 0).length).toBe(23);
const byMethod = new Map<string, RuntimeObservation[]>();
for (const [key, obs] of Object.entries(capture.runtime)) {
diff --git a/test/select-e2e.test.ts b/test/select-e2e.test.ts
index 5a7ef24041..20b4bcf7c0 100644
--- a/test/select-e2e.test.ts
+++ b/test/select-e2e.test.ts
@@ -176,6 +176,7 @@ describe("selectTests", () => {
"test/e2e/search-swamp.test.ts",
"test/e2e/unsupported-embedding-identity-postgres.test.ts",
"test/e2e/vector-candidate-safety-postgres.test.ts",
+ "test/e2e/vector-plan-real-column-postgres.test.ts",
]);
});
@@ -264,6 +265,7 @@ describe("selectTests", () => {
"test/e2e/search-swamp.test.ts",
"test/e2e/unsupported-embedding-identity-postgres.test.ts",
"test/e2e/vector-candidate-safety-postgres.test.ts",
+ "test/e2e/vector-plan-real-column-postgres.test.ts",
]);
});