fix(api): reject retired backtest creation before writes (CL23)

This commit is contained in:
Boki 2026-10-28 13:48:41 -04:00
parent 3fc0a272d8
commit cd1aa61481
10 changed files with 297 additions and 48 deletions

View file

@ -30,7 +30,16 @@ export interface BacktestJob {
error?: string;
}
/** Compatibility facade: V1 uses the same definitions, runs, and result reader as V2. */
export class LegacyBacktestCreationRetiredError extends Error {
readonly code = 'legacy_backtest_creation_retired';
constructor() {
super(
'Legacy backtest creation is retired. Create a catalog template with POST /api/v2/backtests, then submit a run through its /runs endpoint.'
);
}
}
/** Historical V1 reads and cancellation use the same saved records as V2. */
export class BacktestService {
private readonly service: BacktestServiceV2;
constructor(container: IServiceContainer, request?: BacktestTransport) {
@ -39,15 +48,9 @@ export class BacktestService {
async createBacktest(request: BacktestRequest): Promise<BacktestJob> {
rejectCatalogVersionReferences(request);
const backtest = await this.service.createBacktest(
{
...request,
name: typeof request.config?.name === 'string' ? request.config.name : 'Backtest',
},
{ autoStart: false }
);
const run = await this.service.createRun({ backtestId: backtest.id, speedMultiplier: null });
return this.toJob(backtest, run);
// Reject before saving a template: no legacy definition can execute, and a
// failure after its commit would leave an orphan on every client retry.
throw new LegacyBacktestCreationRetiredError();
}
async getBacktest(id: string): Promise<BacktestJob | null> {
const backtest = await this.service.getBacktest(id);