feat(research): isolate candidates and add reviewed paper promotion

This commit is contained in:
Boki 2026-10-24 18:46:55 -04:00
parent 26b97265c6
commit 25b5cbf481
128 changed files with 13038 additions and 1388 deletions

View file

@ -1,7 +1,8 @@
import { asValue } from 'awilix';
import { afterEach, describe, expect, test } from 'bun:test';
import { afterEach, describe, expect, spyOn, test } from 'bun:test';
import { ServiceContainerBuilder } from '@stock-bot/di';
import { BacktestCancelledError } from '../../apps/stock/orchestrator/src/backtest/execution-engine';
import { RustBacktestAdapter } from '../../apps/stock/orchestrator/src/backtest/RustBacktestAdapter';
import { registerOrchestratorServices } from '../../apps/stock/orchestrator/src/container';
import type { OrchestratorServices } from '../../apps/stock/orchestrator/src/types';
import { canonicalAdmissionFixture } from '../fixtures/canonical-admission';
@ -38,14 +39,13 @@ async function fixture() {
container.register({ serviceContainer: asValue(services) });
await registerOrchestratorServices(container);
const runtime = services.custom!,
runner = runtime.BacktestRunner!,
engine = runtime.BacktestEngine!;
runner = runtime.BacktestRunner!;
cleanup.push(async () => {
await runner.shutdown();
await paper.runtime.shutdown();
await container.dispose();
});
return { paper, ...admitted, container, services, runtime, runner, engine };
return { paper, ...admitted, container, services, runtime, runner };
}
describe.skipIf(!process.env.PIPELINE_TEST_DATABASE_URL)(
'canonical research isolation from durable paper custody',
@ -95,25 +95,29 @@ describe.skipIf(!process.env.PIPELINE_TEST_DATABASE_URL)(
for (let index = 0; index < 2; index++) {
const run = await accept();
let stopped: Promise<void> | undefined;
f.runner.once('progress', () => {
const cancelOnProgress = () => {
f.runner.off('progress', cancelOnProgress);
stopped = f.runner.stopBacktest();
});
};
f.runner.on('progress', cancelOnProgress);
const cancelled = await f.runner.runQueued(run.id).catch(error => error);
await stopped;
expect(stopped).toBeDefined();
expect(cancelled).toBeInstanceOf(BacktestCancelledError);
await unchanged();
const failed = await accept(),
original = f.engine.runCanonical;
f.engine.runCanonical = async () => {
throw new Error('Injected canonical execution failure');
};
const failed = await accept();
// The pool deliberately keeps engines private; inject only at the adapter seam.
const failure = spyOn(RustBacktestAdapter.prototype, 'runCanonical').mockImplementationOnce(
async () => {
throw new Error('Injected canonical execution failure');
}
);
try {
await expect(f.runner.runQueued(failed.id)).rejects.toThrow(
'Injected canonical execution failure'
);
} finally {
f.engine.runCanonical = original;
failure.mockRestore();
}
await unchanged();
}