T-165: tests
This commit is contained in:
parent
272d336603
commit
dbd3ca7480
2 changed files with 283 additions and 6 deletions
|
|
@ -26,8 +26,17 @@ const FIXED_TS = '2026-01-15T12:34:56.789Z';
|
|||
|
||||
const cleanup: (() => Promise<void> | void)[] = [];
|
||||
afterEach(async () => {
|
||||
// Run every cleanup step even if an earlier one fails, then surface the first failure.
|
||||
let firstError: unknown;
|
||||
for (const close of cleanup.splice(0).reverse()) {
|
||||
await close();
|
||||
try {
|
||||
await close();
|
||||
} catch (err) {
|
||||
firstError ??= err;
|
||||
}
|
||||
}
|
||||
if (firstError !== undefined) {
|
||||
throw firstError;
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -96,13 +105,12 @@ async function createIsolatedFixture(connectionString: string | undefined = url)
|
|||
const safeUrl = assertSafetyDatabaseUrl(connectionString);
|
||||
const schema = `stock_bot_safety_${randomUUID().replaceAll('-', '')}`;
|
||||
const admin = new Pool({ connectionString: safeUrl });
|
||||
// Registered before CREATE SCHEMA so the admin pool closes even if creation or teardown fails.
|
||||
cleanup.push(() => admin.end());
|
||||
await admin.query(`CREATE SCHEMA ${schema}`);
|
||||
cleanup.push(() => admin.query(`DROP SCHEMA ${schema} CASCADE`).then(() => undefined));
|
||||
const pool = new Pool(buildIsolatedPoolConfig(safeUrl, schema));
|
||||
cleanup.push(async () => {
|
||||
await pool.end();
|
||||
await admin.query(`DROP SCHEMA ${schema} CASCADE`);
|
||||
await admin.end();
|
||||
});
|
||||
cleanup.push(() => pool.end());
|
||||
|
||||
const { rows: schemaRows } = await pool.query<{ current_schema: string | null }>(
|
||||
'SELECT current_schema() AS current_schema'
|
||||
|
|
@ -237,6 +245,12 @@ describe.skipIf(!url)('PostgreSQL MCP trial-ref adapter', () => {
|
|||
expect(await defaultPort.hasResearchVisibleTrial(afterCutoffId)).toBe(false);
|
||||
expect(await defaultPort.hasResearchVisibleTrial('999999999')).toBe(false);
|
||||
expect(await defaultPort.hasResearchVisibleTrial('1; DROP TABLE trial_ledger')).toBe(false);
|
||||
// Largest bigint binds through $1::bigint without overflow and is simply unknown.
|
||||
expect(await defaultPort.hasResearchVisibleTrial('9223372036854775807')).toBe(false);
|
||||
const { rows: ledgerCount } = await f.pool.query<{ c: number }>(
|
||||
'SELECT count(*)::int AS c FROM trial_ledger'
|
||||
);
|
||||
expect(ledgerCount[0]?.c).toBe(3);
|
||||
|
||||
// Explicit schema option against the admin pool (default search_path)
|
||||
const scopedPort = createPostgresTrialRefPort({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue