T-122: M1.3g — @stock-bot/research: Vault-fenced universe planner + adapter method (survivorship-free active listings on a date from curated bars_1d Parquet, US_EQ / CA_EQ / US_CA_EQ) with tests and local benchmark (no new dependencies)
This commit is contained in:
parent
91c7411ed9
commit
0df1ef92ac
2 changed files with 114 additions and 24 deletions
|
|
@ -2712,21 +2712,86 @@ describe('planUniverseQuery & createDuckDbMarketDataStore().universe()', () => {
|
|||
expect((caughtStore as MarketDataStoreValidationError).field).toBe('universeLookbackDays');
|
||||
}
|
||||
|
||||
// Safe-integer overflow and epoch-underflow guards for extreme lookbackDays.
|
||||
for (const hugeLookback of [Number.MAX_SAFE_INTEGER, 100_000_000_000]) {
|
||||
let caught: unknown;
|
||||
// Safe-integer overflow, epoch-underflow, and cutoff-impossible lookbacks must fail
|
||||
// upfront at both planUniverseQuery and createDuckDbMarketDataStore with zero executor calls.
|
||||
for (const impossibleLookback of [
|
||||
Number.MAX_SAFE_INTEGER,
|
||||
100_000_000_000,
|
||||
604_800_000, // 7 days accidentally passed in milliseconds
|
||||
100_100_000, // fits in safe ms (8.64864e15) but underflows supported date range
|
||||
740_129, // 1 day beyond 2026-05-27 -> 0000-01-01 at the 2026 fixture cutoff
|
||||
]) {
|
||||
let caughtPlan: unknown;
|
||||
try {
|
||||
planUniverseQuery(
|
||||
{ ref: 'US_EQ', date: '2025-01-15' },
|
||||
{ ...DEFAULT_CTX, universeLookbackDays: hugeLookback }
|
||||
{ ...DEFAULT_CTX, universeLookbackDays: impossibleLookback }
|
||||
);
|
||||
} catch (err) {
|
||||
caught = err;
|
||||
caughtPlan = err;
|
||||
}
|
||||
expect(caught).toBeInstanceOf(MarketDataStoreValidationError);
|
||||
expect((caught as MarketDataStoreValidationError).field).toBe('universeLookbackDays');
|
||||
expect(caughtPlan).toBeInstanceOf(MarketDataStoreValidationError);
|
||||
expect((caughtPlan as MarketDataStoreValidationError).field).toBe('universeLookbackDays');
|
||||
|
||||
let caughtStore: unknown;
|
||||
try {
|
||||
createDuckDbMarketDataStore({
|
||||
executor: fake.executor,
|
||||
curatedRoot: CURATED_ROOT,
|
||||
vaultCutoffTs: CUTOFF_MS,
|
||||
universeLookbackDays: impossibleLookback,
|
||||
});
|
||||
} catch (err) {
|
||||
caughtStore = err;
|
||||
}
|
||||
expect(caughtStore).toBeInstanceOf(MarketDataStoreValidationError);
|
||||
expect((caughtStore as MarketDataStoreValidationError).field).toBe('universeLookbackDays');
|
||||
}
|
||||
|
||||
// Crossing before year 0000 (while still inside JS Date epoch range) must reject
|
||||
// cleanly in both planUniverseQuery and store.universe with zero executor calls
|
||||
// rather than truncating an extended signed ISO year (`-000001-...`).
|
||||
let caughtYearZeroPlan: unknown;
|
||||
try {
|
||||
planUniverseQuery({ ref: 'US_EQ', date: '0000-01-05' }, DEFAULT_CTX);
|
||||
} catch (err) {
|
||||
caughtYearZeroPlan = err;
|
||||
}
|
||||
expect(caughtYearZeroPlan).toBeInstanceOf(MarketDataStoreValidationError);
|
||||
expect((caughtYearZeroPlan as MarketDataStoreValidationError).field).toBe(
|
||||
'universeLookbackDays'
|
||||
);
|
||||
|
||||
await expect(store.universe({ ref: 'US_EQ', date: '0000-01-05' })).rejects.toMatchObject({
|
||||
name: 'MarketDataStoreValidationError',
|
||||
field: 'universeLookbackDays',
|
||||
});
|
||||
|
||||
// Exact 0000-01-01 boundary succeeds with a valid YYYY-MM-DD lower bound.
|
||||
const exactYearZero = planUniverseQuery({ ref: 'US_EQ', date: '0000-01-08' }, DEFAULT_CTX);
|
||||
expect(exactYearZero.params[1]).toBe('0000-01-01');
|
||||
|
||||
// A lookback valid on the latest permitted date (2026-05-27 -> 0000-01-01) is accepted
|
||||
// at store creation, but still rejected on earlier query dates with zero executor calls.
|
||||
const boundaryStore = createDuckDbMarketDataStore({
|
||||
executor: fake.executor,
|
||||
curatedRoot: CURATED_ROOT,
|
||||
vaultCutoffTs: CUTOFF_MS,
|
||||
universeLookbackDays: 740_128,
|
||||
});
|
||||
const maxBoundaryPlan = planUniverseQuery(
|
||||
{ ref: 'US_EQ', date: MAX_ALLOWED_DATE },
|
||||
{ ...DEFAULT_CTX, universeLookbackDays: 740_128 }
|
||||
);
|
||||
expect(maxBoundaryPlan.params[1]).toBe('0000-01-01');
|
||||
|
||||
await expect(
|
||||
boundaryStore.universe({ ref: 'US_EQ', date: '2026-05-26' })
|
||||
).rejects.toMatchObject({
|
||||
name: 'MarketDataStoreValidationError',
|
||||
field: 'universeLookbackDays',
|
||||
});
|
||||
|
||||
expect(fake.calls).toHaveLength(0);
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue