T-151: M2.1i — findings + provider_caveats append-only PostgreSQL migration (research track, 37-research-findings.sql) with fresh-database schema tests (no adapters, no new deps)
This commit is contained in:
parent
c16d6b3f60
commit
310354b54a
3 changed files with 77 additions and 29 deletions
|
|
@ -29,16 +29,26 @@ async function createIsolatedFixture() {
|
|||
const schema = `stock_bot_safety_${randomUUID().replaceAll('-', '')}`;
|
||||
const admin = new Pool({ connectionString: url });
|
||||
await admin.query(`CREATE SCHEMA ${schema}`);
|
||||
const pool = new Pool({
|
||||
connectionString: url,
|
||||
options: `-c search_path=${schema} -c statement_timeout=5000 -c lock_timeout=5000`,
|
||||
});
|
||||
const poolUrl = new URL(url);
|
||||
const existingOptions = poolUrl.searchParams.get('options')?.trim();
|
||||
const fixtureOptions = `-c search_path=${schema} -c statement_timeout=5000 -c lock_timeout=5000`;
|
||||
poolUrl.searchParams.set(
|
||||
'options',
|
||||
existingOptions ? `${existingOptions} ${fixtureOptions}` : fixtureOptions
|
||||
);
|
||||
const pool = new Pool({ connectionString: poolUrl.toString() });
|
||||
cleanup.push(async () => {
|
||||
await pool.end();
|
||||
await admin.query(`DROP SCHEMA ${schema} CASCADE`);
|
||||
await admin.end();
|
||||
});
|
||||
|
||||
const activeSchema = (await pool.query<{ schema: string }>('SELECT current_schema() AS schema'))
|
||||
.rows[0]?.schema;
|
||||
if (activeSchema !== schema) {
|
||||
throw new Error(`Expected active fixture schema ${schema}, got ${activeSchema ?? 'null'}`);
|
||||
}
|
||||
|
||||
// Bootstrap pre-additive tables needed by the research migration track.
|
||||
for (const filename of [
|
||||
'06-create-backtest-tables.sql',
|
||||
|
|
@ -308,14 +318,15 @@ describe.skipIf(!url)('findings and provider_caveats PostgreSQL schema', () => {
|
|||
expect(first.evidence_refs).toEqual(['artifact:drift-v1']);
|
||||
expect(first.idempotency_key).toBe('req-001');
|
||||
|
||||
// Second row exercises dead_end, empty evidence_refs, and exact boundary lengths/cardinalities.
|
||||
// Second row exercises dead_end, empty evidence_refs, and exact boundary lengths/cardinalities
|
||||
// including Unicode NBSP / ideographic-space padding around max-length title and summary.
|
||||
const maxRefs = Array.from({ length: 32 }, (_, i) => `${i}`.padStart(256, 'r'));
|
||||
const boundary = (
|
||||
await insertFinding(f.pool, {
|
||||
id: 'finding-002',
|
||||
kind: 'dead_end',
|
||||
title: ` ${'t'.repeat(256)} `,
|
||||
summary: 's'.repeat(4096),
|
||||
title: `\u00A0${'t'.repeat(256)}\u00A0`,
|
||||
summary: `\u00A0\u3000${'s'.repeat(4096)}\u00A0`,
|
||||
createdAt: '2026-02-01T00:00:00.000Z',
|
||||
trialRefs: maxRefs,
|
||||
evidenceRefs: [],
|
||||
|
|
@ -347,24 +358,37 @@ describe.skipIf(!url)('findings and provider_caveats PostgreSQL schema', () => {
|
|||
test('findings rejects invalid kind, blank or oversized fields, malformed ref arrays, and invalid idempotency keys', async () => {
|
||||
const f = await createIsolatedFixture();
|
||||
|
||||
// Blank / whitespace-only id and status
|
||||
// Blank / whitespace-only (ASCII and ECMAScript Unicode) id and status
|
||||
const unicodeBlanks = ['\u00A0', '\u00A0\u2003\u3000\uFEFF', '\u2028\u2029'];
|
||||
await expectPgErrorCode(insertFinding(f.pool, { id: '' }), '23514');
|
||||
await expectPgErrorCode(insertFinding(f.pool, { id: ' \t\n ' }), '23514');
|
||||
await expectPgErrorCode(insertFinding(f.pool, { status: '' }), '23514');
|
||||
await expectPgErrorCode(insertFinding(f.pool, { status: ' \t\r\n ' }), '23514');
|
||||
for (const blank of unicodeBlanks) {
|
||||
await expectPgErrorCode(insertFinding(f.pool, { id: blank }), '23514');
|
||||
await expectPgErrorCode(insertFinding(f.pool, { status: blank }), '23514');
|
||||
}
|
||||
|
||||
// Invalid kind
|
||||
await expectPgErrorCode(insertFinding(f.pool, { kind: 'hypothesis' }), '23514');
|
||||
await expectPgErrorCode(insertFinding(f.pool, { kind: 'FINDING' }), '23514');
|
||||
await expectPgErrorCode(insertFinding(f.pool, { kind: '' }), '23514');
|
||||
|
||||
// Blank, whitespace-only, or oversized title / summary
|
||||
// Blank, whitespace-only (ASCII and ECMAScript Unicode), or oversized title / summary
|
||||
await expectPgErrorCode(insertFinding(f.pool, { title: '' }), '23514');
|
||||
await expectPgErrorCode(insertFinding(f.pool, { title: ' \t\n\r ' }), '23514');
|
||||
await expectPgErrorCode(insertFinding(f.pool, { title: 't'.repeat(257) }), '23514');
|
||||
await expectPgErrorCode(
|
||||
insertFinding(f.pool, { title: `\u00A0${'t'.repeat(257)}\u00A0` }),
|
||||
'23514'
|
||||
);
|
||||
await expectPgErrorCode(insertFinding(f.pool, { summary: '' }), '23514');
|
||||
await expectPgErrorCode(insertFinding(f.pool, { summary: ' \t\n\r ' }), '23514');
|
||||
await expectPgErrorCode(insertFinding(f.pool, { summary: 's'.repeat(4097) }), '23514');
|
||||
for (const blank of unicodeBlanks) {
|
||||
await expectPgErrorCode(insertFinding(f.pool, { title: blank }), '23514');
|
||||
await expectPgErrorCode(insertFinding(f.pool, { summary: blank }), '23514');
|
||||
}
|
||||
|
||||
// Cardinality > 32
|
||||
const refs33 = Array.from({ length: 33 }, (_, i) => `ref-${i}`);
|
||||
|
|
@ -401,6 +425,9 @@ describe.skipIf(!url)('findings and provider_caveats PostgreSQL schema', () => {
|
|||
// Invalid idempotency_key (empty, whitespace-only, > 128 chars)
|
||||
await expectPgErrorCode(insertFinding(f.pool, { idempotencyKey: '' }), '23514');
|
||||
await expectPgErrorCode(insertFinding(f.pool, { idempotencyKey: ' \t\n ' }), '23514');
|
||||
for (const blank of unicodeBlanks) {
|
||||
await expectPgErrorCode(insertFinding(f.pool, { idempotencyKey: blank }), '23514');
|
||||
}
|
||||
await expectPgErrorCode(insertFinding(f.pool, { idempotencyKey: 'k'.repeat(129) }), '23514');
|
||||
|
||||
expect((await f.pool.query('SELECT count(*)::int AS c FROM findings')).rows[0].c).toBe(0);
|
||||
|
|
@ -445,7 +472,14 @@ describe.skipIf(!url)('findings and provider_caveats PostgreSQL schema', () => {
|
|||
const defaulted = (await insertProviderCaveat(f.pool, { id: 'caveat-002' })).rows[0];
|
||||
expect(defaulted.created_at).toBeInstanceOf(Date);
|
||||
|
||||
for (const blank of ['', ' ', '\t\n\r']) {
|
||||
for (const blank of [
|
||||
'',
|
||||
' ',
|
||||
'\t\n\r',
|
||||
'\u00A0',
|
||||
'\u00A0\u2003\u3000\uFEFF',
|
||||
'\u2028\u2029',
|
||||
]) {
|
||||
await expectPgErrorCode(insertProviderCaveat(f.pool, { id: blank }), '23514');
|
||||
await expectPgErrorCode(insertProviderCaveat(f.pool, { provider: blank }), '23514');
|
||||
await expectPgErrorCode(insertProviderCaveat(f.pool, { dataset: blank }), '23514');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue