refactor(orchestrator): narrow historical storage to reads (CL17)
This commit is contained in:
parent
03518c8ae4
commit
984dc1a9cc
17 changed files with 88 additions and 232 deletions
|
|
@ -94,7 +94,7 @@ describe('deterministic ingestion → storage → native backtest', () => {
|
|||
};
|
||||
},
|
||||
} as unknown as QuestDBClient;
|
||||
const storage = new StorageService({ logger }, null, null, questdb);
|
||||
const storage = new StorageService(logger, null, questdb);
|
||||
const bars = await storage.getHistoricalBars(identity.eodSearchCode, start, end, '1m');
|
||||
expect(bars[0]?.timestamp.toISOString()).toBe('2024-01-01T15:00:00.000Z');
|
||||
timestamp = '2024-01-01T10:00:00';
|
||||
|
|
@ -113,7 +113,7 @@ describe('deterministic ingestion → storage → native backtest', () => {
|
|||
await persistEodPrices(mongodb, listing, [fixture[0]!]);
|
||||
expect(documents[0]?.exchange).toBe('NASDAQ');
|
||||
expect((documents[0] as unknown as { providerExchange: string }).providerExchange).toBe('US');
|
||||
const storage = new StorageService({ logger }, mongodb, null, null);
|
||||
const storage = new StorageService(logger, mongodb, null);
|
||||
expect(
|
||||
(await storage.getHistoricalBars(listing.eodSearchCode, start, end, '1d'))[0]?.symbol
|
||||
).toBe('FIXTURE.US');
|
||||
|
|
@ -129,7 +129,7 @@ describe('deterministic ingestion → storage → native backtest', () => {
|
|||
await persistEodPrices(mongodb, other, [
|
||||
{ ...fixture[0]!, open: 200, high: 201, low: 199, close: 200 },
|
||||
]);
|
||||
const storage = new StorageService({ logger }, mongodb, null, null);
|
||||
const storage = new StorageService(logger, mongodb, null);
|
||||
expect(
|
||||
(await storage.getHistoricalBars(identity.eodSearchCode, start, end, '1d'))[0]?.close
|
||||
).toBe(fixture[0]!.close);
|
||||
|
|
@ -159,7 +159,7 @@ describe('deterministic ingestion → storage → native backtest', () => {
|
|||
{ ...fixture[1]!, open: 50, high: 55, low: 45, close: 50, adjusted_close: 49, volume: 2000 },
|
||||
];
|
||||
await persistEodPrices(mongodb, identity, prices);
|
||||
const storage = new StorageService({ logger }, mongodb, null, null);
|
||||
const storage = new StorageService(logger, mongodb, null);
|
||||
const raw = await storage.getHistoricalBars(identity.eodSearchCode, start, end, '1d');
|
||||
const adjusted = await storage.getHistoricalBars(identity.eodSearchCode, start, end, '1d', {
|
||||
adjustment: 'provider-adjusted',
|
||||
|
|
@ -181,7 +181,7 @@ describe('deterministic ingestion → storage → native backtest', () => {
|
|||
test('explicit source requests reach storage and cannot silently reuse another provider', async () => {
|
||||
const { mongodb } = memoryStore();
|
||||
await persistEodPrices(mongodb, identity, fixture);
|
||||
const storage = new StorageService({ logger }, mongodb, null, null);
|
||||
const storage = new StorageService(logger, mongodb, null);
|
||||
const providers: unknown[] = [];
|
||||
const selected = await loadDataset(
|
||||
{
|
||||
|
|
@ -205,7 +205,7 @@ describe('deterministic ingestion → storage → native backtest', () => {
|
|||
test('missing provider factors cannot silently turn adjusted requests into raw data', async () => {
|
||||
const { mongodb } = memoryStore();
|
||||
await persistEodPrices(mongodb, identity, [fixture[0]!]);
|
||||
const storage = new StorageService({ logger }, mongodb, null, null);
|
||||
const storage = new StorageService(logger, mongodb, null);
|
||||
await expect(
|
||||
storage.getHistoricalBars(identity.eodSearchCode, start, end, '1d', {
|
||||
adjustment: 'provider-adjusted',
|
||||
|
|
@ -223,7 +223,7 @@ describe('deterministic ingestion → storage → native backtest', () => {
|
|||
test('daily timestamps are UTC session labels with aligned, exclusive ranges', async () => {
|
||||
const { mongodb } = memoryStore();
|
||||
await persistEodPrices(mongodb, identity, fixture.slice(0, 3));
|
||||
const storage = new StorageService({ logger }, mongodb, null, null);
|
||||
const storage = new StorageService(logger, mongodb, null);
|
||||
const bars = await storage.getHistoricalBars(
|
||||
identity.eodSearchCode,
|
||||
start,
|
||||
|
|
@ -248,7 +248,7 @@ describe('deterministic ingestion → storage → native backtest', () => {
|
|||
test('dataset hashes survive JSON key reordering and reject tampering or mismatched requests', async () => {
|
||||
const { mongodb } = memoryStore();
|
||||
await persistEodPrices(mongodb, identity, fixture);
|
||||
const storage = new StorageService({ logger }, mongodb, null, null);
|
||||
const storage = new StorageService(logger, mongodb, null);
|
||||
const first = await loadDataset(storage, datasetConfig());
|
||||
const reordered = JSON.parse(JSON.stringify(first), (_key, value) =>
|
||||
value && !Array.isArray(value) && typeof value === 'object'
|
||||
|
|
@ -273,7 +273,7 @@ describe('deterministic ingestion → storage → native backtest', () => {
|
|||
expect(documents).toHaveLength(fixture.length);
|
||||
expect(documents.every(row => row.source === 'eod')).toBe(true);
|
||||
const services = { logger, mongodb };
|
||||
const storage = new StorageService(services, mongodb, null, null);
|
||||
const storage = new StorageService(services.logger, mongodb, null);
|
||||
const config = BacktestConfigSchema.parse({
|
||||
mode: 'backtest',
|
||||
name: 'Fixed replay',
|
||||
|
|
@ -304,7 +304,7 @@ describe('deterministic ingestion → storage → native backtest', () => {
|
|||
symbols: [identity.eodSearchCode, other.eodSearchCode],
|
||||
config: { fastPeriod: 3, slowPeriod: 7 },
|
||||
};
|
||||
const storage = new StorageService({ logger }, mongodb, null, null);
|
||||
const storage = new StorageService(logger, mongodb, null);
|
||||
const first = await loadDataset(storage, config);
|
||||
const second = await loadDataset(storage, config);
|
||||
for (const id of config.symbols) {
|
||||
|
|
@ -324,14 +324,14 @@ describe('deterministic ingestion → storage → native backtest', () => {
|
|||
});
|
||||
|
||||
test('missing storage never silently produces synthetic prices', async () => {
|
||||
const storage = new StorageService({ logger }, null, null, null);
|
||||
const storage = new StorageService(logger, null, null);
|
||||
await expect(storage.getHistoricalBars('FIXTURE.TEST', start, end, '1d')).rejects.toThrow(
|
||||
'explicit opt-in'
|
||||
);
|
||||
});
|
||||
|
||||
test('explicit synthetic fixtures use a stable seed', async () => {
|
||||
const storage = new StorageService({ logger }, null, null, null, {
|
||||
const storage = new StorageService(logger, null, null, {
|
||||
allowSyntheticData: true,
|
||||
syntheticSeed: 7,
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue