import type { EventEmitter } from 'node:events'; import type { CanonicalRunRequest, CanonicalRunResult, } from '@stock-bot/stock-config/canonical-research'; import type { HistoricalDatasetV2 } from '@stock-bot/types'; import type { DatasetResolver } from '../data/historical-dataset'; import type { BacktestConfig } from '../types'; import type { NativeBacktestResult } from './native-result'; import type { BacktestResult } from './typescript-result'; /** The runner depends on execution capabilities, not backend implementations. */ export interface BacktestExecutionEngine extends Pick { runBacktest( config: BacktestConfig, dataset?: DatasetResolver ): Promise; runCanonical?( request: CanonicalRunRequest, resolveDataset: (signal: AbortSignal) => Promise, controls?: { executionDeadlineAt?: number } ): Promise>; stopBacktest(): Promise; pauseBacktest(): Promise; resumeBacktest(): Promise; setSpeedMultiplier(speed: number | null): void; getStatus(): { isRunning: boolean; isPaused: boolean; progress: number; currentTime: number; }; shutdown(): Promise; } /** Cancellation has no result when a native worker is forcibly stopped. */ export class BacktestCancelledError extends Error { constructor() { super('Backtest cancelled'); this.name = 'BacktestCancelledError'; } } export class BacktestTimeoutError extends Error { constructor(timeoutMs: number) { super(`Native backtest exceeded its ${timeoutMs}ms execution deadline`); this.name = 'BacktestTimeoutError'; } } /** Old requests remain readable, but must be explicitly reconfigured for canonical admission. */ export const LEGACY_EXECUTION_RETIRED = 'Legacy backtest execution is retired. Select an approved strategy version and retained canonical dataset.';