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

@ -2,7 +2,7 @@ import { Hono } from 'hono';
import type { IServiceContainer } from '@stock-bot/handlers';
import { getLogger } from '@stock-bot/logger';
import { isBacktestRequestError } from '@stock-bot/stock-config/backtest';
import { BacktestService } from '../services/backtest.service';
import { BacktestService, LegacyBacktestCreationRetiredError } from '../services/backtest.service';
const logger = getLogger('backtest-routes');
@ -10,7 +10,7 @@ export function createBacktestRoutes(container: IServiceContainer) {
const backtestRoutes = new Hono();
const backtestService = new BacktestService(container);
// Create a new backtest
// Retired creation remains an explicit diagnostic for old clients.
backtestRoutes.post('/api/backtests', async c => {
try {
const body = await c.req.json();
@ -32,10 +32,13 @@ export function createBacktestRoutes(container: IServiceContainer) {
return c.json(backtest, 201);
} catch (error) {
logger.error('Failed to create backtest', { error });
if (error instanceof LegacyBacktestCreationRetiredError) {
return c.json({ code: error.code, error: error.message }, 410);
}
if (isBacktestRequestError(error)) {
return c.json({ error: error.message }, 400);
}
logger.error('Failed to create backtest', { error });
return c.json({ error: 'Failed to create backtest' }, 500);
}
});

View file

@ -66,7 +66,7 @@ export function createBacktestV2Routes(container: IServiceContainer) {
if (body.autoStart !== undefined && typeof body.autoStart !== 'boolean') {
return c.json({ error: 'autoStart must be a boolean' }, 400);
}
// Omitted autoStart preserves legacy clients. New web clients explicitly save only.
// Saving requires explicit autoStart:false; run submission is a separate operation.
const { autoStart, ...definition } = body;
const backtest = await backtestService.createBacktest(definition, { autoStart });
return c.json(backtest, 201);