T-69: Bug sweep (3 bugs: T-64, T-67, T-71)

This commit is contained in:
Studio 2026-11-27 19:23:09 -05:00
parent 2d40d5146a
commit 7f1c9e70ef
4 changed files with 613 additions and 23 deletions

View file

@ -92,6 +92,68 @@ async function until(check: () => Promise<boolean>): Promise<void> {
throw new Error('Timed out waiting for PostgreSQL advisory-lock waiter');
}
interface ProtectionTriggerRow {
relname: string;
tgname: string;
proname: string;
tgenabled: string;
}
const EXPECTED_PROTECTION_TRIGGERS: ProtectionTriggerRow[] = [
{
relname: 'trial_ledger',
tgname: 'trial_ledger_no_truncate',
proname: 'reject_research_evidence_mutation',
tgenabled: 'O',
},
{
relname: 'trial_ledger',
tgname: 'trial_ledger_retained',
proname: 'reject_research_evidence_mutation',
tgenabled: 'O',
},
{
relname: 'vault_evaluations',
tgname: 'vault_evaluations_cap',
proname: 'enforce_vault_evaluation_cap',
tgenabled: 'O',
},
{
relname: 'vault_evaluations',
tgname: 'vault_evaluations_cap_after',
proname: 'verify_vault_evaluation_cap_after',
tgenabled: 'O',
},
{
relname: 'vault_evaluations',
tgname: 'vault_evaluations_no_truncate',
proname: 'reject_research_evidence_mutation',
tgenabled: 'O',
},
{
relname: 'vault_evaluations',
tgname: 'vault_evaluations_retained',
proname: 'reject_research_evidence_mutation',
tgenabled: 'O',
},
];
async function listProtectionTriggers(pool: Pool, schema: string): Promise<ProtectionTriggerRow[]> {
const result = await pool.query<ProtectionTriggerRow>(
`SELECT c.relname, t.tgname, p.proname, t.tgenabled::text AS tgenabled
FROM pg_trigger t
JOIN pg_class c ON c.oid = t.tgrelid
JOIN pg_namespace n ON n.oid = c.relnamespace
JOIN pg_proc p ON p.oid = t.tgfoid
WHERE NOT t.tgisinternal
AND n.nspname = $1
AND c.relname IN ('trial_ledger', 'vault_evaluations')
ORDER BY c.relname COLLATE "C", t.tgname COLLATE "C"`,
[schema]
);
return result.rows;
}
interface TrialInsertOverrides {
principalId?: string;
campaignId?: string | null;
@ -792,6 +854,7 @@ describe.skipIf(!url)(
client.release();
}
expect(await countRows(f.pool, 'vault_evaluations')).toBe(11);
expect(await listProtectionTriggers(f.pool, f.schema)).toEqual(EXPECTED_PROTECTION_TRIGGERS);
const g = await createIsolatedFixture();
const seeder = await g.pool.connect();
@ -809,6 +872,7 @@ describe.skipIf(!url)(
}
await expectPgErrorCode(insertVaultEvaluation(g.pool), '23514', /at most 10 evaluations/i);
expect(await countRows(g.pool, 'vault_evaluations')).toBe(10);
expect(await listProtectionTriggers(g.pool, g.schema)).toEqual(EXPECTED_PROTECTION_TRIGGERS);
});
test('a single 10-row INSERT fills the cap exactly and the next insert is rejected', async () => {
@ -1063,6 +1127,12 @@ describe.skipIf(!url)(
client.release();
}
expect(await countRows(f.pool, 'vault_evaluations')).toBe(0);
expect(await listProtectionTriggers(f.pool, f.schema)).toEqual(EXPECTED_PROTECTION_TRIGGERS);
});
test('research-track migration leaves all 6 trial_ledger and vault_evaluations protection triggers enabled (T-64)', async () => {
const f = await createIsolatedFixture();
expect(await listProtectionTriggers(f.pool, f.schema)).toEqual(EXPECTED_PROTECTION_TRIGGERS);
});
test('failed burns (passed = false, negative Sharpe, NULL notes) still count toward the yearly cap', async () => {