refactor(orchestrator): require canonical research contracts (CL14)
This commit is contained in:
parent
bc2b8a89da
commit
21666242f4
37 changed files with 151 additions and 319 deletions
36
test/contracts/canonical-runner.type-test.ts
Normal file
36
test/contracts/canonical-runner.type-test.ts
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import { BacktestRunner } from '../../apps/stock/orchestrator/src/backtest/BacktestRunner';
|
||||
import type {
|
||||
BacktestExecutionEngine,
|
||||
LegacyBacktestExecutionEngine,
|
||||
} from '../../apps/stock/orchestrator/src/backtest/execution-engine';
|
||||
import type { BacktestRunRepository } from '../../apps/stock/orchestrator/src/backtest/run-repository';
|
||||
import { RustBacktestAdapter } from '../../apps/stock/orchestrator/src/backtest/RustBacktestAdapter';
|
||||
|
||||
function canonicalDependencies(
|
||||
engine: BacktestExecutionEngine,
|
||||
legacy: LegacyBacktestExecutionEngine,
|
||||
repository: BacktestRunRepository,
|
||||
withoutReplay: Omit<BacktestExecutionEngine, 'runCanonical'>,
|
||||
withoutClaim: Omit<BacktestRunRepository, 'startCanonical'>,
|
||||
withoutDataset: Omit<BacktestRunRepository, 'loadCanonicalDataset'>,
|
||||
withoutCompletion: Omit<BacktestRunRepository, 'completeCanonical'>
|
||||
) {
|
||||
const logger = { error() {} };
|
||||
new BacktestRunner({ engine, repository, logger });
|
||||
// @ts-expect-error Canonical replay is mandatory; a legacy playback engine is insufficient.
|
||||
new BacktestRunner({ engine: legacy, repository, logger });
|
||||
// @ts-expect-error The current runner cannot be composed without canonical execution.
|
||||
new BacktestRunner({ engine: withoutReplay, repository, logger });
|
||||
// @ts-expect-error Canonical claim custody is mandatory.
|
||||
new BacktestRunner({ engine, repository: withoutClaim, logger });
|
||||
// @ts-expect-error Retained canonical dataset loading is mandatory.
|
||||
new BacktestRunner({ engine, repository: withoutDataset, logger });
|
||||
// @ts-expect-error Canonical completion persistence is mandatory.
|
||||
new BacktestRunner({ engine, repository: withoutCompletion, logger });
|
||||
// @ts-expect-error Current execution does not accept provider storage dependencies.
|
||||
new RustBacktestAdapter({ logger, storage: { getHistoricalBars: async () => [] } });
|
||||
// @ts-expect-error The canonical runner cannot select a competing engine by name.
|
||||
new BacktestRunner({ engine, repository, logger, engineName: 'typescript' });
|
||||
}
|
||||
|
||||
void canonicalDependencies;
|
||||
|
|
@ -145,7 +145,7 @@ class FixtureEngine extends EventEmitter {
|
|||
stopped = gate();
|
||||
mode: 'trades' | 'empty' | 'fail' = 'trades';
|
||||
private cancelled = false;
|
||||
private readonly engine = new RustBacktestAdapter({ logger, storage }, { timeoutMs: 15000 });
|
||||
private readonly engine = new RustBacktestAdapter({ logger }, { timeoutMs: 15000 });
|
||||
async runBacktest(): Promise<never> {
|
||||
throw new Error('Legacy execution is retired');
|
||||
}
|
||||
|
|
@ -325,16 +325,7 @@ export async function fixture(browser: Browser, native = false) {
|
|||
maxAttempts: 3,
|
||||
});
|
||||
const controlled = new FixtureEngine();
|
||||
const historicalDataReads: string[] = [];
|
||||
const runStorage: Pick<StorageService, 'getHistoricalBars'> = {
|
||||
async getHistoricalBars(...args) {
|
||||
historicalDataReads.push(args[0]);
|
||||
return storage.getHistoricalBars(...args);
|
||||
},
|
||||
};
|
||||
const engine = native
|
||||
? new RustBacktestAdapter({ logger, storage: runStorage }, { timeoutMs: 15000 })
|
||||
: controlled;
|
||||
const engine = native ? new RustBacktestAdapter({ logger }, { timeoutMs: 15000 }) : controlled;
|
||||
const canonicalFailures: string[] = [];
|
||||
if (engine instanceof RustBacktestAdapter) {
|
||||
const executeCanonical = engine.runCanonical.bind(engine);
|
||||
|
|
@ -348,7 +339,6 @@ export async function fixture(browser: Browser, native = false) {
|
|||
}
|
||||
const runner = new BacktestRunner({
|
||||
engine,
|
||||
engineName: 'native',
|
||||
repository: new PostgresBacktestRunRepository(postgres, 2000),
|
||||
logger,
|
||||
heartbeatMs: 50,
|
||||
|
|
@ -617,7 +607,6 @@ export async function fixture(browser: Browser, native = false) {
|
|||
login,
|
||||
close,
|
||||
unexpectedNetwork,
|
||||
historicalDataReads,
|
||||
storedSourceReads,
|
||||
setStoredEodBars: (collection: string, bars: StoredEodBar[]) => {
|
||||
storedEodBars.set(collection, structuredClone(bars));
|
||||
|
|
|
|||
|
|
@ -171,7 +171,6 @@ test('operator_provisions_bounded_agent_views_usage_and_revokes_without_corrupti
|
|||
await f.page.reload();
|
||||
await visible(f.page, /Disabled · Revision 2/);
|
||||
expect(await f.page.getByLabel('New research token', { exact: true }).count()).toBe(0);
|
||||
expect(f.historicalDataReads).toEqual([]);
|
||||
expect(f.unexpectedNetwork).toEqual([]);
|
||||
} finally {
|
||||
await f.close();
|
||||
|
|
@ -503,7 +502,6 @@ test('saved_experiment_comparison_preserves_cost_reference_native_summaries_and_
|
|||
referenceKey
|
||||
);
|
||||
expect(await durableCounts()).toEqual(before);
|
||||
expect(f.historicalDataReads).toEqual([]);
|
||||
expect(f.unexpectedNetwork).toEqual([]);
|
||||
} finally {
|
||||
await f.close();
|
||||
|
|
@ -668,7 +666,6 @@ test('cost_sensitivity_freezes_policy_runs_native_scenarios_and_reopens_existing
|
|||
.locator(`a[href="/backtests/${backtest.id}/run/${experiment.trials[2]!.runId}"]`)
|
||||
.click();
|
||||
await visible(f.page, 'Canonical research result');
|
||||
expect(f.historicalDataReads).toEqual([]);
|
||||
expect(f.unexpectedNetwork).toEqual([]);
|
||||
} finally {
|
||||
await f.close();
|
||||
|
|
@ -925,7 +922,6 @@ test('walk_forward_freezes_all_windows_runs_native_members_and_reopens_reset_rep
|
|||
);
|
||||
expect((await f.pool.query('SELECT * FROM runs')).rowCount).toBe(8);
|
||||
expect((await f.pool.query('SELECT * FROM analysis_artifacts')).rowCount).toBe(2);
|
||||
expect(f.historicalDataReads).toEqual([]);
|
||||
expect(f.unexpectedNetwork).toEqual([]);
|
||||
} finally {
|
||||
await f.close();
|
||||
|
|
@ -1053,7 +1049,6 @@ test('chronological_preflight_checks_explicit_windows_without_admitting_or_savin
|
|||
await visible(f.page, /No experiments yet/);
|
||||
expect(await preparedInputs.count()).toBe(0);
|
||||
expect(await evidence()).toEqual(before);
|
||||
expect(f.historicalDataReads).toEqual([]);
|
||||
expect(f.unexpectedNetwork).toEqual([]);
|
||||
} finally {
|
||||
await f.close();
|
||||
|
|
@ -1250,7 +1245,6 @@ test('durable_chronological_training_fixed_holdouts_report_and_reopen_browser',
|
|||
await visible(f.page, 'Saved chronological validations');
|
||||
await f.page.locator(`a[href="/experiments/validation/${admitted.id}"]`).click();
|
||||
await visible(f.page, 'Execution complete · report saved');
|
||||
expect(f.historicalDataReads).toEqual([]);
|
||||
expect(f.unexpectedNetwork).toEqual([]);
|
||||
} finally {
|
||||
await f.close();
|
||||
|
|
@ -1410,7 +1404,6 @@ test('failed_experiment_trial_retry_preserves_history_and_reopens_native_result_
|
|||
await visible(f.page, 'Canonical research result');
|
||||
const result = (await f.request(`/api/v2/runs/${runId}/results`)) as CanonicalRunResult;
|
||||
expect(result.request).toEqual(failed.request_snapshot);
|
||||
expect(f.historicalDataReads).toEqual([]);
|
||||
expect(f.unexpectedNetwork).toEqual([]);
|
||||
} finally {
|
||||
await f.close();
|
||||
|
|
@ -1593,7 +1586,6 @@ test('retained_experiment_preview_submit_compare_cancel_and_reopen_browser', asy
|
|||
expect(cancelled.trials.every(trial => trial.metrics === null)).toBe(true);
|
||||
expect((await f.pool.query('SELECT * FROM backtest_results')).rowCount).toBe(3);
|
||||
expect((await f.request(`/api/v2/experiments/${experiment.id}`)).experiment).toEqual(completed);
|
||||
expect(f.historicalDataReads).toEqual([]);
|
||||
expect(f.unexpectedNetwork).toEqual([]);
|
||||
} finally {
|
||||
await f.close();
|
||||
|
|
@ -1989,7 +1981,6 @@ test('browser_legacy_frozen_history_reopens_without_reactivating_retired_executi
|
|||
expect((await f.pool.query('SELECT * FROM runs')).rowCount).toBe(1);
|
||||
expect((await f.pool.query('SELECT * FROM backtest_dispatch')).rowCount).toBe(0);
|
||||
expect(await f.request(`/api/v2/runs/${runId}/results`)).toEqual(result);
|
||||
expect(f.historicalDataReads).toEqual([]);
|
||||
expect(f.unexpectedNetwork).toEqual([]);
|
||||
} finally {
|
||||
await f.close();
|
||||
|
|
@ -3003,7 +2994,6 @@ test('research_project_to_finding_browser_with_canonical_strategy_setup_run_and_
|
|||
.rows[0].original_run_id
|
||||
).toBe(run.id);
|
||||
expect((await f.pool.query('SELECT * FROM backtest_results')).rowCount).toBe(3);
|
||||
expect(f.historicalDataReads).toEqual([]);
|
||||
expect(f.storedSourceReads).toHaveLength(2);
|
||||
expect(f.unexpectedNetwork).toEqual([]);
|
||||
} finally {
|
||||
|
|
@ -3264,7 +3254,6 @@ test('isolated_candidate_publication_research_validation_and_reviewed_paper_hist
|
|||
(await f.request(`/api/v2/paper-deployments/${deployment.id}`)).preview.strategy.versionId
|
||||
).toBe(version.id);
|
||||
expect(f.unexpectedNetwork).toEqual([]);
|
||||
expect(f.historicalDataReads).toEqual([]);
|
||||
} finally {
|
||||
await f.close();
|
||||
}
|
||||
|
|
|
|||
3
test/fixtures/backtest-crash-owner.ts
vendored
3
test/fixtures/backtest-crash-owner.ts
vendored
|
|
@ -5,7 +5,6 @@ import { PostgreSQLClient } from '@stock-bot/postgres';
|
|||
import { BacktestRunner } from '../../apps/stock/orchestrator/src/backtest/BacktestRunner';
|
||||
import { PostgresBacktestRunRepository } from '../../apps/stock/orchestrator/src/backtest/PostgresBacktestRunRepository';
|
||||
import { RustBacktestAdapter } from '../../apps/stock/orchestrator/src/backtest/RustBacktestAdapter';
|
||||
import { StorageService } from '../../apps/stock/orchestrator/src/services/StorageService';
|
||||
|
||||
setLoggerConfig({ logLevel: 'fatal', logConsole: false });
|
||||
const url = process.env.PIPELINE_TEST_DATABASE_URL;
|
||||
|
|
@ -35,9 +34,7 @@ repository.loadCanonicalDataset = async () => {
|
|||
const runner = new BacktestRunner({
|
||||
engine: new RustBacktestAdapter({
|
||||
logger,
|
||||
storage: new StorageService({ logger }, null, null, null),
|
||||
}),
|
||||
engineName: 'native',
|
||||
repository,
|
||||
logger,
|
||||
heartbeatMs: 50,
|
||||
|
|
|
|||
20
test/fixtures/canonical-runner.ts
vendored
20
test/fixtures/canonical-runner.ts
vendored
|
|
@ -68,9 +68,6 @@ export function canonicalRunnerFixture() {
|
|||
let heartbeatFailure = false;
|
||||
let status = 'pending';
|
||||
const repo: BacktestRunRepository = {
|
||||
async start() {
|
||||
throw new Error('legacy claim must not run');
|
||||
},
|
||||
async startCanonical(input) {
|
||||
events.push('claim');
|
||||
status = 'running';
|
||||
|
|
@ -95,20 +92,11 @@ export function canonicalRunnerFixture() {
|
|||
}
|
||||
return { cancelRequested: false };
|
||||
},
|
||||
async loadDataset() {
|
||||
throw new Error('v1 data must not run');
|
||||
},
|
||||
async freezeDataset() {
|
||||
throw new Error('provider freeze must not run');
|
||||
},
|
||||
async loadCanonicalDataset(_id, _attempt, hash) {
|
||||
expect(hash).toBe(dataset.manifest.hash);
|
||||
events.push('dataset');
|
||||
return dataset;
|
||||
},
|
||||
async complete() {
|
||||
throw new Error('legacy completion must not run');
|
||||
},
|
||||
async completeCanonical(input) {
|
||||
events.push('complete');
|
||||
result = input;
|
||||
|
|
@ -125,12 +113,8 @@ export function canonicalRunnerFixture() {
|
|||
events.push('cancel');
|
||||
status = 'cancelled';
|
||||
},
|
||||
async updateControl() {},
|
||||
};
|
||||
const engine = Object.assign(new EventEmitter(), {
|
||||
async runBacktest(): Promise<never> {
|
||||
throw new Error('legacy simulator must not run');
|
||||
},
|
||||
async runCanonical(
|
||||
_input: typeof request,
|
||||
resolve: (signal: AbortSignal) => Promise<HistoricalDatasetV2>
|
||||
|
|
@ -146,9 +130,6 @@ export function canonicalRunnerFixture() {
|
|||
async stopBacktest() {
|
||||
events.push('stop');
|
||||
},
|
||||
async pauseBacktest() {},
|
||||
async resumeBacktest() {},
|
||||
setSpeedMultiplier() {},
|
||||
getStatus() {
|
||||
return { isRunning: false, isPaused: false, progress: 0, currentTime: 0 };
|
||||
},
|
||||
|
|
@ -157,7 +138,6 @@ export function canonicalRunnerFixture() {
|
|||
const runner = new BacktestRunner({
|
||||
engine,
|
||||
repository: repo,
|
||||
engineName: 'native',
|
||||
logger,
|
||||
heartbeatMs: 5,
|
||||
heartbeatTimeoutMs: 50,
|
||||
|
|
|
|||
6
test/fixtures/research-pool.ts
vendored
6
test/fixtures/research-pool.ts
vendored
|
|
@ -148,11 +148,6 @@ export async function researchPoolFixture(dataset?: HistoricalDatasetV2) {
|
|||
const engines = repositories.map((_repository, slot) => {
|
||||
const engine = new RustBacktestAdapter({
|
||||
logger,
|
||||
storage: {
|
||||
async getHistoricalBars(): Promise<never> {
|
||||
throw new Error('Retained trials must not read a provider');
|
||||
},
|
||||
},
|
||||
});
|
||||
if (options.beforeExecute) {
|
||||
const execute = engine.runCanonical.bind(engine);
|
||||
|
|
@ -168,7 +163,6 @@ export async function researchPoolFixture(dataset?: HistoricalDatasetV2) {
|
|||
new BacktestRunner({
|
||||
engine,
|
||||
repository: repositories[i]!,
|
||||
engineName: 'native',
|
||||
logger,
|
||||
heartbeatMs: options.heartbeatMs ?? 5000,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -82,15 +82,8 @@ describe('canonical production workflow and legacy retirement', () => {
|
|||
}
|
||||
);
|
||||
test('legacy adapter and worker envelopes refuse before mutable storage or child process access', async () => {
|
||||
let reads = 0;
|
||||
const engine = new RustBacktestAdapter({
|
||||
logger,
|
||||
storage: {
|
||||
async getHistoricalBars() {
|
||||
reads++;
|
||||
return [];
|
||||
},
|
||||
},
|
||||
});
|
||||
await expect(engine.runBacktest(legacy)).rejects.toThrow(LEGACY_EXECUTION_RETIRED);
|
||||
const request = { type: 'run', config: legacy, data: [] };
|
||||
|
|
@ -98,7 +91,6 @@ describe('canonical production workflow and legacy retirement', () => {
|
|||
await expect(
|
||||
new NativeBacktestWorker().execute(request as never, new AbortController().signal, () => {})
|
||||
).rejects.toThrow();
|
||||
expect(reads).toBe(0);
|
||||
expect(engine.getStatus().isRunning).toBe(false);
|
||||
await engine.shutdown();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import { describe, expect, test } from 'bun:test';
|
||||
import { BacktestCancelledError } from '../../apps/stock/orchestrator/src/backtest/execution-engine';
|
||||
import {
|
||||
BacktestCancelledError,
|
||||
type BacktestExecutionEngine,
|
||||
} from '../../apps/stock/orchestrator/src/backtest/execution-engine';
|
||||
import { BacktestLeaseLostError } from '../../apps/stock/orchestrator/src/backtest/run-repository';
|
||||
BacktestLeaseLostError,
|
||||
UnavailableBacktestRunRepository,
|
||||
} from '../../apps/stock/orchestrator/src/backtest/run-repository';
|
||||
import { deferred, canonicalRunnerFixture as setup } from '../fixtures/canonical-runner';
|
||||
|
||||
describe('canonical jobs share the durable runner lifecycle', () => {
|
||||
|
|
@ -47,31 +47,20 @@ describe('canonical jobs share the durable runner lifecycle', () => {
|
|||
expect(f.events).toEqual([]);
|
||||
await f.runner.shutdown();
|
||||
});
|
||||
test('a runner without canonical execution fails without preparation or legacy/provider fallback', async () => {
|
||||
test('unavailable canonical storage refuses before any execution or provider fallback', async () => {
|
||||
const f = setup();
|
||||
const engine: BacktestExecutionEngine = f.engine;
|
||||
delete engine.runCanonical;
|
||||
const fail = f.repo.fail.bind(f.repo);
|
||||
let savedFailure: string | undefined;
|
||||
f.repo.fail = async (runId, error, attemptId) => {
|
||||
savedFailure = error;
|
||||
await fail(runId, error, attemptId);
|
||||
};
|
||||
try {
|
||||
await expect(f.runner.runQueued(f.request.runId)).rejects.toThrow(
|
||||
'Canonical execution capabilities are unavailable'
|
||||
);
|
||||
expect(savedFailure).toBe('Canonical execution capabilities are unavailable');
|
||||
expect(f.events).toEqual(['claim', 'heartbeat', 'fail']);
|
||||
expect(f.result).toBeUndefined();
|
||||
expect(await f.runner.runQueued(f.request.runId)).toEqual({
|
||||
runId: f.request.runId,
|
||||
status: 'failed',
|
||||
});
|
||||
expect(f.events).toEqual(['claim', 'heartbeat', 'fail']);
|
||||
} finally {
|
||||
await f.runner.shutdown();
|
||||
}
|
||||
const unavailable = new UnavailableBacktestRunRepository();
|
||||
f.repo.startCanonical = unavailable.startCanonical.bind(unavailable);
|
||||
await expect(f.runner.runQueued(f.request.runId)).rejects.toThrow(
|
||||
'Backtest execution requires a PostgreSQL run repository'
|
||||
);
|
||||
expect(f.events).toEqual([]);
|
||||
expect(f.result).toBeUndefined();
|
||||
await expect(unavailable.loadCanonicalDataset()).rejects.toThrow('PostgreSQL run repository');
|
||||
await expect(unavailable.completeCanonical({} as never, 'attempt')).rejects.toThrow(
|
||||
'PostgreSQL run repository'
|
||||
);
|
||||
await f.runner.shutdown();
|
||||
});
|
||||
test('cancel waits for execution to finish before committing cancellation', async () => {
|
||||
const f = setup(),
|
||||
|
|
|
|||
|
|
@ -95,16 +95,9 @@ test('canonical adapter cancellation during retained dataset reads prevents a la
|
|||
const f = canonicalRunnerFixture(),
|
||||
entered = deferred<void>(),
|
||||
release = deferred<void>();
|
||||
let providerReads = 0,
|
||||
progress = 0;
|
||||
let progress = 0;
|
||||
const engine = new RustBacktestAdapter({
|
||||
logger: { error() {} },
|
||||
storage: {
|
||||
async getHistoricalBars() {
|
||||
providerReads++;
|
||||
return [];
|
||||
},
|
||||
},
|
||||
});
|
||||
engine.on('progress', () => progress++);
|
||||
const result = engine
|
||||
|
|
@ -119,7 +112,6 @@ test('canonical adapter cancellation during retained dataset reads prevents a la
|
|||
expect(await result).toBeInstanceOf(BacktestCancelledError);
|
||||
release.resolve();
|
||||
await Promise.resolve();
|
||||
expect(providerReads).toBe(0);
|
||||
expect(progress).toBe(0);
|
||||
expect(engine.getStatus().isRunning).toBe(false);
|
||||
await engine.shutdown();
|
||||
|
|
@ -130,11 +122,6 @@ test('canonical adapter timeout covers retained input loading and shutdown close
|
|||
const engine = new RustBacktestAdapter(
|
||||
{
|
||||
logger: { error() {} },
|
||||
storage: {
|
||||
async getHistoricalBars() {
|
||||
throw new Error('provider must not run');
|
||||
},
|
||||
},
|
||||
},
|
||||
{ timeoutMs: 20 }
|
||||
);
|
||||
|
|
|
|||
|
|
@ -341,9 +341,7 @@ describe('deterministic ingestion → storage → native backtest', () => {
|
|||
});
|
||||
|
||||
test('retired provider-at-execution entry refuses before storage or native strategy resolution', async () => {
|
||||
const { mongodb } = memoryStore();
|
||||
const storage = new StorageService({ logger }, mongodb, null, null);
|
||||
const engine = new RustBacktestAdapter({ logger, storage });
|
||||
const engine = new RustBacktestAdapter({ logger });
|
||||
const config = BacktestConfigSchema.parse({
|
||||
mode: 'backtest',
|
||||
symbols: ['FIXTURE.TEST'],
|
||||
|
|
|
|||
|
|
@ -181,7 +181,7 @@ describe('EOD intraday ingestion → research storage', () => {
|
|||
expect(validateDataset(JSON.parse(JSON.stringify(legacy))).manifest.hash).toBe(
|
||||
legacy.manifest.hash
|
||||
);
|
||||
const engine = new RustBacktestAdapter({ logger, storage });
|
||||
const engine = new RustBacktestAdapter({ logger });
|
||||
await expect(engine.runBacktest(config(), async () => legacy)).rejects.toThrow(
|
||||
'Legacy backtest execution is retired'
|
||||
);
|
||||
|
|
|
|||
|
|
@ -2,10 +2,7 @@ import { randomUUID } from 'node:crypto';
|
|||
import { afterEach, describe, expect, test } from 'bun:test';
|
||||
import { Hono } from 'hono';
|
||||
import { createBacktestRoutes } from '../../apps/stock/orchestrator/src/api/rest/backtest';
|
||||
import {
|
||||
BacktestCancelledError,
|
||||
type BacktestExecutionEngine,
|
||||
} from '../../apps/stock/orchestrator/src/backtest/execution-engine';
|
||||
import { BacktestCancelledError } from '../../apps/stock/orchestrator/src/backtest/execution-engine';
|
||||
import { ResearchBacktestPool } from '../../apps/stock/orchestrator/src/backtest/ResearchBacktestPool';
|
||||
import { canonicalRunnerFixture, deferred } from '../fixtures/canonical-runner';
|
||||
import { logger } from '../fixtures/execution';
|
||||
|
|
@ -300,25 +297,26 @@ describe('run-scoped controls and event streams', () => {
|
|||
f.slots[0]!.release.resolve();
|
||||
await work[0];
|
||||
});
|
||||
test('exactly one active run retains no-ID pause/resume/speed controls', async () => {
|
||||
test('one active run preserves explicit rejection of unsupported playback controls', async () => {
|
||||
const f = fixture(1),
|
||||
work = await started(f),
|
||||
controls: unknown[] = [],
|
||||
slot = f.slots[0]!;
|
||||
slot.engine.pauseBacktest = async () => {
|
||||
controls.push('pause');
|
||||
};
|
||||
slot.engine.resumeBacktest = async () => {
|
||||
controls.push('resume');
|
||||
};
|
||||
(slot.engine as BacktestExecutionEngine).setSpeedMultiplier = speed => {
|
||||
controls.push(speed);
|
||||
};
|
||||
for (const action of ['pause', 'resume']) {
|
||||
expect((await post(f.app, action)).status).toBe(200);
|
||||
for (const [action, message] of [
|
||||
['pause', 'Native backtests do not support pause'],
|
||||
['resume', 'Native backtests do not support resume'],
|
||||
['speed', 'Native backtests run at maximum speed'],
|
||||
] as const) {
|
||||
for (const runId of [undefined, slot.request.runId]) {
|
||||
const response = await post(f.app, action, {
|
||||
...(runId ? { runId } : {}),
|
||||
...(action === 'speed' ? { speed: null } : {}),
|
||||
});
|
||||
expect(response.status).toBe(500);
|
||||
expect(await response.json()).toMatchObject({ error: message });
|
||||
}
|
||||
}
|
||||
expect((await post(f.app, 'speed', { speed: null })).status).toBe(200);
|
||||
expect(controls).toEqual(['pause', 'resume', null]);
|
||||
expect(slot.runner.getStatus().isPaused).toBe(false);
|
||||
expect(slot.events).not.toContain('complete');
|
||||
slot.release.resolve();
|
||||
await work[0];
|
||||
});
|
||||
|
|
|
|||
|
|
@ -116,15 +116,9 @@ async function fixture() {
|
|||
app.route('/', createExperimentRoutes(container));
|
||||
const engine = new RustBacktestAdapter({
|
||||
logger,
|
||||
storage: {
|
||||
async getHistoricalBars() {
|
||||
throw new Error('Research must use the frozen dataset');
|
||||
},
|
||||
},
|
||||
});
|
||||
const runner = new BacktestRunner({
|
||||
engine,
|
||||
engineName: 'native',
|
||||
repository: new PostgresBacktestRunRepository(postgres),
|
||||
logger,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -158,16 +158,10 @@ async function fixture(options: { corruptDataset?: boolean; buildMismatch?: bool
|
|||
await pool.query('INSERT INTO backtest_dispatch(run_id) VALUES ($1)', [runId]);
|
||||
};
|
||||
const repository = new PostgresBacktestRunRepository(postgres, 5000);
|
||||
const storage = {
|
||||
async getHistoricalBars(): Promise<never> {
|
||||
throw new Error('Canonical replay must never fetch provider data');
|
||||
},
|
||||
};
|
||||
const engine = new RustBacktestAdapter({ logger, storage }, { timeoutMs: 10000 });
|
||||
const engine = new RustBacktestAdapter({ logger }, { timeoutMs: 10000 });
|
||||
const runner = new BacktestRunner({
|
||||
engine,
|
||||
repository,
|
||||
engineName: 'native',
|
||||
logger,
|
||||
heartbeatMs: 20,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -109,15 +109,9 @@ async function fixture(dataset = canonicalSmaFixture().dataset) {
|
|||
const execute = async (id: string) => {
|
||||
const engine = new RustBacktestAdapter({
|
||||
logger,
|
||||
storage: {
|
||||
async getHistoricalBars() {
|
||||
throw new Error('Canonical execution must never load provider data');
|
||||
},
|
||||
},
|
||||
});
|
||||
const runner = new BacktestRunner({
|
||||
engine,
|
||||
engineName: 'native',
|
||||
repository: new PostgresBacktestRunRepository(postgres),
|
||||
logger,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -173,13 +173,8 @@ async function fixture(poolMax = 1, withValidation = true) {
|
|||
const execute = async (id: string) => {
|
||||
const engine = new RustBacktestAdapter({
|
||||
logger,
|
||||
storage: {
|
||||
async getHistoricalBars() {
|
||||
throw new Error('No provider reads allowed');
|
||||
},
|
||||
},
|
||||
});
|
||||
const runner = new BacktestRunner({ engine, engineName: 'native', repository, logger });
|
||||
const runner = new BacktestRunner({ engine, repository, logger });
|
||||
try {
|
||||
await runner.runQueued(id);
|
||||
} finally {
|
||||
|
|
|
|||
|
|
@ -167,13 +167,8 @@ async function fixture(poolMax = 1, withCosts = true, capital = 10000) {
|
|||
const execute = async (id: string) => {
|
||||
const engine = new RustBacktestAdapter({
|
||||
logger,
|
||||
storage: {
|
||||
async getHistoricalBars() {
|
||||
throw new Error('No provider reads allowed');
|
||||
},
|
||||
},
|
||||
});
|
||||
const runner = new BacktestRunner({ engine, engineName: 'native', repository, logger });
|
||||
const runner = new BacktestRunner({ engine, repository, logger });
|
||||
try {
|
||||
await runner.runQueued(id);
|
||||
} finally {
|
||||
|
|
|
|||
|
|
@ -203,10 +203,9 @@ async function fixture(historical = false) {
|
|||
});
|
||||
},
|
||||
} as unknown as StorageService;
|
||||
const engine = new RustBacktestAdapter({ logger, storage }, { timeoutMs: 5_000 });
|
||||
const engine = new RustBacktestAdapter({ logger }, { timeoutMs: 5_000 });
|
||||
const runner = new BacktestRunner({
|
||||
engine,
|
||||
engineName: 'native',
|
||||
repository,
|
||||
logger,
|
||||
heartbeatMs: 50,
|
||||
|
|
|
|||
|
|
@ -168,13 +168,8 @@ async function fixture(poolMax = 1, withCosts = true, capital = 10000) {
|
|||
const execute = async (id: string) => {
|
||||
const engine = new RustBacktestAdapter({
|
||||
logger,
|
||||
storage: {
|
||||
async getHistoricalBars() {
|
||||
throw new Error('No provider reads allowed');
|
||||
},
|
||||
},
|
||||
});
|
||||
const runner = new BacktestRunner({ engine, engineName: 'native', repository, logger });
|
||||
const runner = new BacktestRunner({ engine, repository, logger });
|
||||
try {
|
||||
await runner.runQueued(id);
|
||||
} finally {
|
||||
|
|
|
|||
|
|
@ -123,15 +123,9 @@ async function fixture(poolMax = 4, withRetries = true) {
|
|||
const execute = async (id: string) => {
|
||||
const engine = new RustBacktestAdapter({
|
||||
logger,
|
||||
storage: {
|
||||
async getHistoricalBars() {
|
||||
throw new Error('Canonical execution must never load provider data');
|
||||
},
|
||||
},
|
||||
});
|
||||
const runner = new BacktestRunner({
|
||||
engine,
|
||||
engineName: 'native',
|
||||
repository: new PostgresBacktestRunRepository(postgres),
|
||||
logger,
|
||||
});
|
||||
|
|
@ -191,11 +185,6 @@ async function failBeforeClaim(
|
|||
async function nativeResult(f: Fixture, request: CanonicalRunRequest): Promise<CanonicalRunResult> {
|
||||
const engine = new RustBacktestAdapter({
|
||||
logger,
|
||||
storage: {
|
||||
async getHistoricalBars() {
|
||||
throw new Error('Provider access forbidden');
|
||||
},
|
||||
},
|
||||
});
|
||||
try {
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -119,15 +119,9 @@ async function fixture(poolMax = 4, withExperiments = true) {
|
|||
const execute = async (id: string) => {
|
||||
const engine = new RustBacktestAdapter({
|
||||
logger,
|
||||
storage: {
|
||||
async getHistoricalBars() {
|
||||
throw new Error('Canonical execution must never load provider data');
|
||||
},
|
||||
},
|
||||
});
|
||||
const runner = new BacktestRunner({
|
||||
engine,
|
||||
engineName: 'native',
|
||||
repository: new PostgresBacktestRunRepository(postgres),
|
||||
logger,
|
||||
});
|
||||
|
|
@ -488,11 +482,6 @@ describe.skipIf(!url)('retained-input experiments', () => {
|
|||
await f.pool.query("UPDATE runs SET status='paused' WHERE id=$1", [requests[2]!.runId]);
|
||||
const engine = new RustBacktestAdapter({
|
||||
logger,
|
||||
storage: {
|
||||
async getHistoricalBars() {
|
||||
throw new Error('Provider access forbidden');
|
||||
},
|
||||
},
|
||||
});
|
||||
let computed;
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -105,15 +105,9 @@ async function fixture() {
|
|||
const execute = async (runId: string) => {
|
||||
const engine = new RustBacktestAdapter({
|
||||
logger,
|
||||
storage: {
|
||||
async getHistoricalBars() {
|
||||
throw new Error('Candidate must use retained data only');
|
||||
},
|
||||
},
|
||||
});
|
||||
const runner = new BacktestRunner({
|
||||
engine,
|
||||
engineName: 'native',
|
||||
repository: new PostgresBacktestRunRepository(postgres),
|
||||
logger,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -151,13 +151,8 @@ async function fixture(max = 1, withPromotion = true, candidate = false) {
|
|||
const execute = async (id: string) => {
|
||||
const engine = new RustBacktestAdapter({
|
||||
logger,
|
||||
storage: {
|
||||
async getHistoricalBars() {
|
||||
throw new Error('No provider allowed');
|
||||
},
|
||||
},
|
||||
});
|
||||
const runner = new BacktestRunner({ engine, engineName: 'native', repository, logger });
|
||||
const runner = new BacktestRunner({ engine, repository, logger });
|
||||
try {
|
||||
await runner.runQueued(id);
|
||||
} finally {
|
||||
|
|
|
|||
|
|
@ -126,15 +126,9 @@ async function fixture(poolMax = 4, withAgents = true, dataset = canonicalSmaFix
|
|||
const execute = async (id: string) => {
|
||||
const engine = new RustBacktestAdapter({
|
||||
logger,
|
||||
storage: {
|
||||
async getHistoricalBars() {
|
||||
throw new Error('Canonical execution must never load provider data');
|
||||
},
|
||||
},
|
||||
});
|
||||
const runner = new BacktestRunner({
|
||||
engine,
|
||||
engineName: 'native',
|
||||
repository: new PostgresBacktestRunRepository(postgres),
|
||||
logger,
|
||||
});
|
||||
|
|
@ -810,11 +804,6 @@ describe.skipIf(!url)('authoritative research principals and budgets', () => {
|
|||
request = await requestFor(f, id);
|
||||
const engine = new RustBacktestAdapter({
|
||||
logger,
|
||||
storage: {
|
||||
getHistoricalBars: async () => {
|
||||
throw new Error('Provider forbidden');
|
||||
},
|
||||
},
|
||||
});
|
||||
let economic: Pick<CanonicalRunResult, 'financial' | 'analytics'>;
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -150,13 +150,8 @@ async function fixture(poolMax = 1, withSources = true) {
|
|||
const execute = async (id: string) => {
|
||||
const engine = new RustBacktestAdapter({
|
||||
logger,
|
||||
storage: {
|
||||
async getHistoricalBars() {
|
||||
throw new Error('No provider reads allowed');
|
||||
},
|
||||
},
|
||||
});
|
||||
const runner = new BacktestRunner({ engine, engineName: 'native', repository, logger });
|
||||
const runner = new BacktestRunner({ engine, repository, logger });
|
||||
try {
|
||||
await runner.runQueued(id);
|
||||
} finally {
|
||||
|
|
|
|||
|
|
@ -155,13 +155,7 @@ async function fixture(applyWorkspace = true, maxConnections = 10) {
|
|||
const runner = new BacktestRunner({
|
||||
engine: new RustBacktestAdapter({
|
||||
logger,
|
||||
storage: {
|
||||
async getHistoricalBars() {
|
||||
throw new Error('No provider fallback');
|
||||
},
|
||||
},
|
||||
}),
|
||||
engineName: 'native',
|
||||
repository: new PostgresBacktestRunRepository(postgres),
|
||||
logger,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -116,15 +116,9 @@ async function fixture(poolMax = 4, withReproduction = true) {
|
|||
const execute = async (id: string) => {
|
||||
const engine = new RustBacktestAdapter({
|
||||
logger,
|
||||
storage: {
|
||||
async getHistoricalBars() {
|
||||
throw new Error('Canonical execution must never load provider data');
|
||||
},
|
||||
},
|
||||
});
|
||||
const runner = new BacktestRunner({
|
||||
engine,
|
||||
engineName: 'native',
|
||||
repository: new PostgresBacktestRunRepository(postgres),
|
||||
logger,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -163,13 +163,8 @@ async function fixture(poolMax = 1, withWalkForward = true) {
|
|||
const execute = async (id: string) => {
|
||||
const engine = new RustBacktestAdapter({
|
||||
logger,
|
||||
storage: {
|
||||
async getHistoricalBars() {
|
||||
throw new Error('No provider reads allowed');
|
||||
},
|
||||
},
|
||||
});
|
||||
const runner = new BacktestRunner({ engine, engineName: 'native', repository, logger });
|
||||
const runner = new BacktestRunner({ engine, repository, logger });
|
||||
try {
|
||||
await runner.runQueued(id);
|
||||
} finally {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue