Share backtest request contracts and isolate stored result mapping
This commit is contained in:
parent
007e35c747
commit
420c47704e
21 changed files with 777 additions and 244 deletions
|
|
@ -26,6 +26,7 @@ import { BacktestHandler } from '../../apps/stock/orchestrator/src/handlers/back
|
|||
import { StorageService } from '../../apps/stock/orchestrator/src/services/StorageService';
|
||||
import type { OrchestratorServices } from '../../apps/stock/orchestrator/src/types';
|
||||
import { BacktestConfigSchema } from '../../apps/stock/orchestrator/src/types';
|
||||
import { createBacktestRoutes as createV1Routes } from '../../apps/stock/web-api/src/routes/backtest.routes';
|
||||
import { createBacktestV2Routes } from '../../apps/stock/web-api/src/routes/backtests-v2.routes';
|
||||
import { BacktestServiceV2 } from '../../apps/stock/web-api/src/services/backtest-v2.service';
|
||||
import { BacktestService } from '../../apps/stock/web-api/src/services/backtest.service';
|
||||
|
|
@ -176,6 +177,11 @@ describe('one backtest execution workflow', () => {
|
|||
{ ...config, symbols: ['FIXTURE'] },
|
||||
{ ...config, config: { dataPolicy: { adjustment: 'raw', timestamp: 'utc-instant' } } },
|
||||
{ ...config, config: { datasetHash: 'invalid' } },
|
||||
{ ...config, config: { commission: -0.01 } },
|
||||
{ ...config, config: { slippage: 0.11 } },
|
||||
{ ...config, config: { commission: '0.001' } },
|
||||
{ ...config, initialCapital: 0 },
|
||||
{ ...config, strategy: '' },
|
||||
]) {
|
||||
const response = await api.request('/api/v2/backtests', {
|
||||
method: 'POST',
|
||||
|
|
@ -212,6 +218,18 @@ describe('one backtest execution workflow', () => {
|
|||
'not found'
|
||||
);
|
||||
});
|
||||
|
||||
test('V1 reports shared request-validation failures as bad input without creating definitions or runs', async () => {
|
||||
const f = await fixture();
|
||||
const response = await createV1Routes(f.services).request('/api/backtests', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ ...config, config: { commission: -0.01 } }),
|
||||
});
|
||||
expect(response.status).toBe(400);
|
||||
expect((await f.postgres.query('SELECT * FROM backtests')).rows).toHaveLength(0);
|
||||
expect((await f.postgres.query('SELECT * FROM runs')).rows).toHaveLength(0);
|
||||
});
|
||||
test('REST and decorated jobs execute real data and commit the same canonical result', async () => {
|
||||
const f = await fixture();
|
||||
const response = await f.routes.request('/api/backtest/run', {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue