T-145: tests

This commit is contained in:
Studio 2026-12-01 22:32:25 -05:00
parent dd8dc692af
commit 8f1bfbe9f1
2 changed files with 257 additions and 0 deletions

View file

@ -3220,3 +3220,60 @@ describe('planFundamentalsAsOfQuery & createDuckDbMarketDataStore().fundamentals
).rejects.toBeInstanceOf(MarketDataStoreValidationError);
});
});
describe('fundamentalsAsOf hostile request inputs', () => {
it('fails closed with zero executor calls for JSON-decoded object, symbol, and sparse field entries', async () => {
const fake = createRecordingExecutor();
const store = createDuckDbMarketDataStore({
executor: fake.executor,
curatedRoot: CURATED_ROOT,
vaultCutoffTs: CUTOFF_MS,
});
const hostileFields: unknown[] = [
JSON.parse('[{"toString": 1}]'),
[Object.create(null)],
[Symbol('revenue')],
// eslint-disable-next-line no-sparse-arrays
[, 'revenue'],
['REVENUE'],
[' revenue'],
];
for (const fields of hostileFields) {
await expect(
store.fundamentalsAsOf({ listingIds: [1], fields: fields as string[], asOf: '2025-06-15' })
).rejects.toThrow();
}
const hostileLag = JSON.parse('{"toString": 1}');
await expect(
store.fundamentalsAsOf({
listingIds: [1],
fields: ['revenue'],
asOf: '2025-06-15',
allowEstimatedLag: hostileLag as boolean,
})
).rejects.toThrow();
expect(fake.calls).toHaveLength(0);
expect(fake.runCalls).toHaveLength(0);
});
it('plans a request asOf with an offset that crosses the cutoff as a clamped bound', () => {
// 2026-05-28T01:00:00+02:00 === 2026-05-27T23:00:00Z, i.e. before the cutoff: not clamped.
const beforeCutoff = planFundamentalsAsOfQuery(
{ listingIds: [1], fields: ['revenue'], asOf: '2026-05-28T01:00:00+02:00' },
DEFAULT_CTX
);
expect(Date.parse(beforeCutoff.params[2] as string)).toBe(Date.UTC(2026, 4, 27, 23, 0, 0, 0));
expect(beforeCutoff.fenced.clampedAsOf).toBe(false);
// 2026-05-27T23:00:00-02:00 === 2026-05-28T01:00:00Z, i.e. after the cutoff: clamped.
const afterCutoff = planFundamentalsAsOfQuery(
{ listingIds: [1], fields: ['revenue'], asOf: '2026-05-27T23:00:00-02:00' },
DEFAULT_CTX
);
expect(afterCutoff.params[2]).toBe(MAX_ALLOWED_ISO_MICROS);
expect(afterCutoff.fenced.clampedAsOf).toBe(true);
});
});