import type { EventEmitter } from 'node:events'; import type { CanonicalRunRequest, CanonicalRunResult, } from '@stock-bot/stock-config/canonical-research'; import type { HistoricalDatasetV2 } from '@stock-bot/types'; /** Capabilities required by the canonical durable runner. No provider loading or playback. */ export interface BacktestExecutionEngine extends Pick { runCanonical( request: CanonicalRunRequest, resolveDataset: (signal: AbortSignal) => Promise, controls?: { executionDeadlineAt?: number } ): Promise>; stopBacktest(): Promise; 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.';