From 872debd9c65a028fc3092f5c7eb7881d3e9175f0 Mon Sep 17 00:00:00 2001 From: Studio Date: Thu, 3 Dec 2026 14:59:15 -0500 Subject: [PATCH] =?UTF-8?q?T-200:=20M2.1t=20(retry=20of=20T-197)=20?= =?UTF-8?q?=E2=80=94=20Land=20the=20PostgreSQL=20executor=20factory=20for?= =?UTF-8?q?=20the=20MCP=20copilot=20stdio=20host:=20`openResearchCopilotEx?= =?UTF-8?q?ecutor(config)`=20in=20`libs/data/postgres/src/research-copilot?= =?UTF-8?q?-executor.ts`,=20reusing=20the=20finished=20T-197=20branch=20wo?= =?UTF-8?q?rk=20and=20completing=20QA=20sign-off=20(no=20new=20deps,=20no?= =?UTF-8?q?=20DuckDB,=20no=20bin,=20no=20curate-etl=20changes)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/postgres/mcp-copilot-executor.test.ts | 62 +++++++++++++--------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/test/postgres/mcp-copilot-executor.test.ts b/test/postgres/mcp-copilot-executor.test.ts index 029f4973..e85a9134 100644 --- a/test/postgres/mcp-copilot-executor.test.ts +++ b/test/postgres/mcp-copilot-executor.test.ts @@ -295,10 +295,10 @@ describe.skipIf(!url)('PostgreSQL MCP copilot executor integration', () => { schema: f.schema, vaultCutoffTs: VAULT_CUTOFF_TS, }); - expect(await trialLookup.hasVisibleTrialRef('1')).toBe(true); - expect(await trialLookup.hasVisibleTrialRef('2')).toBe(false); + expect(await trialLookup.hasResearchVisibleTrial('1')).toBe(true); + expect(await trialLookup.hasResearchVisibleTrial('2')).toBe(false); - // 2. Findings idempotent replay (both same-ID 23505 path and same-key ON CONFLICT path). + // 2. Findings idempotent replay (both same-key ON CONFLICT and same-ID 23505 paths). const writePort = createPostgresFindingWritePort({ executor: handle.executor, schema: f.schema, @@ -315,33 +315,45 @@ describe.skipIf(!url)('PostgreSQL MCP copilot executor integration', () => { summary: 'Verifies SQLSTATE 23505 and ON CONFLICT replay through openResearchCopilotExecutor.', trialRefs: ['1'], evidenceRefs: ['evidence:e1'], - idempotencyKey, }; - const first = await writePort.appendFinding(baseFinding); - expect(first.replayed).toBe(false); - expect(first.id).toBe(findingId); - expect(first.createdAt).toBe(FIXED_TS); - - // Same-key replay with a different ID and later timestamp must return the original finding. - const sameKeyReplay = await writePort.appendFinding({ - ...baseFinding, - id: `finding-${randomUUID()}`, - createdAt: '2026-02-01T00:00:00.000Z', + const first = await writePort.appendFinding(baseFinding, idempotencyKey); + expect(first).toEqual({ + status: 'created', + id: findingId, + createdAt: FIXED_TS, }); - expect(sameKeyReplay.replayed).toBe(true); - expect(sameKeyReplay.id).toBe(findingId); - expect(sameKeyReplay.createdAt).toBe(FIXED_TS); - // Same-ID replay without idempotencyKey triggers SQLSTATE 23505 primary-key replay path. - const sameIdReplay = await writePort.appendFinding({ - ...baseFinding, - idempotencyKey: undefined, - createdAt: '2026-03-01T00:00:00.000Z', + // Same-key replay with a different ID and later timestamp (ON CONFLICT DO NOTHING path) + // must return the original finding and timestamp. + const sameKeyReplay = await writePort.appendFinding( + { + ...baseFinding, + id: `finding-${randomUUID()}`, + createdAt: '2026-02-01T00:00:00.000Z', + }, + idempotencyKey + ); + expect(sameKeyReplay).toEqual({ + status: 'replayed', + id: findingId, + createdAt: FIXED_TS, + }); + + // Same-ID replay with the same idempotencyKey triggers PostgreSQL PK SQLSTATE 23505; + // executor must preserve SQLSTATE 23505 so the adapter resolves the original finding. + const sameIdReplay = await writePort.appendFinding( + { + ...baseFinding, + createdAt: '2026-03-01T00:00:00.000Z', + }, + idempotencyKey + ); + expect(sameIdReplay).toEqual({ + status: 'replayed', + id: findingId, + createdAt: FIXED_TS, }); - expect(sameIdReplay.replayed).toBe(true); - expect(sameIdReplay.id).toBe(findingId); - expect(sameIdReplay.createdAt).toBe(FIXED_TS); const rowCount = await handle.executor.query<{ count: string }>( `SELECT count(*)::text AS count FROM ${f.schema}.findings`