Separate backtest execution settings from strategy parameters

This commit is contained in:
Boki 2026-10-22 00:19:19 -04:00
parent 420c47704e
commit e4925ecdfe
9 changed files with 283 additions and 48 deletions

View file

@ -2,8 +2,10 @@ import { describe, expect, test } from 'bun:test';
import {
BACKTEST_DEFAULTS,
BacktestConfigSchema,
BacktestExecutionSettingsSchema,
backtestRequestFromDefinition,
isBacktestRequestError,
normalizeBacktestStrategyConfig,
parseBacktestRequest,
} from '@stock-bot/stock-config/backtest';
import { parseBacktestRequest as runnerParser } from '../../apps/stock/orchestrator/src/backtest/BacktestRunner';
@ -31,6 +33,31 @@ const definition = {
};
describe('shared backtest request contract', () => {
test('execution-owned fields are classified from their schema, not a second filtering list', () => {
const settings = Object.fromEntries(
Object.keys(BacktestExecutionSettingsSchema.shape).map(key => [key, 'execution-only'])
);
const input = {
...settings,
fastPeriod: 3,
slowPeriod: 7,
featureWindow: 17,
useTypeScriptImplementation: false,
};
const before = structuredClone(input);
expect(normalizeBacktestStrategyConfig(input)).toEqual({
parameters: { fastPeriod: 3, slowPeriod: 7, featureWindow: 17 },
useTypeScriptImplementation: false,
});
expect(input).toEqual(before);
expect(normalizeBacktestStrategyConfig({ fastPreriod: 3 }).parameters).toEqual({
fastPreriod: 3,
});
expect(() =>
normalizeBacktestStrategyConfig({ useTypeScriptImplementation: 'false' })
).toThrow();
});
test('runner and legacy schema exports delegate to the same pure contract', () => {
expect(orchestratorSchema).toBe(BacktestConfigSchema);
expect(runnerParser).toBe(parseBacktestRequest);