63 lines
2.3 KiB
TypeScript
63 lines
2.3 KiB
TypeScript
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
|
|
);
|
|
}
|
|
}
|
|
}
|
|
});
|