From fbf31681879b2a232e36efc71539ff2a180f09a3 Mon Sep 17 00:00:00 2001 From: yannickmonney Date: Fri, 9 Oct 2026 17:32:03 +0200 Subject: [PATCH] fix(cli): preserve literal knowledge observation queries --- tools/cli/src/lib/deployment/observation-sql.test.ts | 12 ++++++++++++ tools/cli/src/lib/deployment/observation-sql.ts | 4 +++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/tools/cli/src/lib/deployment/observation-sql.test.ts b/tools/cli/src/lib/deployment/observation-sql.test.ts index c871617c65..cffb6b9759 100644 --- a/tools/cli/src/lib/deployment/observation-sql.test.ts +++ b/tools/cli/src/lib/deployment/observation-sql.test.ts @@ -25,6 +25,18 @@ const knowledge = [ corpus('private_knowledge'), corpus('public_web'), ].join('\n'); +test('corpus observations retain the complete anchored SQL pattern in both schemas', () => { + expect( + OBSERVATION_KNOWLEDGE_SQL.match( + /c\.relname ~ '\^chunk_vectors_\[0-9\]\+\$'/g, + ), + ).toHaveLength(2); + for (const schema of ['private_knowledge', 'public_web']) { + expect(OBSERVATION_KNOWLEDGE_SQL).toContain( + `c.relname ~ '^chunk_vectors_[0-9]+$'))\nFROM ${schema}.chunks;`, + ); + } +}); test('fixed queries are bounded read-only transactions without a cutover lock', () => { for (const sql of [OBSERVATION_APP_SQL, OBSERVATION_KNOWLEDGE_SQL]) { expect(sql.startsWith('BEGIN READ ONLY;')).toBe(true); diff --git a/tools/cli/src/lib/deployment/observation-sql.ts b/tools/cli/src/lib/deployment/observation-sql.ts index a854416285..29a1d84d2a 100644 --- a/tools/cli/src/lib/deployment/observation-sql.ts +++ b/tools/cli/src/lib/deployment/observation-sql.ts @@ -36,7 +36,9 @@ const corpus = ( FROM ${schema}.chunks;`; export const OBSERVATION_KNOWLEDGE_SQL = ACCEPTANCE_SQL['knowledge-db'].replace( 'ROLLBACK;', - `${corpus('private_knowledge')}\n${corpus('public_web')}\nROLLBACK;`, + // A callback keeps the SQL regex's dollar-apostrophe literal; a replacement + // string would expand that sequence and consume its closing SQL quote. + () => `${corpus('private_knowledge')}\n${corpus('public_web')}\nROLLBACK;`, ); const count = z.number().int().nonnegative().safe(); const corpusSchema = z.strictObject({