T-159: tests

This commit is contained in:
Studio 2026-12-02 09:25:59 -05:00
parent d65016c851
commit ae01904cd6
2 changed files with 388 additions and 0 deletions

View file

@ -418,3 +418,108 @@ describe('createPostgresTrialRefLookupPort wired into createFileFindingTool', ()
expect(appended).toHaveLength(0);
});
});
describe('createPostgresTrialRefLookupPort (QA edge cases)', () => {
test('queries in-range 19-digit refs and rejects 19-digit refs above the signed BIGINT max', async () => {
const fake = createFakeExecutor([{ visible: 1 }]);
const port = createPostgresTrialRefLookupPort({
executor: fake.executor,
vaultCutoffTs: CUTOFF_MIDNIGHT_TS,
});
expect(await port.hasResearchVisibleTrial('1000000000000000000')).toBe(true);
expect(await port.hasResearchVisibleTrial('9223372036854775806')).toBe(true);
expect(await port.hasResearchVisibleTrial('9223372036854775900')).toBe(false);
expect(await port.hasResearchVisibleTrial('9999999999999999999')).toBe(false);
expect(fake.calls.map(c => c.params?.[0])).toEqual([
'1000000000000000000',
'9223372036854775806',
]);
});
test('rejects trailing-newline, tab, fullwidth-digit, and boxed-String refs without querying', async () => {
const fake = createFakeExecutor([{ visible: 1 }]);
const port = createPostgresTrialRefLookupPort({
executor: fake.executor,
vaultCutoffTs: CUTOFF_MIDNIGHT_TS,
});
for (const ref of ['42\n', '\n42', '4\t2', '42', '42\u0000', new String('42')] as unknown[]) {
expect(await port.hasResearchVisibleTrial(ref as string)).toBe(false);
}
expect(fake.calls).toHaveLength(0);
});
test('accepts the four-digit PostgreSQL calendar bounds 0001-01-01 and 9999-12-31 as cutoff dates', async () => {
const earliest = Date.parse('0001-01-01T00:00:00.000Z');
const latest = Date.parse('9999-12-31T23:59:59.999Z');
for (const [ts, expected] of [
[earliest, '0001-01-01'],
[latest, '9999-12-31'],
[Date.UTC(1969, 11, 31, 23, 59, 59, 999), '1969-12-31'],
] as const) {
const fake = createFakeExecutor([]);
const port = createPostgresTrialRefLookupPort({ executor: fake.executor, vaultCutoffTs: ts });
await port.hasResearchVisibleTrial('5');
expect(fake.calls[0]!.params).toEqual(['5', expected]);
}
let caught: unknown;
try {
createPostgresTrialRefLookupPort({
executor: createFakeExecutor().executor,
vaultCutoffTs: latest + 1,
});
} catch (err) {
caught = err;
}
expect((caught as PostgresTrialRefError).code).toBe('INVALID_VAULT_CUTOFF');
});
test('freezes the cutoff date and SQL text at construction across repeated lookups', async () => {
const fake = createFakeExecutor([]);
const options = { executor: fake.executor, vaultCutoffTs: CUTOFF_MIDNIGHT_TS };
const port = createPostgresTrialRefLookupPort(options);
await port.hasResearchVisibleTrial('1');
(options as { vaultCutoffTs: number }).vaultCutoffTs = Date.UTC(2030, 0, 1);
await port.hasResearchVisibleTrial('2');
expect(fake.calls).toHaveLength(2);
expect(fake.calls[0]!.text).toBe(fake.calls[1]!.text);
expect(fake.calls[1]!.params).toEqual(['2', '2025-06-30']);
});
test('returns true for multiple matching rows and rejects (not false) on a malformed executor response', async () => {
const many = createFakeExecutor([{ visible: 1 }, { visible: 1 }]);
const manyPort = createPostgresTrialRefLookupPort({
executor: many.executor,
vaultCutoffTs: CUTOFF_MIDNIGHT_TS,
});
expect(await manyPort.hasResearchVisibleTrial('3')).toBe(true);
for (const response of [null, {}, { rows: 'x' }, { rows: null }]) {
const executor: TrialRefExecutor = {
async query() {
return response as unknown as { readonly rows: readonly never[] };
},
};
const port = createPostgresTrialRefLookupPort({ executor, vaultCutoffTs: CUTOFF_MIDNIGHT_TS });
await expect(port.hasResearchVisibleTrial('3')).rejects.toBeInstanceOf(TypeError);
}
});
test('propagates a synchronous executor throw as a rejection with the same error', async () => {
const failure = new Error('pool exhausted');
const executor = {
query() {
throw failure;
},
} as unknown as TrialRefExecutor;
const port = createPostgresTrialRefLookupPort({ executor, vaultCutoffTs: CUTOFF_MIDNIGHT_TS });
await expect(port.hasResearchVisibleTrial('42')).rejects.toBe(failure);
});
});