feat(research): add durable walk-forward validation workflows

This commit is contained in:
Boki 2026-10-24 12:34:39 -04:00
parent abd1c5b83d
commit 3ed7b98f7c
45 changed files with 5188 additions and 199 deletions

View file

@ -19,12 +19,19 @@ import {
parseValidationSubmission,
} from '../services/validation-evidence';
import { parseChronologicalValidation } from '../services/validation-preview';
import {
parseWalkForwardFinalization,
parseWalkForwardInput,
parseWalkForwardSubmission,
} from '../services/walk-forward-input';
import { WalkForwardService } from '../services/walk-forward.service';
/** Mounted HTTP security owns read authorization; every mutation additionally requires credential proof. */
export function createExperimentRoutes(container: IServiceContainer) {
const app = new Hono();
const service = new ExperimentsService(container);
const validations = new ChronologicalValidationService(container);
const walkForwards = new WalkForwardService(container);
const logger = getLogger('experiments-api');
const credentials: MiddlewareHandler = async (c, next) => {
c.header('Cache-Control', 'no-store');
@ -50,6 +57,54 @@ export function createExperimentRoutes(container: IServiceContainer) {
throw new ExperimentError(400, 'Invalid JSON request');
}
};
app.post('/api/v2/experiments/walk-forward/preview', async c =>
c.json({ preview: await walkForwards.preview(parseWalkForwardInput(await body(c.req.raw))) })
);
app.post('/api/v2/experiments/walk-forward', async c => {
const input = parseWalkForwardSubmission(await body(c.req.raw));
const walkForward = await walkForwards.submit(
input,
experimentReceipt({
principal: getCredentialHttpPrincipal(c.req.raw) ?? '',
key: c.req.header('Idempotency-Key') ?? '',
})
);
c.header('Location', `/api/v2/experiments/walk-forward/${walkForward.id}`);
return c.json({ walkForward }, 202);
});
app.get('/api/v2/experiments/walk-forward', async c =>
c.json({ walkForwards: await walkForwards.list(c.req.query('backtestId')) })
);
app.get('/api/v2/experiments/walk-forward/:id', async c =>
c.json({ walkForward: await walkForwards.get(experimentId(c.req.param('id'))) })
);
app.post('/api/v2/experiments/walk-forward/:id/finalize', async c => {
const id = experimentId(c.req.param('id')),
input = parseWalkForwardFinalization(await body(c.req.raw));
return c.json(
await walkForwards.finalize(
id,
input,
experimentReceipt({
principal: getCredentialHttpPrincipal(c.req.raw) ?? '',
key: c.req.header('Idempotency-Key') ?? '',
})
),
202
);
});
app.post('/api/v2/experiments/walk-forward/:id/cancel', async c => {
const id = experimentId(c.req.param('id'));
if (
!z
.object({})
.strict()
.safeParse(await body(c.req.raw)).success
) {
throw new ExperimentError(400, 'Cancellation accepts an empty object only');
}
return c.json({ walkForward: await walkForwards.cancel(id) });
});
app.post('/api/v2/experiments/validation/preview', async c => {
const input = parseChronologicalValidation(await body(c.req.raw));
return c.json({ preview: await service.previewValidation(input) });