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
|
|
@ -14,7 +14,7 @@ import type { BacktestConfig } from '../types';
|
|||
import { BacktestMarket } from './BacktestMarket';
|
||||
import { BacktestPlayback, type PlaybackProgress } from './BacktestPlayback';
|
||||
import { BacktestReport } from './BacktestReport';
|
||||
import type { BacktestExecutionEngine } from './execution-engine';
|
||||
import type { LegacyBacktestExecutionEngine } from './execution-engine';
|
||||
import { closedTradesSchema } from './native-result';
|
||||
import { backtestStrategies } from './strategy-plan';
|
||||
import type { BacktestResult } from './typescript-result';
|
||||
|
|
@ -23,7 +23,7 @@ export type { BacktestResult } from './typescript-result';
|
|||
const speeds = { max: null, realtime: 1, '2x': 2, '5x': 5, '10x': 10 } as const;
|
||||
|
||||
/** Composes one run's playback, market projection and report. The runner owns durable lifecycle. */
|
||||
export class BacktestEngine extends EventEmitter implements BacktestExecutionEngine {
|
||||
export class BacktestEngine extends EventEmitter implements LegacyBacktestExecutionEngine {
|
||||
private playback?: BacktestPlayback;
|
||||
private active?: Promise<BacktestResult>;
|
||||
private completedReport?: BacktestReport;
|
||||
|
|
|
|||
|
|
@ -57,7 +57,6 @@ export class BacktestRunner extends EventEmitter {
|
|||
constructor(
|
||||
private readonly dependencies: {
|
||||
engine: BacktestExecutionEngine;
|
||||
engineName: Exclude<BacktestRunResult['engine'], 'legacy'>;
|
||||
repository: BacktestRunRepository;
|
||||
logger: Pick<Logger, 'error'>;
|
||||
heartbeatMs?: number;
|
||||
|
|
@ -222,9 +221,6 @@ export class BacktestRunner extends EventEmitter {
|
|||
};
|
||||
this.dependencies.engine.on('progress', onProgress);
|
||||
try {
|
||||
if (!this.dependencies.repository.startCanonical) {
|
||||
throw new Error('Canonical run repository is unavailable');
|
||||
}
|
||||
this.active = await this.dependencies.repository.startCanonical(config);
|
||||
if (
|
||||
this.active.executionDeadlineAt !== undefined &&
|
||||
|
|
@ -283,18 +279,13 @@ export class BacktestRunner extends EventEmitter {
|
|||
{
|
||||
const engine = this.dependencies.engine;
|
||||
const repository = this.dependencies.repository;
|
||||
const loadCanonicalDataset = repository.loadCanonicalDataset;
|
||||
if (!engine.runCanonical || !loadCanonicalDataset || !repository.completeCanonical) {
|
||||
throw new Error('Canonical execution capabilities are unavailable');
|
||||
}
|
||||
const claim = this.active;
|
||||
// Resolve retained data through the owning attempt. The adapter supplies its
|
||||
// abort signal; neither this callback nor the worker fetches fresh provider bars.
|
||||
const report = await engine.runCanonical(
|
||||
executionConfig,
|
||||
signal =>
|
||||
loadCanonicalDataset.call(
|
||||
repository,
|
||||
repository.loadCanonicalDataset(
|
||||
claim.runId,
|
||||
claim.attemptId,
|
||||
executionConfig.datasetHash,
|
||||
|
|
@ -324,12 +315,8 @@ export class BacktestRunner extends EventEmitter {
|
|||
if (this.leaseFailure) {
|
||||
throw this.leaseFailure;
|
||||
}
|
||||
const completeCanonical = this.dependencies.repository.completeCanonical;
|
||||
if (!completeCanonical) {
|
||||
throw new Error('Canonical result persistence is unavailable');
|
||||
}
|
||||
checkDeadline();
|
||||
await completeCanonical.call(this.dependencies.repository, result, this.active.attemptId);
|
||||
await this.dependencies.repository.completeCanonical(result, this.active.attemptId);
|
||||
// Observers cannot turn a committed success into a failed run.
|
||||
this.publish('complete', result);
|
||||
return result;
|
||||
|
|
@ -450,36 +437,21 @@ export class BacktestRunner extends EventEmitter {
|
|||
await this.dependencies.engine.shutdown();
|
||||
}
|
||||
}
|
||||
/** Compatibility control; the engine must accept it before SQL records a pause. */
|
||||
async pauseBacktest(runId?: string) {
|
||||
const active = this.requireActive(runId);
|
||||
await this.dependencies.engine.pauseBacktest();
|
||||
await this.dependencies.repository.updateControl(
|
||||
active.runId,
|
||||
{ status: 'paused' },
|
||||
active.attemptId
|
||||
);
|
||||
/** Retained control routes reject playback operations without mutating durable state. */
|
||||
async pauseBacktest(runId?: string): Promise<void> {
|
||||
this.requireActive(runId);
|
||||
throw new Error('Native backtests do not support pause');
|
||||
}
|
||||
async resumeBacktest(runId?: string) {
|
||||
const active = this.requireActive(runId);
|
||||
await this.dependencies.engine.resumeBacktest();
|
||||
await this.dependencies.repository.updateControl(
|
||||
active.runId,
|
||||
{ status: 'running' },
|
||||
active.attemptId
|
||||
);
|
||||
async resumeBacktest(runId?: string): Promise<void> {
|
||||
this.requireActive(runId);
|
||||
throw new Error('Native backtests do not support resume');
|
||||
}
|
||||
async setSpeedMultiplier(speed: number | null, runId?: string) {
|
||||
async setSpeedMultiplier(speed: number | null, runId?: string): Promise<void> {
|
||||
if (speed !== null && (!Number.isFinite(speed) || speed <= 0)) {
|
||||
throw new Error('Backtest speed must be positive or null');
|
||||
}
|
||||
const active = this.requireActive(runId);
|
||||
this.dependencies.engine.setSpeedMultiplier(speed);
|
||||
await this.dependencies.repository.updateControl(
|
||||
active.runId,
|
||||
{ speedMultiplier: speed },
|
||||
active.attemptId
|
||||
);
|
||||
this.requireActive(runId);
|
||||
throw new Error('Native backtests run at maximum speed');
|
||||
}
|
||||
/** Local worker projection; persisted run status remains authoritative after restart. */
|
||||
getStatus() {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import {
|
|||
} from '@stock-bot/stock-config/canonical-research';
|
||||
import type { HistoricalDatasetV2 } from '@stock-bot/types';
|
||||
import type { DatasetResolver } from '../data/historical-dataset';
|
||||
import type { StorageService } from '../services/StorageService';
|
||||
import type { BacktestConfig } from '../types';
|
||||
import {
|
||||
BacktestCancelledError,
|
||||
|
|
@ -33,7 +32,6 @@ export class RustBacktestAdapter extends EventEmitter implements BacktestExecuti
|
|||
constructor(
|
||||
private readonly dependencies: {
|
||||
logger: Pick<Logger, 'error'>;
|
||||
storage: Pick<StorageService, 'getHistoricalBars'>;
|
||||
},
|
||||
options: { timeoutMs?: number; workerUrl?: URL } = {}
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -9,21 +9,14 @@ 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. */
|
||||
/** Capabilities required by the canonical durable runner. No provider loading or playback. */
|
||||
export interface BacktestExecutionEngine extends Pick<EventEmitter, 'on' | 'off'> {
|
||||
runBacktest(
|
||||
config: BacktestConfig,
|
||||
dataset?: DatasetResolver
|
||||
): Promise<BacktestResult | NativeBacktestResult>;
|
||||
runCanonical?(
|
||||
runCanonical(
|
||||
request: CanonicalRunRequest,
|
||||
resolveDataset: (signal: AbortSignal) => Promise<HistoricalDatasetV2>,
|
||||
controls?: { executionDeadlineAt?: number }
|
||||
): Promise<Pick<CanonicalRunResult, 'financial' | 'analytics'>>;
|
||||
stopBacktest(): Promise<void>;
|
||||
pauseBacktest(): Promise<void>;
|
||||
resumeBacktest(): Promise<void>;
|
||||
setSpeedMultiplier(speed: number | null): void;
|
||||
getStatus(): {
|
||||
isRunning: boolean;
|
||||
isPaused: boolean;
|
||||
|
|
@ -33,6 +26,18 @@ export interface BacktestExecutionEngine extends Pick<EventEmitter, 'on' | 'off'
|
|||
shutdown(): Promise<void>;
|
||||
}
|
||||
|
||||
/** Retained algorithm/playback examples only; cannot satisfy the durable runner contract. */
|
||||
export interface LegacyBacktestExecutionEngine
|
||||
extends Pick<BacktestExecutionEngine, 'on' | 'off' | 'stopBacktest' | 'getStatus' | 'shutdown'> {
|
||||
runBacktest(
|
||||
config: BacktestConfig,
|
||||
dataset?: DatasetResolver
|
||||
): Promise<BacktestResult | NativeBacktestResult>;
|
||||
pauseBacktest(): Promise<void>;
|
||||
resumeBacktest(): Promise<void>;
|
||||
setSpeedMultiplier(speed: number | null): void;
|
||||
}
|
||||
|
||||
/** Cancellation has no result when a native worker is forcibly stopped. */
|
||||
export class BacktestCancelledError extends Error {
|
||||
constructor() {
|
||||
|
|
|
|||
|
|
@ -21,34 +21,21 @@ export interface CanonicalRunClaim extends RunIdentity {
|
|||
config: CanonicalRunRequest;
|
||||
}
|
||||
|
||||
/** Every execution write must prove ownership of an unexpired attempt. */
|
||||
/** Canonical execution only; every write proves ownership of an unexpired attempt.
|
||||
* Concrete compatibility methods for older saved runs are outside this contract. */
|
||||
export interface BacktestRunRepository {
|
||||
start(config: BacktestConfig): Promise<RunClaim>;
|
||||
/** Only already admitted canonical rows may be claimed; no implicit creation. */
|
||||
startCanonical?(request: CanonicalRunRequest): Promise<CanonicalRunClaim>;
|
||||
loadCanonicalDataset?(
|
||||
startCanonical(request: CanonicalRunRequest): Promise<CanonicalRunClaim>;
|
||||
loadCanonicalDataset(
|
||||
runId: string,
|
||||
attemptId: string,
|
||||
requestedHash: string,
|
||||
signal?: AbortSignal
|
||||
): Promise<HistoricalDatasetV2>;
|
||||
completeCanonical?(result: CanonicalRunResult, attemptId: string): Promise<void>;
|
||||
completeCanonical(result: CanonicalRunResult, attemptId: string): Promise<void>;
|
||||
load(runId: string): Promise<{ status: string; config: unknown } | null>;
|
||||
rejectPending(runId: string, error: string): Promise<void>;
|
||||
heartbeat(runId: string, attemptId: string): Promise<{ cancelRequested: boolean }>;
|
||||
loadDataset(
|
||||
runId: string,
|
||||
attemptId: string,
|
||||
requestedHash?: string,
|
||||
signal?: AbortSignal
|
||||
): Promise<HistoricalDataset | null>;
|
||||
freezeDataset(
|
||||
runId: string,
|
||||
attemptId: string,
|
||||
dataset: HistoricalDataset,
|
||||
signal?: AbortSignal
|
||||
): Promise<HistoricalDataset>;
|
||||
complete(result: BacktestRunResult, attemptId: string): Promise<void>;
|
||||
updateProgress(
|
||||
runId: string,
|
||||
progress: number,
|
||||
|
|
@ -57,11 +44,6 @@ export interface BacktestRunRepository {
|
|||
): Promise<void>;
|
||||
fail(runId: string, error: string, attemptId: string): Promise<void>;
|
||||
cancel(runId: string, attemptId: string): Promise<void>;
|
||||
updateControl(
|
||||
runId: string,
|
||||
update: { status?: 'running' | 'paused'; speedMultiplier?: number | null },
|
||||
attemptId: string
|
||||
): Promise<void>;
|
||||
}
|
||||
export class BacktestConflictError extends Error {}
|
||||
export class BacktestLeaseLostError extends BacktestConflictError {}
|
||||
|
|
@ -71,6 +53,16 @@ export class UnavailableBacktestRunRepository implements BacktestRunRepository {
|
|||
private unavailable(): never {
|
||||
throw new Error('Backtest execution requires a PostgreSQL run repository');
|
||||
}
|
||||
async startCanonical(_request: CanonicalRunRequest): Promise<CanonicalRunClaim> {
|
||||
return this.unavailable();
|
||||
}
|
||||
async loadCanonicalDataset(): Promise<HistoricalDatasetV2> {
|
||||
return this.unavailable();
|
||||
}
|
||||
async completeCanonical(_result: CanonicalRunResult, _attemptId: string): Promise<void> {
|
||||
this.unavailable();
|
||||
}
|
||||
/** Compatibility diagnostics for callers of the retired repository surface. */
|
||||
async start(_config: BacktestConfig): Promise<RunClaim> {
|
||||
return this.unavailable();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -152,10 +152,9 @@ export async function registerOrchestratorServices(
|
|||
() =>
|
||||
new BacktestRunner({
|
||||
engine: new RustBacktestAdapter(
|
||||
{ logger: services.logger, storage: storageService },
|
||||
{ logger: services.logger },
|
||||
{ timeoutMs: options.nativeExecutionTimeoutMs }
|
||||
),
|
||||
engineName: 'native',
|
||||
repository: services.postgres
|
||||
? new PostgresBacktestRunRepository(services.postgres)
|
||||
: new UnavailableBacktestRunRepository(),
|
||||
|
|
|
|||
|
|
@ -2706,7 +2706,7 @@
|
|||
"epic": "E11",
|
||||
"priority": "P1",
|
||||
"severity": "High",
|
||||
"status": "in_progress",
|
||||
"status": "done",
|
||||
"dependencies": [],
|
||||
"decision_dependencies": [],
|
||||
"task_file": "backlog/tasks/CL14.md",
|
||||
|
|
@ -2734,10 +2734,17 @@
|
|||
"completed_commit": null,
|
||||
"blocker": null,
|
||||
"release_gates": [],
|
||||
"integration_state": "not_started",
|
||||
"integration_state": "validated_pending_commit",
|
||||
"integration_base": "700ee09c",
|
||||
"completion_evidence": "orchestrator-engine-cleanup.md",
|
||||
"worktree": "/tmp/stock-bot-engine-cleanup-20261026/cl14"
|
||||
"worktree": "/tmp/stock-bot-engine-cleanup-20261026/cl14",
|
||||
"reviewed_by": "/root (independent of implement_cl14)",
|
||||
"review_notes": "Accepted required canonical interfaces and preserved retirement/control behavior. Root validation:91 focused tests,33 canonical/legacy durable PostgreSQL tests; types/contracts/build pass.",
|
||||
"validation": {
|
||||
"focused": "91 pass,6888 assertions across6 files",
|
||||
"postgres": "33 pass,181 assertions across canonical-durable-backtest and durable-backtest; disposable stock_bot_safety database/Redis15",
|
||||
"static": "Orchestrator build, application typecheck, negative contract fixtures and diff checks pass"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "CL15",
|
||||
|
|
@ -2775,10 +2782,10 @@
|
|||
],
|
||||
"assignment": "/root/implement_cl15",
|
||||
"branch": "cleanup/cl15-rust-scaffolding",
|
||||
"completed_commit": null,
|
||||
"completed_commit": "bc2b8a89",
|
||||
"blocker": null,
|
||||
"release_gates": [],
|
||||
"integration_state": "validated_pending_commit",
|
||||
"integration_state": "validated_committed",
|
||||
"integration_base": "700ee09c",
|
||||
"completion_evidence": "orchestrator-engine-cleanup.md",
|
||||
"worktree": "/tmp/stock-bot-engine-cleanup-20261026/cl15",
|
||||
|
|
@ -2789,7 +2796,8 @@
|
|||
"focused": "75 pass,6625 assertions; bindings/terminal-equity/market-data/architecture",
|
||||
"rust": "150 pass,4 ignored",
|
||||
"diff": "git diff --check passed"
|
||||
}
|
||||
},
|
||||
"implementation_commit": "bc2b8a89"
|
||||
},
|
||||
{
|
||||
"id": "CL16",
|
||||
|
|
|
|||
|
|
@ -30,3 +30,11 @@ Implementation records will be appended here as tasks pass review and validation
|
|||
Removed 24 unused adapter/alternate-architecture files; moved two uncompiled reporting prototypes byte-for-byte into `engine/reference/legacy-reporting/` with explicit limitations. `MIGRATION.md` records every removal/preservation and current boundaries. Only compiled-code change removes the unused adapter module; canonical finance, legacy algorithms and native exports are unchanged.
|
||||
|
||||
Implemented by `/root/implement_cl15`; independently reviewed/integrated by `/root`. Both preserved files were compared against baseline bytes. Root rebuilt the addon and ran `bun test scripts/test/native-bindings.test.ts test/integration/native-terminal-equity.test.ts test/integration/native-market-data.test.ts scripts/test/architecture.test.ts`: 75 passed. `cargo test -p engine --lib --offline`: 150 passed, 4 ignored. `git diff --check` passed. The sandbox initially prevented NAPI from spawning `/bin/sh`; the authorized rebuild succeeded. No performance claim or stored-artifact migration.
|
||||
|
||||
### CL14 — accepted
|
||||
|
||||
The durable runner now requires canonical engine/repository capabilities. Legacy playback uses an explicit separate interface; concrete compatibility methods and historical formats remain. Removed unused adapter storage and runner engineName. Existing pause/resume/speed routes keep their production rejection behavior without SQL control writes. Negative type fixtures reject missing canonical capabilities.
|
||||
|
||||
Implemented by `/root/implement_cl14`; independently reviewed/integrated by `/root`. Root rebuilt the orchestrator and passed application typecheck/contract tests. Focused runner/workflow/worker/pool/isolation/architecture suite: 91 passed, 6,888 assertions. Disposable PostgreSQL canonical and retained durable-run suites: 33 passed, 181 assertions. No SQL/native/economic policy changes. Worker tests required execution outside the sandbox; two transient worktree Bun dependency-reading failures passed on separate reruns and root integration. Legacy-only provider-spy assertions were removed with the unused injection, not replaced with fabricated coverage. Full combined repository gate follows CL16 integration.
|
||||
|
||||
CL15 implementation commit: `bc2b8a89`.
|
||||
|
|
|
|||
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 {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
"extends": "./tsconfig.check.json",
|
||||
"include": [
|
||||
"libs/core/services/test/contracts.type-test.ts",
|
||||
"test/contracts/strategy-runtime.type-test.ts"
|
||||
"test/contracts/strategy-runtime.type-test.ts",
|
||||
"test/contracts/canonical-runner.type-test.ts"
|
||||
]
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue