refactor(backtest): isolate legacy persistence capabilities (CL33)
This commit is contained in:
parent
24487d35da
commit
ec582bd5e8
14 changed files with 413 additions and 311 deletions
|
|
@ -12,7 +12,7 @@ import {
|
|||
parseStrategyVersionPackage,
|
||||
validateStrategyParameters,
|
||||
} from '@stock-bot/stock-config/strategy';
|
||||
import { PostgresBacktestRunRepository } from '../../apps/stock/orchestrator/src/backtest/PostgresBacktestRunRepository';
|
||||
import { LegacyBacktestRunWriter } from '../../apps/stock/orchestrator/src/backtest/compatibility/LegacyBacktestRunWriter';
|
||||
import { BacktestService } from '../../apps/stock/web-api/src/services/backtest.service';
|
||||
|
||||
const definition = {
|
||||
|
|
@ -69,7 +69,7 @@ describe('catalog draft and execution contracts', () => {
|
|||
throw new Error('Unexpected write');
|
||||
}),
|
||||
};
|
||||
const repository = new PostgresBacktestRunRepository(database);
|
||||
const repository = new LegacyBacktestRunWriter(database);
|
||||
for (const marker of [
|
||||
{ strategy: 'catalog' },
|
||||
{ strategyVersionId: null },
|
||||
|
|
|
|||
63
test/integration/run-repository-capabilities.test.ts
Normal file
63
test/integration/run-repository-capabilities.test.ts
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
import { dirname, resolve } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { expect, mock, test } from 'bun:test';
|
||||
import { LegacyBacktestRunWriter } from '../../apps/stock/orchestrator/src/backtest/compatibility/LegacyBacktestRunWriter';
|
||||
import { PostgresBacktestRunRepository } from '../../apps/stock/orchestrator/src/backtest/PostgresBacktestRunRepository';
|
||||
import { UnavailableBacktestRunRepository } from '../../apps/stock/orchestrator/src/backtest/run-repository';
|
||||
import { runtimeImports } from '../../scripts/runtime-imports';
|
||||
|
||||
const legacyMethods = [
|
||||
'start',
|
||||
'loadDataset',
|
||||
'freezeDataset',
|
||||
'complete',
|
||||
'updateControl',
|
||||
] as const;
|
||||
|
||||
test('canonical concrete repositories cannot expose retired write capabilities', () => {
|
||||
const database = {
|
||||
transaction: mock(async () => {
|
||||
throw new Error('Unexpected database access');
|
||||
}),
|
||||
};
|
||||
const canonical = new PostgresBacktestRunRepository(database);
|
||||
const unavailable = new UnavailableBacktestRunRepository();
|
||||
const historical = new LegacyBacktestRunWriter(database);
|
||||
for (const method of legacyMethods) {
|
||||
expect(method in canonical).toBe(false);
|
||||
expect(method in unavailable).toBe(false);
|
||||
expect(typeof historical[method]).toBe('function');
|
||||
}
|
||||
// Compatibility does not copy or replace supported ownership/failure transitions.
|
||||
for (const method of [
|
||||
'startCanonical',
|
||||
'loadCanonicalDataset',
|
||||
'completeCanonical',
|
||||
'heartbeat',
|
||||
'updateProgress',
|
||||
'cancel',
|
||||
'fail',
|
||||
] as const) {
|
||||
expect(historical[method]).toBe(canonical[method]);
|
||||
}
|
||||
expect(database.transaction).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('production modules do not import or re-export the compatibility writer', () => {
|
||||
const root = fileURLToPath(new URL('../../', import.meta.url));
|
||||
const compatibility = resolve(
|
||||
root,
|
||||
'apps/stock/orchestrator/src/backtest/compatibility/LegacyBacktestRunWriter'
|
||||
);
|
||||
const files = new Bun.Glob('{apps,libs}/**/src/**/*.{ts,tsx}').scanSync({ cwd: root });
|
||||
for (const file of files) {
|
||||
const absolute = resolve(root, file);
|
||||
for (const specifier of runtimeImports(absolute)) {
|
||||
if (specifier.startsWith('.')) {
|
||||
expect(resolve(dirname(absolute), specifier).replace(/\.[cm]?[jt]sx?$/, '')).not.toBe(
|
||||
compatibility
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue