T-158: tests
This commit is contained in:
parent
c6fcc341b9
commit
15f53dba9e
2 changed files with 180 additions and 25 deletions
|
|
@ -4,11 +4,11 @@ import { Client, Pool, type PoolConfig } from 'pg';
|
|||
import { getLogger, setLoggerConfig } from '@stock-bot/logger';
|
||||
import { PostgreSQLClient, runPostgresMigrations } from '@stock-bot/postgres';
|
||||
import {
|
||||
type SearchSymbolsResultPayload,
|
||||
type SymbolSearchExecutor,
|
||||
createMcpServer,
|
||||
createPostgresSymbolSearchPort,
|
||||
createSearchSymbolsTool,
|
||||
type SearchSymbolsResultPayload,
|
||||
type SymbolSearchExecutor,
|
||||
} from '../../libs/research/src/mcp/index';
|
||||
|
||||
setLoggerConfig({ logLevel: 'fatal', logConsole: false });
|
||||
|
|
@ -182,7 +182,9 @@ async function seedFixture(pool: Pool): Promise<void> {
|
|||
|
||||
describe('PostgreSQL symbol search safety guard', () => {
|
||||
test('rejects unsafe database targets before connecting', () => {
|
||||
expect(() => assertSafetyDatabaseUrl(undefined)).toThrow('Dedicated stock_bot_safety database required');
|
||||
expect(() => assertSafetyDatabaseUrl(undefined)).toThrow(
|
||||
'Dedicated stock_bot_safety database required'
|
||||
);
|
||||
expect(() =>
|
||||
assertSafetyDatabaseUrl('postgres://postgres:postgres@127.0.0.1:5432/trading_bot')
|
||||
).toThrow('Dedicated stock_bot_safety database required');
|
||||
|
|
@ -364,9 +366,7 @@ describe.skipIf(!url)('PostgreSQL MCP symbol search adapter', () => {
|
|||
includeDelisted: true,
|
||||
vaultCutoffTs: VAULT_CUTOFF_TS,
|
||||
});
|
||||
expect(caRows.map(r => ({ id: r.listingId, mic: r.mic }))).toEqual([
|
||||
{ id: 101, mic: 'XTSE' },
|
||||
]);
|
||||
expect(caRows.map(r => ({ id: r.listingId, mic: r.mic }))).toEqual([{ id: 101, mic: 'XTSE' }]);
|
||||
|
||||
// (e) Case-insensitive exact ISIN match with partial-ISIN negative
|
||||
const isinRows = await port.searchSymbols({
|
||||
|
|
@ -486,6 +486,85 @@ describe.skipIf(!url)('PostgreSQL MCP symbol search adapter', () => {
|
|||
expect(futureDelistPayload.rows[0]!.delistedAt).toBeNull();
|
||||
});
|
||||
|
||||
test('moves as-of resolution with the cutoff date, including a near-midnight UTC instant', async () => {
|
||||
const f = await createIsolatedFixture();
|
||||
const port = createPostgresSymbolSearchPort({ executor: createPgExecutor(f.pool) });
|
||||
const search = (query: string, vaultCutoffTs: number, includeDelisted = true) =>
|
||||
port.searchSymbols({ query, limit: 20, includeDelisted, vaultCutoffTs });
|
||||
const lastMsOfCutoffDay = Date.UTC(2024, 5, 30, 23, 59, 59, 999);
|
||||
const dayAfterCutoff = Date.UTC(2024, 6, 1, 0, 0, 0, 0);
|
||||
|
||||
// Last millisecond of 2024-06-30 UTC still resolves the pre-rename ticker.
|
||||
const lateOld = await search('OLDCO', lastMsOfCutoffDay);
|
||||
expect(lateOld.map(r => ({ id: r.listingId, ticker: r.ticker }))).toEqual([
|
||||
{ id: 101, ticker: 'ZOLD' },
|
||||
{ id: 113, ticker: 'OLDCO2' },
|
||||
{ id: 114, ticker: 'OLDCO' },
|
||||
]);
|
||||
expect(await search('NEWCO', lastMsOfCutoffDay)).toEqual([]);
|
||||
|
||||
// One day later the rename, the GAPNEW start and the IPO become visible, and OLDCO no longer resolves to 114.
|
||||
const nextOld = await search('OLDCO', dayAfterCutoff);
|
||||
expect(nextOld.map(r => r.listingId)).toEqual([101, 113]);
|
||||
const nextNew = await search('NEWCO', dayAfterCutoff);
|
||||
expect(nextNew.map(r => ({ id: r.listingId, ticker: r.ticker }))).toEqual([
|
||||
{ id: 114, ticker: 'NEWCO' },
|
||||
]);
|
||||
const nextGap = await search('GAPNEW', dayAfterCutoff);
|
||||
expect(nextGap.map(r => ({ id: r.listingId, ticker: r.ticker }))).toEqual([
|
||||
{ id: 102, ticker: 'GAPNEW' },
|
||||
]);
|
||||
expect(await search('GAPOLD', dayAfterCutoff)).toEqual([]);
|
||||
expect((await search('IPO25', dayAfterCutoff)).map(r => r.listingId)).toEqual([106]);
|
||||
|
||||
// A cutoff on the future delisting date makes that delisting confirmed and filterable.
|
||||
const onFutureDelist = await search('Delist Boundary', Date.UTC(2024, 8, 15), false);
|
||||
expect(onFutureDelist.map(r => r.listingId)).toEqual([109, 110]);
|
||||
});
|
||||
|
||||
test('projects identical calendar dates regardless of the session TimeZone', async () => {
|
||||
const f = await createIsolatedFixture();
|
||||
const client = await f.pool.connect();
|
||||
try {
|
||||
await client.query("SET TimeZone = 'Pacific/Kiritimati'");
|
||||
const executor: SymbolSearchExecutor = {
|
||||
query<Row = Record<string, unknown>>(text: string, params?: readonly unknown[]) {
|
||||
return client.query(
|
||||
text,
|
||||
params === undefined ? undefined : [...params]
|
||||
) as unknown as Promise<{
|
||||
readonly rows: readonly Row[];
|
||||
}>;
|
||||
},
|
||||
};
|
||||
const port = createPostgresSymbolSearchPort({ executor });
|
||||
|
||||
const rows = await port.searchSymbols({
|
||||
query: 'Delist Boundary',
|
||||
limit: 20,
|
||||
includeDelisted: true,
|
||||
vaultCutoffTs: VAULT_CUTOFF_TS,
|
||||
});
|
||||
|
||||
expect(
|
||||
rows.map(r => ({
|
||||
id: r.listingId,
|
||||
first: r.firstBarDate,
|
||||
last: r.lastBarDate,
|
||||
delistedAt: r.delistedAt,
|
||||
}))
|
||||
).toEqual([
|
||||
{ id: 108, first: '2015-01-01', last: '2024-06-30', delistedAt: '2024-06-30' },
|
||||
{ id: 109, first: '2015-01-01', last: '2024-06-28', delistedAt: null },
|
||||
{ id: 110, first: '2015-01-01', last: '2024-06-28', delistedAt: null },
|
||||
{ id: 111, first: '2015-01-01', last: '2024-09-15', delistedAt: '2024-09-15' },
|
||||
]);
|
||||
} finally {
|
||||
await client.query('RESET TimeZone');
|
||||
client.release();
|
||||
}
|
||||
});
|
||||
|
||||
test('isolates fixture schema even when the safety database URL includes startup options', async () => {
|
||||
const parsed = new URL(assertSafetyDatabaseUrl(url));
|
||||
parsed.searchParams.set('options', '-c statement_timeout=30000 -c search_path=public');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue