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
|
|
@ -13,6 +13,9 @@ function fixture(failAt?: string) {
|
|||
const record = async (step: string) => {
|
||||
calls.push(step);
|
||||
const [service, operation] = step.split('.');
|
||||
if (!service || !operation) {
|
||||
throw new Error('Invalid lifecycle fixture step');
|
||||
}
|
||||
if (operation === 'shutdown') {
|
||||
resources.delete(service);
|
||||
} else {
|
||||
|
|
@ -28,10 +31,6 @@ function fixture(failAt?: string) {
|
|||
initialize: () => record('execution.initialize'),
|
||||
shutdown: () => record('execution.shutdown'),
|
||||
},
|
||||
storage: {
|
||||
initialize: () => record('storage.initialize'),
|
||||
shutdown: () => record('storage.shutdown'),
|
||||
},
|
||||
strategies: {
|
||||
restoreStrategies: () => record('strategies.restore'),
|
||||
shutdown: () => record('strategies.shutdown'),
|
||||
|
|
@ -48,23 +47,17 @@ describe('explicit mode lifecycle dependencies', () => {
|
|||
test('paper recovery completes before the feed starts; shutdown drains the feed before strategies and execution', async () => {
|
||||
const f = fixture();
|
||||
await f.mode.initializeMode({ mode: 'paper', startingCapital: 10000 });
|
||||
expect(f.calls).toEqual([
|
||||
'execution.initialize',
|
||||
'storage.initialize',
|
||||
'strategies.restore',
|
||||
'market.initialize',
|
||||
]);
|
||||
expect(f.calls).toEqual(['execution.initialize', 'strategies.restore', 'market.initialize']);
|
||||
await f.mode.shutdown();
|
||||
expect(f.calls.slice(4)).toEqual([
|
||||
expect(f.calls.slice(3)).toEqual([
|
||||
'market.shutdown',
|
||||
'strategies.shutdown',
|
||||
'execution.shutdown',
|
||||
'storage.shutdown',
|
||||
]);
|
||||
expect(() => f.mode.getTradingEngine()).toThrow('not initialized');
|
||||
expect(f.mode.getConfig()).toBeNull();
|
||||
await f.mode.shutdown();
|
||||
expect(f.calls).toHaveLength(8);
|
||||
expect(f.calls).toHaveLength(6);
|
||||
});
|
||||
|
||||
test('backtest mode replaces the current engine without restoring paper strategies', async () => {
|
||||
|
|
@ -75,51 +68,37 @@ describe('explicit mode lifecycle dependencies', () => {
|
|||
expect(f.mode.getTradingEngine()).not.toBe(prior);
|
||||
expect(f.calls).toEqual([
|
||||
'execution.initialize',
|
||||
'storage.initialize',
|
||||
'market.initialize',
|
||||
'market.shutdown',
|
||||
'strategies.shutdown',
|
||||
'execution.shutdown',
|
||||
'storage.shutdown',
|
||||
'execution.initialize',
|
||||
'storage.initialize',
|
||||
'market.initialize',
|
||||
]);
|
||||
await f.mode.shutdown();
|
||||
});
|
||||
|
||||
test.each(['market.shutdown', 'strategies.shutdown', 'execution.shutdown', 'storage.shutdown'])(
|
||||
test.each(['market.shutdown', 'strategies.shutdown', 'execution.shutdown'])(
|
||||
'%s failure still closes every other dependency and clears the mode engine',
|
||||
async failAt => {
|
||||
const f = fixture(failAt);
|
||||
await f.mode.initializeMode(config);
|
||||
await expect(f.mode.shutdown()).rejects.toBe(f.failure);
|
||||
expect(f.calls.slice(3)).toEqual([
|
||||
expect(f.calls.slice(2)).toEqual([
|
||||
'market.shutdown',
|
||||
'strategies.shutdown',
|
||||
'execution.shutdown',
|
||||
'storage.shutdown',
|
||||
]);
|
||||
expect(() => f.mode.getTradingEngine()).toThrow('not initialized');
|
||||
expect(f.mode.getConfig()).toBeNull();
|
||||
await f.mode.shutdown();
|
||||
expect(f.calls).toHaveLength(7);
|
||||
expect(f.calls).toHaveLength(5);
|
||||
}
|
||||
);
|
||||
|
||||
const paper = { mode: 'paper' as const, startingCapital: 10000 };
|
||||
const initialization = [
|
||||
'execution.initialize',
|
||||
'storage.initialize',
|
||||
'strategies.restore',
|
||||
'market.initialize',
|
||||
];
|
||||
const cleanup = [
|
||||
'market.shutdown',
|
||||
'strategies.shutdown',
|
||||
'execution.shutdown',
|
||||
'storage.shutdown',
|
||||
];
|
||||
const initialization = ['execution.initialize', 'strategies.restore', 'market.initialize'];
|
||||
const cleanup = ['market.shutdown', 'strategies.shutdown', 'execution.shutdown'];
|
||||
|
||||
test.each(initialization)(
|
||||
'partial acquisition in %s cleans up attempted stages and allows retry without a success event',
|
||||
|
|
@ -175,7 +154,7 @@ describe('explicit mode lifecycle dependencies', () => {
|
|||
const f = fixture();
|
||||
await f.mode.initializeMode(config);
|
||||
const prior = f.mode.getTradingEngine();
|
||||
f.failures.set('storage.initialize', f.failure);
|
||||
f.failures.set('strategies.restore', f.failure);
|
||||
await expect(f.mode.initializeMode(paper)).rejects.toBe(f.failure);
|
||||
expect(f.mode.getConfig()).toBeNull();
|
||||
expect(() => f.mode.getTradingEngine()).toThrow('not initialized');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue