refactor(api): compose research services with narrow collaborators (CL28)

This commit is contained in:
Boki 2026-10-28 14:45:11 -04:00
parent 3a63b2039e
commit 24487d35da
28 changed files with 281 additions and 94 deletions

View file

@ -17,9 +17,8 @@ import {
import { readPaperHostIdentity } from '../../apps/stock/orchestrator/src/paper/paper-host-identity';
import { PaperDeploymentHost } from '../../apps/stock/orchestrator/src/paper/PaperDeploymentHost';
import { BacktestServiceV2 } from '../../apps/stock/web-api/src/services/backtest-v2.service';
import { ChronologicalValidationService } from '../../apps/stock/web-api/src/services/chronological-validation.service';
import { ExperimentsService } from '../../apps/stock/web-api/src/services/experiments.service';
import { PaperDeploymentsService } from '../../apps/stock/web-api/src/services/paper-deployments.service';
import { createResearchServices } from '../../apps/stock/web-api/src/services/research-services';
import { StrategyCatalogService } from '../../apps/stock/web-api/src/services/strategy-catalog.service';
import { retainResearchDataset } from '../../scripts/import-research-dataset';
import { packageBuiltinStrategies } from '../../scripts/package-builtin-strategies';
@ -72,11 +71,12 @@ async function fixture(max = 1, withPromotion = true, candidate = false) {
Object.defineProperty(postgres, 'connectionPool', { get: () => pool });
Object.defineProperty(postgres, 'query', { value: pool.query.bind(pool) });
const container = { postgres, logger },
researchServices = createResearchServices(container),
api = new BacktestServiceV2(container),
experiments = new ExperimentsService(container),
validations = new ChronologicalValidationService(container),
validations = researchServices.validations,
catalog = new StrategyCatalogService(container),
service = new PaperDeploymentsService(container);
service = researchServices.paperDeployments;
const pkg = (await packageBuiltinStrategies())[0];
if (!pkg) {
throw new Error('Missing builtin');
@ -495,14 +495,18 @@ describe.skipIf(!url)('human-reviewed paper deployment', () => {
}, 60000);
test('changed installed host and retained artifact cannot initialize or overwrite an account', async () => {
const f = await fixture(),
drifted = new PaperDeploymentsService(f.container, async () => ({
drifted = createResearchServices(f.container, {
paperIdentity: async () => ({
...(await readPaperHostIdentity()),
hostSha256: 'f'.repeat(64),
}),
}).paperDeployments;
const wrongNative = createResearchServices(f.container, {
paperIdentity: async () => ({
...(await readPaperHostIdentity()),
hostSha256: 'f'.repeat(64),
}));
const wrongNative = new PaperDeploymentsService(f.container, async () => ({
...(await readPaperHostIdentity()),
engineBinarySha256: 'f'.repeat(64),
}));
engineBinarySha256: 'f'.repeat(64),
}),
}).paperDeployments;
await expect(wrongNative.preview(f.promotion)).rejects.toThrow('same native');
const preview = await drifted.preview(f.promotion),
saved = await drifted.create(