refactor(api): compose research services with narrow collaborators (CL28)
This commit is contained in:
parent
3a63b2039e
commit
24487d35da
28 changed files with 281 additions and 94 deletions
|
|
@ -8,6 +8,7 @@ import { cors } from 'hono/cors';
|
||||||
import type { HttpSecurity } from '@stock-bot/di';
|
import type { HttpSecurity } from '@stock-bot/di';
|
||||||
import type { IServiceContainer } from '@stock-bot/handlers';
|
import type { IServiceContainer } from '@stock-bot/handlers';
|
||||||
import { createWebApiSecurity } from '../http-security';
|
import { createWebApiSecurity } from '../http-security';
|
||||||
|
import { createResearchServices } from '../services/research-services';
|
||||||
import { createBacktestRoutes } from './backtest.routes';
|
import { createBacktestRoutes } from './backtest.routes';
|
||||||
import { createBacktestV2Routes } from './backtests-v2.routes';
|
import { createBacktestV2Routes } from './backtests-v2.routes';
|
||||||
import { createDatasetRoutes } from './datasets.routes';
|
import { createDatasetRoutes } from './datasets.routes';
|
||||||
|
|
@ -44,6 +45,7 @@ export function createRoutes(
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
security.mount(app);
|
security.mount(app);
|
||||||
|
const researchServices = createResearchServices(container);
|
||||||
|
|
||||||
// Create routes with container
|
// Create routes with container
|
||||||
const healthRoutes = createHealthRoutes(container);
|
const healthRoutes = createHealthRoutes(container);
|
||||||
|
|
@ -63,13 +65,14 @@ export function createRoutes(
|
||||||
app.route('/', backtestRoutes); // Mounted at root since routes already have /api prefix
|
app.route('/', backtestRoutes); // Mounted at root since routes already have /api prefix
|
||||||
app.route('/', backtestV2Routes); // V2 routes also mounted at root
|
app.route('/', backtestV2Routes); // V2 routes also mounted at root
|
||||||
app.route('/', createDatasetRoutes(container));
|
app.route('/', createDatasetRoutes(container));
|
||||||
app.route('/', createStrategyRoutes(container));
|
app.route('/', createStrategyRoutes(container, researchServices.catalog));
|
||||||
app.route('/', createResearchRoutes(container));
|
app.route('/', createResearchRoutes(container, researchServices.research));
|
||||||
app.route('/', createResearchAgentRoutes(container, security.researchEnabled));
|
app.route('/', createResearchAgentRoutes(container, security.researchEnabled));
|
||||||
app.route('/', createExperimentRoutes(container));
|
app.route('/', createExperimentRoutes(container, researchServices));
|
||||||
app.route(
|
app.route(
|
||||||
'/',
|
'/',
|
||||||
createPaperDeploymentRoutes(container, {
|
createPaperDeploymentRoutes(container, {
|
||||||
|
service: researchServices.paperDeployments,
|
||||||
origin: integrations ? integrations.paperOrchestratorOrigin : process.env.ORCHESTRATOR_URL,
|
origin: integrations ? integrations.paperOrchestratorOrigin : process.env.ORCHESTRATOR_URL,
|
||||||
origins: security.allowedOrigins,
|
origins: security.allowedOrigins,
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ import { z } from 'zod';
|
||||||
import { getResearchHttpPrincipal } from '@stock-bot/di';
|
import { getResearchHttpPrincipal } from '@stock-bot/di';
|
||||||
import { getLogger } from '@stock-bot/logger';
|
import { getLogger } from '@stock-bot/logger';
|
||||||
import type { IServiceContainer } from '@stock-bot/services';
|
import type { IServiceContainer } from '@stock-bot/services';
|
||||||
import { ChronologicalValidationService } from '../services/chronological-validation.service';
|
|
||||||
import {
|
import {
|
||||||
parseCostSensitivityInput,
|
parseCostSensitivityInput,
|
||||||
parseCostSensitivitySubmission,
|
parseCostSensitivitySubmission,
|
||||||
|
|
@ -16,8 +15,8 @@ import {
|
||||||
parseExperimentSubmission,
|
parseExperimentSubmission,
|
||||||
} from '../services/experiment-input';
|
} from '../services/experiment-input';
|
||||||
import { parseExperimentRetry } from '../services/experiment-retry';
|
import { parseExperimentRetry } from '../services/experiment-retry';
|
||||||
import { ExperimentsService } from '../services/experiments.service';
|
|
||||||
import { researchAgentDatabaseError, ResearchAgentError } from '../services/research-agent-budget';
|
import { researchAgentDatabaseError, ResearchAgentError } from '../services/research-agent-budget';
|
||||||
|
import { createResearchServices, type ResearchServices } from '../services/research-services';
|
||||||
import {
|
import {
|
||||||
parseValidationFinalization,
|
parseValidationFinalization,
|
||||||
parseValidationSelection,
|
parseValidationSelection,
|
||||||
|
|
@ -29,14 +28,17 @@ import {
|
||||||
parseWalkForwardInput,
|
parseWalkForwardInput,
|
||||||
parseWalkForwardSubmission,
|
parseWalkForwardSubmission,
|
||||||
} from '../services/walk-forward-input';
|
} from '../services/walk-forward-input';
|
||||||
import { WalkForwardService } from '../services/walk-forward.service';
|
|
||||||
|
|
||||||
/** Mounted HTTP security owns read authorization; every mutation additionally requires credential proof. */
|
/** Mounted HTTP security owns read authorization; every mutation additionally requires credential proof. */
|
||||||
export function createExperimentRoutes(container: IServiceContainer) {
|
export function createExperimentRoutes(
|
||||||
|
container: IServiceContainer,
|
||||||
|
services: Pick<
|
||||||
|
ResearchServices,
|
||||||
|
'experiments' | 'validations' | 'walkForwards'
|
||||||
|
> = createResearchServices(container)
|
||||||
|
) {
|
||||||
const app = new Hono();
|
const app = new Hono();
|
||||||
const service = new ExperimentsService(container);
|
const { experiments: service, validations, walkForwards } = services;
|
||||||
const validations = new ChronologicalValidationService(container);
|
|
||||||
const walkForwards = new WalkForwardService(container);
|
|
||||||
const logger = getLogger('experiments-api');
|
const logger = getLogger('experiments-api');
|
||||||
const credentials: MiddlewareHandler = async (c, next) => {
|
const credentials: MiddlewareHandler = async (c, next) => {
|
||||||
c.header('Cache-Control', 'no-store');
|
c.header('Cache-Control', 'no-store');
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,9 @@ import {
|
||||||
paperAllowedOrigins,
|
paperAllowedOrigins,
|
||||||
requirePaperOperator,
|
requirePaperOperator,
|
||||||
} from '@stock-bot/trading-runtime/paper-operator';
|
} from '@stock-bot/trading-runtime/paper-operator';
|
||||||
import { PaperDeploymentsService } from '../services/paper-deployments.service';
|
import type { PaperDeploymentsService } from '../services/paper-deployments.service';
|
||||||
import { ResearchError } from '../services/research-errors';
|
import { ResearchError } from '../services/research-errors';
|
||||||
|
import { createResearchServices } from '../services/research-services';
|
||||||
|
|
||||||
/** Forwards the original human credential; never substitutes a service token. */
|
/** Forwards the original human credential; never substitutes a service token. */
|
||||||
export async function forwardPaperCommand(
|
export async function forwardPaperCommand(
|
||||||
|
|
@ -95,7 +96,7 @@ export function createPaperDeploymentRoutes(
|
||||||
} = {}
|
} = {}
|
||||||
) {
|
) {
|
||||||
const app = new Hono(),
|
const app = new Hono(),
|
||||||
service = options.service ?? new PaperDeploymentsService(container),
|
service = options.service ?? createResearchServices(container).paperDeployments,
|
||||||
origins = options.origins ?? paperAllowedOrigins();
|
origins = options.origins ?? paperAllowedOrigins();
|
||||||
app.use('*', async (c, next) => {
|
app.use('*', async (c, next) => {
|
||||||
c.header('Cache-Control', 'no-store');
|
c.header('Cache-Control', 'no-store');
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import type { IServiceContainer } from '@stock-bot/services';
|
||||||
import { archiveResearchSchema, parseResearchInput } from '@stock-bot/stock-config/research';
|
import { archiveResearchSchema, parseResearchInput } from '@stock-bot/stock-config/research';
|
||||||
import { researchAgentDatabaseError, ResearchAgentError } from '../services/research-agent-budget';
|
import { researchAgentDatabaseError, ResearchAgentError } from '../services/research-agent-budget';
|
||||||
import { ResearchError } from '../services/research-errors';
|
import { ResearchError } from '../services/research-errors';
|
||||||
import { ResearchService } from '../services/research.service';
|
import { createResearchServices } from '../services/research-services';
|
||||||
|
|
||||||
const emptyBody = z.object({}).strict();
|
const emptyBody = z.object({}).strict();
|
||||||
function includeArchived(value: string | undefined): boolean {
|
function includeArchived(value: string | undefined): boolean {
|
||||||
|
|
@ -25,9 +25,11 @@ async function noMutationBody(request: Request): Promise<void> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Research metadata only; the mounted security layer owns authenticated read access. */
|
/** Research metadata only; the mounted security layer owns authenticated read access. */
|
||||||
export function createResearchRoutes(container: IServiceContainer) {
|
export function createResearchRoutes(
|
||||||
|
container: IServiceContainer,
|
||||||
|
service = createResearchServices(container).research
|
||||||
|
) {
|
||||||
const app = new Hono();
|
const app = new Hono();
|
||||||
const service = new ResearchService(container);
|
|
||||||
const credentials: MiddlewareHandler = async (c, next) => {
|
const credentials: MiddlewareHandler = async (c, next) => {
|
||||||
c.header('Cache-Control', 'no-store');
|
c.header('Cache-Control', 'no-store');
|
||||||
if (!['GET', 'HEAD'].includes(c.req.method) && !getResearchHttpPrincipal(c.req.raw)) {
|
if (!['GET', 'HEAD'].includes(c.req.method) && !getResearchHttpPrincipal(c.req.raw)) {
|
||||||
|
|
|
||||||
|
|
@ -11,9 +11,11 @@ const publication = z
|
||||||
const parameters = z.object({ parameters: z.unknown() }).strict();
|
const parameters = z.object({ parameters: z.unknown() }).strict();
|
||||||
const submissionKey = z.string().regex(/^[\x21-\x7e]{1,200}$/);
|
const submissionKey = z.string().regex(/^[\x21-\x7e]{1,200}$/);
|
||||||
|
|
||||||
export function createStrategyRoutes(container: IServiceContainer) {
|
export function createStrategyRoutes(
|
||||||
|
container: IServiceContainer,
|
||||||
|
service = new StrategyCatalogService(container)
|
||||||
|
) {
|
||||||
const app = new Hono();
|
const app = new Hono();
|
||||||
const service = new StrategyCatalogService(container);
|
|
||||||
const credentials: MiddlewareHandler = async (c, next) => {
|
const credentials: MiddlewareHandler = async (c, next) => {
|
||||||
c.header('Cache-Control', 'no-store');
|
c.header('Cache-Control', 'no-store');
|
||||||
if (!['GET', 'HEAD'].includes(c.req.method) && !getResearchHttpPrincipal(c.req.raw)) {
|
if (!['GET', 'HEAD'].includes(c.req.method) && !getResearchHttpPrincipal(c.req.raw)) {
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ import type {
|
||||||
import type { ExperimentPreview } from '@stock-bot/stock-config/experiments';
|
import type { ExperimentPreview } from '@stock-bot/stock-config/experiments';
|
||||||
import type { ResearchActor } from '@stock-bot/types';
|
import type { ResearchActor } from '@stock-bot/types';
|
||||||
import { HistoricalDataRequestError } from '@stock-bot/types';
|
import { HistoricalDataRequestError } from '@stock-bot/types';
|
||||||
import { BacktestServiceV2 } from './backtest-v2.service';
|
import type { BacktestResults } from './backtests/results';
|
||||||
import { readCanonicalDataset } from './canonical-research.service';
|
import { readCanonicalDataset } from './canonical-research.service';
|
||||||
import {
|
import {
|
||||||
ExperimentError,
|
ExperimentError,
|
||||||
|
|
@ -28,7 +28,7 @@ import {
|
||||||
experimentReceipt,
|
experimentReceipt,
|
||||||
experimentTrialRequest,
|
experimentTrialRequest,
|
||||||
} from './experiment-input';
|
} from './experiment-input';
|
||||||
import { ExperimentsService } from './experiments.service';
|
import type { ExperimentsService } from './experiments.service';
|
||||||
import { lockExperimentResearchAgent, lockResearchAgent } from './research-agent-budget';
|
import { lockExperimentResearchAgent, lockResearchAgent } from './research-agent-budget';
|
||||||
import { RunReproductionError, verifyReproductionInputs } from './run-reproduction';
|
import { RunReproductionError, verifyReproductionInputs } from './run-reproduction';
|
||||||
import {
|
import {
|
||||||
|
|
@ -76,10 +76,16 @@ export class ChronologicalValidationService {
|
||||||
private readonly database;
|
private readonly database;
|
||||||
private readonly experiments;
|
private readonly experiments;
|
||||||
private readonly results;
|
private readonly results;
|
||||||
constructor(private readonly container: IServiceContainer) {
|
constructor(
|
||||||
|
private readonly container: IServiceContainer,
|
||||||
|
collaborators: {
|
||||||
|
experiments: Pick<ExperimentsService, 'lockedPreview' | 'readParameterDetail'>;
|
||||||
|
results: Pick<BacktestResults, 'getRunResults'>;
|
||||||
|
}
|
||||||
|
) {
|
||||||
this.database = requireServices(container, 'postgres').postgres;
|
this.database = requireServices(container, 'postgres').postgres;
|
||||||
this.experiments = new ExperimentsService(container);
|
this.experiments = collaborators.experiments;
|
||||||
this.results = new BacktestServiceV2(container);
|
this.results = collaborators.results;
|
||||||
}
|
}
|
||||||
async submit(raw: unknown, actor: Actor): Promise<ChronologicalValidationDetail> {
|
async submit(raw: unknown, actor: Actor): Promise<ChronologicalValidationDetail> {
|
||||||
const submission = parseValidationSubmission(raw),
|
const submission = parseValidationSubmission(raw),
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@ import {
|
||||||
type PaperPromotionPreview,
|
type PaperPromotionPreview,
|
||||||
} from '@stock-bot/stock-config/paper-deployments';
|
} from '@stock-bot/stock-config/paper-deployments';
|
||||||
import { assertStrategyJsonText, canonicalStrategyJson } from '@stock-bot/stock-config/strategy';
|
import { assertStrategyJsonText, canonicalStrategyJson } from '@stock-bot/stock-config/strategy';
|
||||||
import type { ResearchEvidenceReference } from '@stock-bot/types';
|
|
||||||
import { validatePaperConfiguration } from '@stock-bot/trading-runtime/paper-configuration';
|
import { validatePaperConfiguration } from '@stock-bot/trading-runtime/paper-configuration';
|
||||||
import {
|
import {
|
||||||
authorizedPaperPackage,
|
authorizedPaperPackage,
|
||||||
|
|
@ -24,7 +23,9 @@ import {
|
||||||
retainedPaperDeployment,
|
retainedPaperDeployment,
|
||||||
} from '@stock-bot/trading-runtime/paper-deployment-custody';
|
} from '@stock-bot/trading-runtime/paper-deployment-custody';
|
||||||
import { readPaperHostIdentity } from '@stock-bot/trading-runtime/paper-host-identity';
|
import { readPaperHostIdentity } from '@stock-bot/trading-runtime/paper-host-identity';
|
||||||
import { BacktestServiceV2, type BacktestResultQuery } from './backtest-v2.service';
|
import type { ResearchEvidenceReference } from '@stock-bot/types';
|
||||||
|
import type { BacktestResultQuery } from './backtests/contracts';
|
||||||
|
import type { BacktestResults } from './backtests/results';
|
||||||
import { retainedCostSensitivityPreview } from './cost-sensitivity-input';
|
import { retainedCostSensitivityPreview } from './cost-sensitivity-input';
|
||||||
import { canonicalReproductionHash } from './reproduction-comparison';
|
import { canonicalReproductionHash } from './reproduction-comparison';
|
||||||
import { verifyResearchSource } from './research-source-evidence';
|
import { verifyResearchSource } from './research-source-evidence';
|
||||||
|
|
@ -70,13 +71,12 @@ function evidence(result: CanonicalRunResult) {
|
||||||
|
|
||||||
export class PaperDeploymentsService {
|
export class PaperDeploymentsService {
|
||||||
private readonly database;
|
private readonly database;
|
||||||
private readonly results;
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly container: IServiceContainer,
|
private readonly container: IServiceContainer,
|
||||||
|
private readonly results: Pick<BacktestResults, 'getRunResults'>,
|
||||||
private readonly identity = readPaperHostIdentity
|
private readonly identity = readPaperHostIdentity
|
||||||
) {
|
) {
|
||||||
this.database = requireServices(container, 'postgres').postgres;
|
this.database = requireServices(container, 'postgres').postgres;
|
||||||
this.results = new BacktestServiceV2(container);
|
|
||||||
}
|
}
|
||||||
private async prepare(
|
private async prepare(
|
||||||
input: PaperPromotionInput,
|
input: PaperPromotionInput,
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,8 @@ import type {
|
||||||
ResearchEvidenceReference,
|
ResearchEvidenceReference,
|
||||||
ResearchFindingSource,
|
ResearchFindingSource,
|
||||||
} from '@stock-bot/types';
|
} from '@stock-bot/types';
|
||||||
import { BacktestServiceV2, type BacktestResultQuery } from './backtest-v2.service';
|
import type { BacktestResultQuery } from './backtests/contracts';
|
||||||
|
import type { BacktestResults } from './backtests/results';
|
||||||
import { ResearchError } from './research-errors';
|
import { ResearchError } from './research-errors';
|
||||||
import { verifyResearchSource } from './research-source-evidence';
|
import { verifyResearchSource } from './research-source-evidence';
|
||||||
|
|
||||||
|
|
@ -124,10 +125,11 @@ export function projectResearchEvidence(
|
||||||
|
|
||||||
export class ResearchEvidenceResolver {
|
export class ResearchEvidenceResolver {
|
||||||
private readonly database;
|
private readonly database;
|
||||||
private readonly results;
|
constructor(
|
||||||
constructor(container: IServiceContainer) {
|
container: IServiceContainer,
|
||||||
|
private readonly results: Pick<BacktestResults, 'getRunResults'>
|
||||||
|
) {
|
||||||
this.database = requireServices(container, 'postgres').postgres;
|
this.database = requireServices(container, 'postgres').postgres;
|
||||||
this.results = new BacktestServiceV2(container);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async resolveAll(
|
async resolveAll(
|
||||||
|
|
|
||||||
36
apps/stock/web-api/src/services/research-services.ts
Normal file
36
apps/stock/web-api/src/services/research-services.ts
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
import { requireServices, type IServiceContainer } from '@stock-bot/services';
|
||||||
|
import { BacktestResults } from './backtests/results';
|
||||||
|
import { ChronologicalValidationService } from './chronological-validation.service';
|
||||||
|
import { ExperimentsService } from './experiments.service';
|
||||||
|
import { PaperDeploymentsService } from './paper-deployments.service';
|
||||||
|
import { ResearchEvidenceResolver } from './research-evidence';
|
||||||
|
import { ResearchService } from './research.service';
|
||||||
|
import { StrategyCatalogService } from './strategy-catalog.service';
|
||||||
|
import { WalkForwardService } from './walk-forward.service';
|
||||||
|
|
||||||
|
/** Per-application composition only: constructors do no I/O and do not start workers or paper hosts. */
|
||||||
|
export function createResearchServices(
|
||||||
|
container: IServiceContainer,
|
||||||
|
options: { paperIdentity?: ConstructorParameters<typeof PaperDeploymentsService>[2] } = {}
|
||||||
|
) {
|
||||||
|
const results = new BacktestResults(requireServices(container, 'postgres'));
|
||||||
|
const experiments = new ExperimentsService(container);
|
||||||
|
const validations = new ChronologicalValidationService(container, { experiments, results });
|
||||||
|
const walkForwards = new WalkForwardService(container, { experiments, validations });
|
||||||
|
const catalog = new StrategyCatalogService(container);
|
||||||
|
const evidence = new ResearchEvidenceResolver(container, results);
|
||||||
|
const research = new ResearchService(container, { evidence, catalog });
|
||||||
|
const paperDeployments = new PaperDeploymentsService(container, results, options.paperIdentity);
|
||||||
|
return {
|
||||||
|
results,
|
||||||
|
experiments,
|
||||||
|
validations,
|
||||||
|
walkForwards,
|
||||||
|
catalog,
|
||||||
|
evidence,
|
||||||
|
research,
|
||||||
|
paperDeployments,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ResearchServices = ReturnType<typeof createResearchServices>;
|
||||||
|
|
@ -30,8 +30,8 @@ import type {
|
||||||
} from '@stock-bot/types';
|
} from '@stock-bot/types';
|
||||||
import { lockResearchAgent } from './research-agent-budget';
|
import { lockResearchAgent } from './research-agent-budget';
|
||||||
import { ResearchError } from './research-errors';
|
import { ResearchError } from './research-errors';
|
||||||
import { ResearchEvidenceResolver } from './research-evidence';
|
import type { ResearchEvidenceResolver } from './research-evidence';
|
||||||
import { StrategyCatalogService } from './strategy-catalog.service';
|
import type { StrategyCatalogService } from './strategy-catalog.service';
|
||||||
|
|
||||||
type Database = {
|
type Database = {
|
||||||
query<T extends QueryResultRow = QueryResultRow>(
|
query<T extends QueryResultRow = QueryResultRow>(
|
||||||
|
|
@ -134,10 +134,16 @@ export class ResearchService {
|
||||||
private readonly database;
|
private readonly database;
|
||||||
private readonly evidence;
|
private readonly evidence;
|
||||||
private readonly catalog;
|
private readonly catalog;
|
||||||
constructor(container: IServiceContainer) {
|
constructor(
|
||||||
|
container: IServiceContainer,
|
||||||
|
collaborators: {
|
||||||
|
evidence: Pick<ResearchEvidenceResolver, 'resolveAll'>;
|
||||||
|
catalog: Pick<StrategyCatalogService, 'getStrategy'>;
|
||||||
|
}
|
||||||
|
) {
|
||||||
this.database = requireServices(container, 'postgres').postgres;
|
this.database = requireServices(container, 'postgres').postgres;
|
||||||
this.evidence = new ResearchEvidenceResolver(container);
|
this.evidence = collaborators.evidence;
|
||||||
this.catalog = new StrategyCatalogService(container);
|
this.catalog = collaborators.catalog;
|
||||||
}
|
}
|
||||||
|
|
||||||
async listProjects(includeArchived = false): Promise<ResearchProject[]> {
|
async listProjects(includeArchived = false): Promise<ResearchProject[]> {
|
||||||
|
|
|
||||||
|
|
@ -11,14 +11,14 @@ import type {
|
||||||
WalkForwardSummary,
|
WalkForwardSummary,
|
||||||
} from '@stock-bot/stock-config/walk-forward';
|
} from '@stock-bot/stock-config/walk-forward';
|
||||||
import { readCanonicalDataset } from './canonical-research.service';
|
import { readCanonicalDataset } from './canonical-research.service';
|
||||||
import { ChronologicalValidationService } from './chronological-validation.service';
|
import type { ChronologicalValidationService } from './chronological-validation.service';
|
||||||
import {
|
import {
|
||||||
ExperimentError,
|
ExperimentError,
|
||||||
experimentHash,
|
experimentHash,
|
||||||
experimentId,
|
experimentId,
|
||||||
experimentReceipt,
|
experimentReceipt,
|
||||||
} from './experiment-input';
|
} from './experiment-input';
|
||||||
import { ExperimentsService } from './experiments.service';
|
import type { ExperimentsService } from './experiments.service';
|
||||||
import { lockResearchAgent } from './research-agent-budget';
|
import { lockResearchAgent } from './research-agent-budget';
|
||||||
import { validationEqual } from './validation-evidence';
|
import { validationEqual } from './validation-evidence';
|
||||||
import {
|
import {
|
||||||
|
|
@ -73,10 +73,19 @@ export class WalkForwardService {
|
||||||
private readonly database;
|
private readonly database;
|
||||||
private readonly experiments;
|
private readonly experiments;
|
||||||
private readonly validations;
|
private readonly validations;
|
||||||
constructor(container: IServiceContainer) {
|
constructor(
|
||||||
|
container: IServiceContainer,
|
||||||
|
collaborators: {
|
||||||
|
experiments: Pick<ExperimentsService, 'lockedPreview'>;
|
||||||
|
validations: Pick<
|
||||||
|
ChronologicalValidationService,
|
||||||
|
'admitPrepared' | 'verifiedSealedReport' | 'readDetail'
|
||||||
|
>;
|
||||||
|
}
|
||||||
|
) {
|
||||||
this.database = requireServices(container, 'postgres').postgres;
|
this.database = requireServices(container, 'postgres').postgres;
|
||||||
this.experiments = new ExperimentsService(container);
|
this.experiments = collaborators.experiments;
|
||||||
this.validations = new ChronologicalValidationService(container);
|
this.validations = collaborators.validations;
|
||||||
}
|
}
|
||||||
async preview(raw: unknown, principal = 'operator') {
|
async preview(raw: unknown, principal = 'operator') {
|
||||||
const input = parseWalkForwardInput(raw);
|
const input = parseWalkForwardInput(raw);
|
||||||
|
|
|
||||||
|
|
@ -29,3 +29,5 @@ Agents use root-reserved disjoint files in the integration worktree. Root alone
|
||||||
- **CL30:** Independent workspace/finding UI suites: 203 passed, 1306 assertions; agent full relevant UI set344 passed, 2143 assertions. Full source typecheck and scoped lint/format passed. Extracted feature-owned read/draft/write hooks; neutral styles and unsaved warning imports replace cross-feature dependencies; custody and uncertainty behavior preserved.
|
- **CL30:** Independent workspace/finding UI suites: 203 passed, 1306 assertions; agent full relevant UI set344 passed, 2143 assertions. Full source typecheck and scoped lint/format passed. Extracted feature-owned read/draft/write hooks; neutral styles and unsaved warning imports replace cross-feature dependencies; custody and uncertainty behavior preserved.
|
||||||
|
|
||||||
- **CL31:** Independent public-author/runtime suite:25 passed,363 assertions; standalone compilation uses no repository aliases or orchestrator/native implementation types. Source and packaged strategies produce identical native traces/checkpoints; contract compilation and scoped lint/format passed. Old contract path is a type-only compatibility export.
|
- **CL31:** Independent public-author/runtime suite:25 passed,363 assertions; standalone compilation uses no repository aliases or orchestrator/native implementation types. Source and packaged strategies produce identical native traces/checkpoints; contract compilation and scoped lint/format passed. Old contract path is a type-only compatibility export.
|
||||||
|
|
||||||
|
- **CL28:** One application composition graph with narrow collaborators and caller-owned transactions; independent review no blockers. Focused API45 passed547 assertions; root combined composition/capability5 passed1091 assertions. Disposable PG research/validation/walk-forward/paper/durable gates69 passed602 assertions plus catalog/durable-validation17 passed186 assertions. Scoped lint/format passed.
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
# Canonical development backlog
|
# Canonical development backlog
|
||||||
|
|
||||||
**Active: E13 architecture cleanup, CL22–CL35 (11/14 complete).** Owner authorized all October 28 audit recommendations and a commit per validated task. Earlier completion counts below are historical. [Execution record](../architecture-cleanup-execution.md).
|
**Active: E13 architecture cleanup, CL22–CL35 (12/14 complete).** Owner authorized all October 28 audit recommendations and a commit per validated task. Earlier completion counts below are historical. [Execution record](../architecture-cleanup-execution.md).
|
||||||
|
|
||||||
**Current scheduled backlog: 99/99 complete.** The owner resumed performance and authorized review of all seven conditions. P08 and O02 are implemented; five optional extensions remain deliberately deferred, and four merged IDs are redirects. This is not a claim that all 108 retained IDs were implemented. [Decisions, measurements and validation](../conditional-review.md).
|
**Current scheduled backlog: 99/99 complete.** The owner resumed performance and authorized review of all seven conditions. P08 and O02 are implemented; five optional extensions remain deliberately deferred, and four merged IDs are redirects. This is not a claim that all 108 retained IDs were implemented. [Decisions, measurements and validation](../conditional-review.md).
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3870,7 +3870,7 @@
|
||||||
"epic": "E13",
|
"epic": "E13",
|
||||||
"priority": "P2",
|
"priority": "P2",
|
||||||
"severity": "Medium",
|
"severity": "Medium",
|
||||||
"status": "ready",
|
"status": "done",
|
||||||
"dependencies": ["CL26"],
|
"dependencies": ["CL26"],
|
||||||
"decision_dependencies": [],
|
"decision_dependencies": [],
|
||||||
"task_file": "backlog/tasks/CL28.md",
|
"task_file": "backlog/tasks/CL28.md",
|
||||||
|
|
@ -3880,7 +3880,9 @@
|
||||||
"completed_commit": null,
|
"completed_commit": null,
|
||||||
"blocker": null,
|
"blocker": null,
|
||||||
"release_gates": [],
|
"release_gates": [],
|
||||||
"completion_evidence": "architecture-cleanup-execution.md"
|
"completion_evidence": "architecture-cleanup-execution.md",
|
||||||
|
"integration_state": "accepted",
|
||||||
|
"validation": "One application composition graph with narrow collaborators and caller-owned transactions; independent review no blockers. Focused API45 passed547 assertions; root combined composition/capability5 passed1091 assertions. Disposable PG research/validation/walk-forward/paper/durable gates69 passed602 assertions plus catalog/durable-validation17 passed186 assertions. Scoped lint/format passed."
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "CL29",
|
"id": "CL29",
|
||||||
|
|
@ -3888,7 +3890,7 @@
|
||||||
"epic": "E13",
|
"epic": "E13",
|
||||||
"priority": "P2",
|
"priority": "P2",
|
||||||
"severity": "Medium",
|
"severity": "Medium",
|
||||||
"status": "blocked",
|
"status": "ready",
|
||||||
"dependencies": ["CL28"],
|
"dependencies": ["CL28"],
|
||||||
"decision_dependencies": [],
|
"decision_dependencies": [],
|
||||||
"task_file": "backlog/tasks/CL29.md",
|
"task_file": "backlog/tasks/CL29.md",
|
||||||
|
|
@ -3896,7 +3898,7 @@
|
||||||
"assignment": null,
|
"assignment": null,
|
||||||
"write_locks": ["CL29"],
|
"write_locks": ["CL29"],
|
||||||
"completed_commit": null,
|
"completed_commit": null,
|
||||||
"blocker": "Implementation dependencies",
|
"blocker": null,
|
||||||
"release_gates": [],
|
"release_gates": [],
|
||||||
"completion_evidence": "architecture-cleanup-execution.md"
|
"completion_evidence": "architecture-cleanup-execution.md"
|
||||||
},
|
},
|
||||||
|
|
@ -3933,7 +3935,7 @@
|
||||||
"complexity": "M",
|
"complexity": "M",
|
||||||
"assignment": null,
|
"assignment": null,
|
||||||
"write_locks": ["CL31"],
|
"write_locks": ["CL31"],
|
||||||
"completed_commit": null,
|
"completed_commit": "3a63b2039e8f6b874d5cb1e1748c688a10f98c11",
|
||||||
"blocker": null,
|
"blocker": null,
|
||||||
"release_gates": [],
|
"release_gates": [],
|
||||||
"completion_evidence": "architecture-cleanup-execution.md",
|
"completion_evidence": "architecture-cleanup-execution.md",
|
||||||
|
|
@ -10403,7 +10405,7 @@
|
||||||
],
|
],
|
||||||
"work_policy": "Root integrates/commits reviewed tasks; agents own disjoint explicit files in the root integration worktree. Only root builds shared outputs and runs combined gates. No isolated native agent build claim.",
|
"work_policy": "Root integrates/commits reviewed tasks; agents own disjoint explicit files in the root integration worktree. Only root builds shared outputs and runs combined gates. No isolated native agent build claim.",
|
||||||
"first_wave": ["CL22", "CL23", "CL24"],
|
"first_wave": ["CL22", "CL23", "CL24"],
|
||||||
"completed": 11,
|
"completed": 12,
|
||||||
"last_verification": "Independent public-author/runtime suite:25 passed,363 assertions; standalone compilation uses no repository aliases or orchestrator/native implementation types. Source and packaged strategies produce identical native traces/checkpoints; contract compilation and scoped lint/format passed. Old contract path is a type-only compatibility export."
|
"last_verification": "One application composition graph with narrow collaborators and caller-owned transactions; independent review no blockers. Focused API45 passed547 assertions; root combined composition/capability5 passed1091 assertions. Disposable PG research/validation/walk-forward/paper/durable gates69 passed602 assertions plus catalog/durable-validation17 passed186 assertions. Scoped lint/format passed."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,3 +18,7 @@ Service/API and PostgreSQL research/validation tests. Focused review/tests prece
|
||||||
|
|
||||||
No new service/framework, financial simulator, real trading activation, external research execution, push/PR or .env changes. D04/P03/P05/P06/CL21 remain deferred. Root owns shared outputs, task state and commits; agents own disjoint files in the integration worktree.
|
No new service/framework, financial simulator, real trading activation, external research execution, push/PR or .env changes. D04/P03/P05/P06/CL21 remain deferred. Root owns shared outputs, task state and commits; agents own disjoint files in the integration worktree.
|
||||||
|
|
||||||
|
|
||||||
|
## Accepted verification
|
||||||
|
|
||||||
|
One application composition graph with narrow collaborators and caller-owned transactions; independent review no blockers. Focused API45 passed547 assertions; root combined composition/capability5 passed1091 assertions. Disposable PG research/validation/walk-forward/paper/durable gates69 passed602 assertions plus catalog/durable-validation17 passed186 assertions. Scoped lint/format passed.
|
||||||
|
|
|
||||||
|
|
@ -16,13 +16,13 @@ import { parseValidationDetail } from '../../apps/stock/config/src/contracts/res
|
||||||
import { parseChronologicalValidationPreview } from '../../apps/stock/config/src/contracts/research-responses/validation-preview';
|
import { parseChronologicalValidationPreview } from '../../apps/stock/config/src/contracts/research-responses/validation-preview';
|
||||||
import { parseWalkForwardDetail } from '../../apps/stock/config/src/contracts/research-responses/walk-forward';
|
import { parseWalkForwardDetail } from '../../apps/stock/config/src/contracts/research-responses/walk-forward';
|
||||||
import { canonicalRiskSessionClock } from '../../apps/stock/web-api/src/services/canonical-risk-clock';
|
import { canonicalRiskSessionClock } from '../../apps/stock/web-api/src/services/canonical-risk-clock';
|
||||||
import { ChronologicalValidationService } from '../../apps/stock/web-api/src/services/chronological-validation.service';
|
|
||||||
import {
|
import {
|
||||||
buildExperimentPreview,
|
buildExperimentPreview,
|
||||||
experimentHash,
|
experimentHash,
|
||||||
experimentTrialRequest,
|
experimentTrialRequest,
|
||||||
} from '../../apps/stock/web-api/src/services/experiment-input';
|
} from '../../apps/stock/web-api/src/services/experiment-input';
|
||||||
import { ExperimentsService } from '../../apps/stock/web-api/src/services/experiments.service';
|
import { ExperimentsService } from '../../apps/stock/web-api/src/services/experiments.service';
|
||||||
|
import { createResearchServices } from '../../apps/stock/web-api/src/services/research-services';
|
||||||
import {
|
import {
|
||||||
selectValidationWinner,
|
selectValidationWinner,
|
||||||
validationPhasePreview,
|
validationPhasePreview,
|
||||||
|
|
@ -181,7 +181,7 @@ async function pendingValidation(preview: ChronologicalValidationPreview, id = v
|
||||||
validation_selection: null,
|
validation_selection: null,
|
||||||
validation_report: null,
|
validation_report: null,
|
||||||
});
|
});
|
||||||
return new ChronologicalValidationService(stored.container).readDetail(stored.client, id);
|
return createResearchServices(stored.container).validations.readDetail(stored.client, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const [label, parameters] of [
|
for (const [label, parameters] of [
|
||||||
|
|
|
||||||
112
test/integration/research-service-composition.test.ts
Normal file
112
test/integration/research-service-composition.test.ts
Normal file
|
|
@ -0,0 +1,112 @@
|
||||||
|
import { randomUUID } from 'node:crypto';
|
||||||
|
import { expect, mock, test } from 'bun:test';
|
||||||
|
import { Hono } from 'hono';
|
||||||
|
import type { PoolClient } from 'pg';
|
||||||
|
import type { IServiceContainer } from '@stock-bot/services';
|
||||||
|
import { createExperimentRoutes } from '../../apps/stock/web-api/src/routes/experiments.routes';
|
||||||
|
import { createPaperDeploymentRoutes } from '../../apps/stock/web-api/src/routes/paper-deployments.routes';
|
||||||
|
import { createResearchRoutes } from '../../apps/stock/web-api/src/routes/research.routes';
|
||||||
|
import { createStrategyRoutes } from '../../apps/stock/web-api/src/routes/strategies.routes';
|
||||||
|
import { ResearchEvidenceResolver } from '../../apps/stock/web-api/src/services/research-evidence';
|
||||||
|
import { createResearchServices } from '../../apps/stock/web-api/src/services/research-services';
|
||||||
|
import { walkForwardDataset } from '../fixtures/walk-forward';
|
||||||
|
|
||||||
|
test('composing research services and reading lists needs no worker, paper host, or transaction', async () => {
|
||||||
|
const query = mock(async () => ({ rows: [] }));
|
||||||
|
const transaction = mock(async () => {
|
||||||
|
throw new Error('Read-only listing must not start a transaction');
|
||||||
|
});
|
||||||
|
const paperIdentity = mock(async () => {
|
||||||
|
throw new Error('Read-only listing must not load a paper host');
|
||||||
|
});
|
||||||
|
const container = { postgres: { query, transaction } } as unknown as IServiceContainer;
|
||||||
|
const services = createResearchServices(container, { paperIdentity });
|
||||||
|
expect(query).not.toHaveBeenCalled();
|
||||||
|
const app = new Hono()
|
||||||
|
.route('/', createResearchRoutes(container, services.research))
|
||||||
|
.route('/', createExperimentRoutes(container, services))
|
||||||
|
.route('/', createStrategyRoutes(container, services.catalog))
|
||||||
|
.route(
|
||||||
|
'/',
|
||||||
|
createPaperDeploymentRoutes(container, {
|
||||||
|
service: services.paperDeployments,
|
||||||
|
origins: ['http://fixture.test'],
|
||||||
|
})
|
||||||
|
);
|
||||||
|
for (const [path, key] of [
|
||||||
|
['research-projects', 'projects'],
|
||||||
|
['experiments', 'experiments'],
|
||||||
|
['strategies', 'strategies'],
|
||||||
|
['paper-deployments', 'deployments'],
|
||||||
|
] as const) {
|
||||||
|
const response = await app.request(`/api/v2/${path}`);
|
||||||
|
expect(response.status).toBe(200);
|
||||||
|
expect(await response.json()).toEqual({ [key]: [] });
|
||||||
|
}
|
||||||
|
expect(query).toHaveBeenCalledTimes(4);
|
||||||
|
expect(transaction).not.toHaveBeenCalled();
|
||||||
|
expect(paperIdentity).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('walk-forward and chronological validation share the injected experiment preview inside their caller transaction', async () => {
|
||||||
|
const client = { query: mock(async () => ({ rows: [] })) } as unknown as PoolClient;
|
||||||
|
const poolQuery = mock(async () => {
|
||||||
|
throw new Error('Collaborator escaped its transaction');
|
||||||
|
});
|
||||||
|
const transaction = mock(async <T>(work: (client: PoolClient) => Promise<T>) => work(client));
|
||||||
|
const services = createResearchServices({
|
||||||
|
postgres: { query: poolQuery, transaction },
|
||||||
|
} as unknown as IServiceContainer);
|
||||||
|
const failure = new Error('Injected preview failure');
|
||||||
|
const lockedPreview = mock(async () => {
|
||||||
|
throw failure;
|
||||||
|
});
|
||||||
|
services.experiments.lockedPreview = lockedPreview;
|
||||||
|
const base = { backtestId: randomUUID(), name: 'Shared preview', grid: { fastPeriod: [1, 2] } };
|
||||||
|
const windows = walkForwardDataset().windows;
|
||||||
|
await expect(services.walkForwards.preview({ ...base, windows })).rejects.toBe(failure);
|
||||||
|
expect(lockedPreview).toHaveBeenLastCalledWith(client, base, 'operator');
|
||||||
|
await expect(
|
||||||
|
services.validations.submit(
|
||||||
|
{ ...base, recipe: windows[0], previewHash: 'a'.repeat(64) },
|
||||||
|
{ principal: 'operator', key: 'validation-preview' }
|
||||||
|
)
|
||||||
|
).rejects.toBe(failure);
|
||||||
|
expect(lockedPreview).toHaveBeenLastCalledWith(client, base, 'operator');
|
||||||
|
expect(lockedPreview).toHaveBeenCalledTimes(2);
|
||||||
|
expect(transaction).toHaveBeenCalledTimes(2);
|
||||||
|
expect(poolQuery).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('evidence accepts only a result-reader collaborator and passes through the supplied transaction', async () => {
|
||||||
|
const runId = randomUUID();
|
||||||
|
const client = {
|
||||||
|
query: mock(async () => ({
|
||||||
|
rows: [{ id: runId, backtest_id: randomUUID(), status: 'completed' }],
|
||||||
|
})),
|
||||||
|
} as unknown as PoolClient;
|
||||||
|
const poolQuery = mock(async () => {
|
||||||
|
throw new Error('Evidence escaped the supplied transaction');
|
||||||
|
});
|
||||||
|
const transaction = mock(async () => {
|
||||||
|
throw new Error('Evidence must not open a nested transaction');
|
||||||
|
});
|
||||||
|
const getRunResults = mock(async () => null);
|
||||||
|
const evidence = new ResearchEvidenceResolver(
|
||||||
|
{ postgres: { query: poolQuery, transaction } } as unknown as IServiceContainer,
|
||||||
|
{ getRunResults }
|
||||||
|
);
|
||||||
|
await expect(
|
||||||
|
evidence.resolve(
|
||||||
|
{
|
||||||
|
runId,
|
||||||
|
metricsVersion: 'canonical-analytics/v1',
|
||||||
|
metricPath: 'analytics.metrics.totalReturn',
|
||||||
|
},
|
||||||
|
client
|
||||||
|
)
|
||||||
|
).rejects.toThrow('Retained evidence result is missing');
|
||||||
|
expect(getRunResults).toHaveBeenCalledWith(runId, client);
|
||||||
|
expect(poolQuery).not.toHaveBeenCalled();
|
||||||
|
expect(transaction).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
@ -18,7 +18,7 @@ import { createResearchAgentRoutes } from '../../apps/stock/web-api/src/routes/r
|
||||||
import { createResearchRoutes } from '../../apps/stock/web-api/src/routes/research.routes';
|
import { createResearchRoutes } from '../../apps/stock/web-api/src/routes/research.routes';
|
||||||
import { createStrategyRoutes } from '../../apps/stock/web-api/src/routes/strategies.routes';
|
import { createStrategyRoutes } from '../../apps/stock/web-api/src/routes/strategies.routes';
|
||||||
import { ResearchAgentsService } from '../../apps/stock/web-api/src/services/research-agents.service';
|
import { ResearchAgentsService } from '../../apps/stock/web-api/src/services/research-agents.service';
|
||||||
import { ResearchService } from '../../apps/stock/web-api/src/services/research.service';
|
import { createResearchServices } from '../../apps/stock/web-api/src/services/research-services';
|
||||||
import {
|
import {
|
||||||
runResearchCycle,
|
runResearchCycle,
|
||||||
type ResearchCycleEvent,
|
type ResearchCycleEvent,
|
||||||
|
|
@ -91,7 +91,7 @@ async function fixture() {
|
||||||
);
|
);
|
||||||
const container = { postgres, logger };
|
const container = { postgres, logger };
|
||||||
const agents = new ResearchAgentsService(container),
|
const agents = new ResearchAgentsService(container),
|
||||||
research = new ResearchService(container);
|
research = createResearchServices(container).research;
|
||||||
const project = await research.createProject({ title: 'AI research acceptance' }, 'operator');
|
const project = await research.createProject({ title: 'AI research acceptance' }, 'operator');
|
||||||
const provisioned = await agents.create({
|
const provisioned = await agents.create({
|
||||||
name: 'Workflow researcher',
|
name: 'Workflow researcher',
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,9 @@ import { PostgresBacktestRunRepository } from '../../apps/stock/orchestrator/src
|
||||||
import { RustBacktestAdapter } from '../../apps/stock/orchestrator/src/backtest/RustBacktestAdapter';
|
import { RustBacktestAdapter } from '../../apps/stock/orchestrator/src/backtest/RustBacktestAdapter';
|
||||||
import { createExperimentRoutes } from '../../apps/stock/web-api/src/routes/experiments.routes';
|
import { createExperimentRoutes } from '../../apps/stock/web-api/src/routes/experiments.routes';
|
||||||
import { BacktestServiceV2 } from '../../apps/stock/web-api/src/services/backtest-v2.service';
|
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 { experimentHash } from '../../apps/stock/web-api/src/services/experiment-input';
|
import { experimentHash } from '../../apps/stock/web-api/src/services/experiment-input';
|
||||||
import { ExperimentsService } from '../../apps/stock/web-api/src/services/experiments.service';
|
import { ExperimentsService } from '../../apps/stock/web-api/src/services/experiments.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 { StrategyCatalogService } from '../../apps/stock/web-api/src/services/strategy-catalog.service';
|
||||||
import {
|
import {
|
||||||
selectValidationWinner,
|
selectValidationWinner,
|
||||||
|
|
@ -168,7 +168,7 @@ async function fixture(poolMax = 1, withValidation = true) {
|
||||||
}
|
}
|
||||||
return rows;
|
return rows;
|
||||||
};
|
};
|
||||||
const validations = new ChronologicalValidationService(container);
|
const validations = createResearchServices(container).validations;
|
||||||
const repository = new PostgresBacktestRunRepository(postgres);
|
const repository = new PostgresBacktestRunRepository(postgres);
|
||||||
const execute = async (id: string) => {
|
const execute = async (id: string) => {
|
||||||
const engine = new RustBacktestAdapter({
|
const engine = new RustBacktestAdapter({
|
||||||
|
|
|
||||||
|
|
@ -13,10 +13,10 @@ import { PostgresBacktestRunRepository } from '../../apps/stock/orchestrator/src
|
||||||
import { RustBacktestAdapter } from '../../apps/stock/orchestrator/src/backtest/RustBacktestAdapter';
|
import { RustBacktestAdapter } from '../../apps/stock/orchestrator/src/backtest/RustBacktestAdapter';
|
||||||
import { createExperimentRoutes } from '../../apps/stock/web-api/src/routes/experiments.routes';
|
import { createExperimentRoutes } from '../../apps/stock/web-api/src/routes/experiments.routes';
|
||||||
import { BacktestServiceV2 } from '../../apps/stock/web-api/src/services/backtest-v2.service';
|
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 { ExperimentError } from '../../apps/stock/web-api/src/services/experiment-input';
|
import { ExperimentError } from '../../apps/stock/web-api/src/services/experiment-input';
|
||||||
import { ExperimentsService } from '../../apps/stock/web-api/src/services/experiments.service';
|
import { ExperimentsService } from '../../apps/stock/web-api/src/services/experiments.service';
|
||||||
import { canonicalReproductionHash } from '../../apps/stock/web-api/src/services/reproduction-comparison';
|
import { canonicalReproductionHash } from '../../apps/stock/web-api/src/services/reproduction-comparison';
|
||||||
|
import { createResearchServices } from '../../apps/stock/web-api/src/services/research-services';
|
||||||
import { StrategyCatalogService } from '../../apps/stock/web-api/src/services/strategy-catalog.service';
|
import { StrategyCatalogService } from '../../apps/stock/web-api/src/services/strategy-catalog.service';
|
||||||
import { retainResearchDataset } from '../../scripts/import-research-dataset';
|
import { retainResearchDataset } from '../../scripts/import-research-dataset';
|
||||||
import { packageBuiltinStrategies } from '../../scripts/package-builtin-strategies';
|
import { packageBuiltinStrategies } from '../../scripts/package-builtin-strategies';
|
||||||
|
|
@ -162,7 +162,7 @@ async function fixture(poolMax = 1, withCosts = true, capital = 10000) {
|
||||||
}
|
}
|
||||||
return rows;
|
return rows;
|
||||||
};
|
};
|
||||||
const validations = new ChronologicalValidationService(container);
|
const validations = createResearchServices(container).validations;
|
||||||
const repository = new PostgresBacktestRunRepository(postgres);
|
const repository = new PostgresBacktestRunRepository(postgres);
|
||||||
const execute = async (id: string) => {
|
const execute = async (id: string) => {
|
||||||
const engine = new RustBacktestAdapter({
|
const engine = new RustBacktestAdapter({
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,8 @@ import { PostgresBacktestRunRepository } from '../../apps/stock/orchestrator/src
|
||||||
import { RustBacktestAdapter } from '../../apps/stock/orchestrator/src/backtest/RustBacktestAdapter';
|
import { RustBacktestAdapter } from '../../apps/stock/orchestrator/src/backtest/RustBacktestAdapter';
|
||||||
import { createExperimentRoutes } from '../../apps/stock/web-api/src/routes/experiments.routes';
|
import { createExperimentRoutes } from '../../apps/stock/web-api/src/routes/experiments.routes';
|
||||||
import { BacktestServiceV2 } from '../../apps/stock/web-api/src/services/backtest-v2.service';
|
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 { ExperimentsService } from '../../apps/stock/web-api/src/services/experiments.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 { StrategyCatalogService } from '../../apps/stock/web-api/src/services/strategy-catalog.service';
|
||||||
import { retainResearchDataset } from '../../scripts/import-research-dataset';
|
import { retainResearchDataset } from '../../scripts/import-research-dataset';
|
||||||
import { packageBuiltinStrategies } from '../../scripts/package-builtin-strategies';
|
import { packageBuiltinStrategies } from '../../scripts/package-builtin-strategies';
|
||||||
|
|
@ -163,7 +163,7 @@ async function fixture(poolMax = 1, withCosts = true, capital = 10000) {
|
||||||
}
|
}
|
||||||
return rows;
|
return rows;
|
||||||
};
|
};
|
||||||
const validations = new ChronologicalValidationService(container);
|
const validations = createResearchServices(container).validations;
|
||||||
const repository = new PostgresBacktestRunRepository(postgres);
|
const repository = new PostgresBacktestRunRepository(postgres);
|
||||||
const execute = async (id: string) => {
|
const execute = async (id: string) => {
|
||||||
const engine = new RustBacktestAdapter({
|
const engine = new RustBacktestAdapter({
|
||||||
|
|
|
||||||
|
|
@ -13,11 +13,10 @@ import { PostgresBacktestRunRepository } from '../../apps/stock/orchestrator/src
|
||||||
import { RustBacktestAdapter } from '../../apps/stock/orchestrator/src/backtest/RustBacktestAdapter';
|
import { RustBacktestAdapter } from '../../apps/stock/orchestrator/src/backtest/RustBacktestAdapter';
|
||||||
import { runStrategyReplay } from '../../apps/stock/orchestrator/src/backtest/strategy-runtime';
|
import { runStrategyReplay } from '../../apps/stock/orchestrator/src/backtest/strategy-runtime';
|
||||||
import { createBuiltinStrategy } from '../../apps/stock/orchestrator/src/strategies/canonical-builtins';
|
import { createBuiltinStrategy } from '../../apps/stock/orchestrator/src/strategies/canonical-builtins';
|
||||||
import { ChronologicalValidationService } from '../../apps/stock/web-api/src/services/chronological-validation.service';
|
|
||||||
import { ExperimentsService } from '../../apps/stock/web-api/src/services/experiments.service';
|
import { ExperimentsService } from '../../apps/stock/web-api/src/services/experiments.service';
|
||||||
import { researchGrantPolicy } from '../../apps/stock/web-api/src/services/research-agent-budget';
|
import { researchGrantPolicy } from '../../apps/stock/web-api/src/services/research-agent-budget';
|
||||||
import { ResearchAgentsService } from '../../apps/stock/web-api/src/services/research-agents.service';
|
import { ResearchAgentsService } from '../../apps/stock/web-api/src/services/research-agents.service';
|
||||||
import { WalkForwardService } from '../../apps/stock/web-api/src/services/walk-forward.service';
|
import { createResearchServices } from '../../apps/stock/web-api/src/services/research-services';
|
||||||
import { retainResearchDataset } from '../../scripts/import-research-dataset';
|
import { retainResearchDataset } from '../../scripts/import-research-dataset';
|
||||||
import { canonicalAdmissionFixture } from '../fixtures/canonical-admission';
|
import { canonicalAdmissionFixture } from '../fixtures/canonical-admission';
|
||||||
import { walkForwardDataset } from '../fixtures/walk-forward';
|
import { walkForwardDataset } from '../fixtures/walk-forward';
|
||||||
|
|
@ -359,8 +358,7 @@ suite('isolated candidate durable research', () => {
|
||||||
endDate: new Date(data.dataset.manifest.bounds.tradeEnd).toISOString(),
|
endDate: new Date(data.dataset.manifest.bounds.tradeEnd).toISOString(),
|
||||||
config: { ...f.definition.config, datasetHash: data.dataset.manifest.hash },
|
config: { ...f.definition.config, datasetHash: data.dataset.manifest.hash },
|
||||||
});
|
});
|
||||||
const walks = new WalkForwardService(f.container),
|
const { walkForwards: walks, validations } = createResearchServices(f.container);
|
||||||
validations = new ChronologicalValidationService(f.container);
|
|
||||||
const input = {
|
const input = {
|
||||||
name: 'Candidate rolling windows',
|
name: 'Candidate rolling windows',
|
||||||
backtestId: f.draft.id,
|
backtestId: f.draft.id,
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,8 @@ import {
|
||||||
import { readPaperHostIdentity } from '../../apps/stock/orchestrator/src/paper/paper-host-identity';
|
import { readPaperHostIdentity } from '../../apps/stock/orchestrator/src/paper/paper-host-identity';
|
||||||
import { PaperDeploymentHost } from '../../apps/stock/orchestrator/src/paper/PaperDeploymentHost';
|
import { PaperDeploymentHost } from '../../apps/stock/orchestrator/src/paper/PaperDeploymentHost';
|
||||||
import { BacktestServiceV2 } from '../../apps/stock/web-api/src/services/backtest-v2.service';
|
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 { 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 { StrategyCatalogService } from '../../apps/stock/web-api/src/services/strategy-catalog.service';
|
||||||
import { retainResearchDataset } from '../../scripts/import-research-dataset';
|
import { retainResearchDataset } from '../../scripts/import-research-dataset';
|
||||||
import { packageBuiltinStrategies } from '../../scripts/package-builtin-strategies';
|
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, 'connectionPool', { get: () => pool });
|
||||||
Object.defineProperty(postgres, 'query', { value: pool.query.bind(pool) });
|
Object.defineProperty(postgres, 'query', { value: pool.query.bind(pool) });
|
||||||
const container = { postgres, logger },
|
const container = { postgres, logger },
|
||||||
|
researchServices = createResearchServices(container),
|
||||||
api = new BacktestServiceV2(container),
|
api = new BacktestServiceV2(container),
|
||||||
experiments = new ExperimentsService(container),
|
experiments = new ExperimentsService(container),
|
||||||
validations = new ChronologicalValidationService(container),
|
validations = researchServices.validations,
|
||||||
catalog = new StrategyCatalogService(container),
|
catalog = new StrategyCatalogService(container),
|
||||||
service = new PaperDeploymentsService(container);
|
service = researchServices.paperDeployments;
|
||||||
const pkg = (await packageBuiltinStrategies())[0];
|
const pkg = (await packageBuiltinStrategies())[0];
|
||||||
if (!pkg) {
|
if (!pkg) {
|
||||||
throw new Error('Missing builtin');
|
throw new Error('Missing builtin');
|
||||||
|
|
@ -495,14 +495,18 @@ describe.skipIf(!url)('human-reviewed paper deployment', () => {
|
||||||
}, 60000);
|
}, 60000);
|
||||||
test('changed installed host and retained artifact cannot initialize or overwrite an account', async () => {
|
test('changed installed host and retained artifact cannot initialize or overwrite an account', async () => {
|
||||||
const f = await fixture(),
|
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()),
|
...(await readPaperHostIdentity()),
|
||||||
hostSha256: 'f'.repeat(64),
|
engineBinarySha256: 'f'.repeat(64),
|
||||||
}));
|
}),
|
||||||
const wrongNative = new PaperDeploymentsService(f.container, async () => ({
|
}).paperDeployments;
|
||||||
...(await readPaperHostIdentity()),
|
|
||||||
engineBinarySha256: 'f'.repeat(64),
|
|
||||||
}));
|
|
||||||
await expect(wrongNative.preview(f.promotion)).rejects.toThrow('same native');
|
await expect(wrongNative.preview(f.promotion)).rejects.toThrow('same native');
|
||||||
const preview = await drifted.preview(f.promotion),
|
const preview = await drifted.preview(f.promotion),
|
||||||
saved = await drifted.create(
|
saved = await drifted.create(
|
||||||
|
|
|
||||||
|
|
@ -17,13 +17,11 @@ import { createRoutes } from '../../apps/stock/web-api/src/routes/create-routes'
|
||||||
import { createExperimentRoutes } from '../../apps/stock/web-api/src/routes/experiments.routes';
|
import { createExperimentRoutes } from '../../apps/stock/web-api/src/routes/experiments.routes';
|
||||||
import { BacktestServiceV2 } from '../../apps/stock/web-api/src/services/backtest-v2.service';
|
import { BacktestServiceV2 } from '../../apps/stock/web-api/src/services/backtest-v2.service';
|
||||||
import { BacktestDispatcher } from '../../apps/stock/web-api/src/services/BacktestDispatcher';
|
import { BacktestDispatcher } from '../../apps/stock/web-api/src/services/BacktestDispatcher';
|
||||||
import { ChronologicalValidationService } from '../../apps/stock/web-api/src/services/chronological-validation.service';
|
|
||||||
import { ExperimentsService } from '../../apps/stock/web-api/src/services/experiments.service';
|
import { ExperimentsService } from '../../apps/stock/web-api/src/services/experiments.service';
|
||||||
import { researchGrantPolicy } from '../../apps/stock/web-api/src/services/research-agent-budget';
|
import { researchGrantPolicy } from '../../apps/stock/web-api/src/services/research-agent-budget';
|
||||||
import { ResearchAgentsService } from '../../apps/stock/web-api/src/services/research-agents.service';
|
import { ResearchAgentsService } from '../../apps/stock/web-api/src/services/research-agents.service';
|
||||||
import { ResearchService } from '../../apps/stock/web-api/src/services/research.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 { StrategyCatalogService } from '../../apps/stock/web-api/src/services/strategy-catalog.service';
|
||||||
import { WalkForwardService } from '../../apps/stock/web-api/src/services/walk-forward.service';
|
|
||||||
import { retainResearchDataset } from '../../scripts/import-research-dataset';
|
import { retainResearchDataset } from '../../scripts/import-research-dataset';
|
||||||
import { packageBuiltinStrategies } from '../../scripts/package-builtin-strategies';
|
import { packageBuiltinStrategies } from '../../scripts/package-builtin-strategies';
|
||||||
import { canonicalSettings } from '../fixtures/canonical-research';
|
import { canonicalSettings } from '../fixtures/canonical-research';
|
||||||
|
|
@ -142,7 +140,7 @@ async function fixture(poolMax = 4, withAgents = true, dataset = canonicalSmaFix
|
||||||
postgres,
|
postgres,
|
||||||
container,
|
container,
|
||||||
agents: new ResearchAgentsService(container),
|
agents: new ResearchAgentsService(container),
|
||||||
research: new ResearchService(container),
|
research: createResearchServices(container).research,
|
||||||
schema,
|
schema,
|
||||||
api,
|
api,
|
||||||
experiments,
|
experiments,
|
||||||
|
|
@ -687,8 +685,7 @@ describe.skipIf(!url)('authoritative research principals and budgets', () => {
|
||||||
);
|
);
|
||||||
expect(cost.trials).toHaveLength(2);
|
expect(cost.trials).toHaveLength(2);
|
||||||
await f.experiments.cancel(cost.id);
|
await f.experiments.cancel(cost.id);
|
||||||
const validation = new ChronologicalValidationService(f.container),
|
const { validations: validation, walkForwards: walk } = createResearchServices(f.container);
|
||||||
walk = new WalkForwardService(f.container);
|
|
||||||
const input = {
|
const input = {
|
||||||
backtestId: f.draft.id,
|
backtestId: f.draft.id,
|
||||||
name: 'Validation',
|
name: 'Validation',
|
||||||
|
|
@ -909,7 +906,7 @@ describe.skipIf(!url)('authoritative research principals and budgets', () => {
|
||||||
[randomUUID(), runId, b.agent.id, randomUUID(), 'a'.repeat(64)]
|
[randomUUID(), runId, b.agent.id, randomUUID(), 'a'.repeat(64)]
|
||||||
)
|
)
|
||||||
).rejects.toThrow(/owning.*principal/);
|
).rejects.toThrow(/owning.*principal/);
|
||||||
const validation = new ChronologicalValidationService(f.container),
|
const validation = createResearchServices(f.container).validations,
|
||||||
input = {
|
input = {
|
||||||
backtestId: f.draft.id,
|
backtestId: f.draft.id,
|
||||||
name: 'Owned phases',
|
name: 'Owned phases',
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import { PostgresBacktestRunRepository } from '../../apps/stock/orchestrator/src
|
||||||
import { BacktestLeaseLostError } from '../../apps/stock/orchestrator/src/backtest/run-repository';
|
import { BacktestLeaseLostError } from '../../apps/stock/orchestrator/src/backtest/run-repository';
|
||||||
import { canonicalReproductionHash } from '../../apps/stock/web-api/src/services/reproduction-comparison';
|
import { canonicalReproductionHash } from '../../apps/stock/web-api/src/services/reproduction-comparison';
|
||||||
import { ResearchAgentsService } from '../../apps/stock/web-api/src/services/research-agents.service';
|
import { ResearchAgentsService } from '../../apps/stock/web-api/src/services/research-agents.service';
|
||||||
import { ResearchService } from '../../apps/stock/web-api/src/services/research.service';
|
import { createResearchServices } from '../../apps/stock/web-api/src/services/research-services';
|
||||||
import { deferred } from '../fixtures/canonical-runner';
|
import { deferred } from '../fixtures/canonical-runner';
|
||||||
import { logger } from '../fixtures/execution';
|
import { logger } from '../fixtures/execution';
|
||||||
import { nativeReplayFixture } from '../fixtures/native-replay';
|
import { nativeReplayFixture } from '../fixtures/native-replay';
|
||||||
|
|
@ -201,7 +201,7 @@ describe.skipIf(!process.env.PIPELINE_TEST_DATABASE_URL || !process.env.BACKTEST
|
||||||
}, 60000);
|
}, 60000);
|
||||||
test('four slots cannot bypass agent admission capacity or per-attempt absolute deadlines', async () => {
|
test('four slots cannot bypass agent admission capacity or per-attempt absolute deadlines', async () => {
|
||||||
const f = await fixture();
|
const f = await fixture();
|
||||||
const research = new ResearchService({ postgres: f.postgres, logger });
|
const research = createResearchServices({ postgres: f.postgres, logger }).research;
|
||||||
const project = await research.createProject({ title: 'Pool budget gate' }, 'operator');
|
const project = await research.createProject({ title: 'Pool budget gate' }, 'operator');
|
||||||
const agents = new ResearchAgentsService({ postgres: f.postgres, logger });
|
const agents = new ResearchAgentsService({ postgres: f.postgres, logger });
|
||||||
const agent = await agents.create({
|
const agent = await agents.create({
|
||||||
|
|
|
||||||
|
|
@ -13,12 +13,10 @@ import { PostgresBacktestRunRepository } from '../../apps/stock/orchestrator/src
|
||||||
import { RustBacktestAdapter } from '../../apps/stock/orchestrator/src/backtest/RustBacktestAdapter';
|
import { RustBacktestAdapter } from '../../apps/stock/orchestrator/src/backtest/RustBacktestAdapter';
|
||||||
import { createResearchRoutes } from '../../apps/stock/web-api/src/routes/research.routes';
|
import { createResearchRoutes } from '../../apps/stock/web-api/src/routes/research.routes';
|
||||||
import { BacktestServiceV2 } from '../../apps/stock/web-api/src/services/backtest-v2.service';
|
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 { experimentHash } from '../../apps/stock/web-api/src/services/experiment-input';
|
import { experimentHash } from '../../apps/stock/web-api/src/services/experiment-input';
|
||||||
import { ExperimentsService } from '../../apps/stock/web-api/src/services/experiments.service';
|
import { ExperimentsService } from '../../apps/stock/web-api/src/services/experiments.service';
|
||||||
import { ResearchService } from '../../apps/stock/web-api/src/services/research.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 { StrategyCatalogService } from '../../apps/stock/web-api/src/services/strategy-catalog.service';
|
||||||
import { WalkForwardService } from '../../apps/stock/web-api/src/services/walk-forward.service';
|
|
||||||
import { retainResearchDataset } from '../../scripts/import-research-dataset';
|
import { retainResearchDataset } from '../../scripts/import-research-dataset';
|
||||||
import { packageBuiltinStrategies } from '../../scripts/package-builtin-strategies';
|
import { packageBuiltinStrategies } from '../../scripts/package-builtin-strategies';
|
||||||
import { canonicalSettings } from '../fixtures/canonical-research';
|
import { canonicalSettings } from '../fixtures/canonical-research';
|
||||||
|
|
@ -145,7 +143,8 @@ async function fixture(poolMax = 1, withSources = true) {
|
||||||
}
|
}
|
||||||
return rows;
|
return rows;
|
||||||
};
|
};
|
||||||
const validations = new ChronologicalValidationService(container);
|
const services = createResearchServices(container);
|
||||||
|
const validations = services.validations;
|
||||||
const repository = new PostgresBacktestRunRepository(postgres);
|
const repository = new PostgresBacktestRunRepository(postgres);
|
||||||
const execute = async (id: string) => {
|
const execute = async (id: string) => {
|
||||||
const engine = new RustBacktestAdapter({
|
const engine = new RustBacktestAdapter({
|
||||||
|
|
@ -179,7 +178,7 @@ async function fixture(poolMax = 1, withSources = true) {
|
||||||
{ autoStart: false }
|
{ autoStart: false }
|
||||||
),
|
),
|
||||||
validations,
|
validations,
|
||||||
walks: new WalkForwardService(container),
|
walks: services.walkForwards,
|
||||||
repository,
|
repository,
|
||||||
execute,
|
execute,
|
||||||
api,
|
api,
|
||||||
|
|
@ -191,7 +190,7 @@ async function fixture(poolMax = 1, withSources = true) {
|
||||||
draft,
|
draft,
|
||||||
dataset,
|
dataset,
|
||||||
input,
|
input,
|
||||||
research: new ResearchService(container),
|
research: services.research,
|
||||||
container,
|
container,
|
||||||
schema,
|
schema,
|
||||||
review,
|
review,
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import { BacktestRunner } from '../../apps/stock/orchestrator/src/backtest/Backt
|
||||||
import { PostgresBacktestRunRepository } from '../../apps/stock/orchestrator/src/backtest/PostgresBacktestRunRepository';
|
import { PostgresBacktestRunRepository } from '../../apps/stock/orchestrator/src/backtest/PostgresBacktestRunRepository';
|
||||||
import { RustBacktestAdapter } from '../../apps/stock/orchestrator/src/backtest/RustBacktestAdapter';
|
import { RustBacktestAdapter } from '../../apps/stock/orchestrator/src/backtest/RustBacktestAdapter';
|
||||||
import { BacktestServiceV2 } from '../../apps/stock/web-api/src/services/backtest-v2.service';
|
import { BacktestServiceV2 } from '../../apps/stock/web-api/src/services/backtest-v2.service';
|
||||||
import { ResearchService } from '../../apps/stock/web-api/src/services/research.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 { StrategyCatalogService } from '../../apps/stock/web-api/src/services/strategy-catalog.service';
|
||||||
import { retainResearchDataset } from '../../scripts/import-research-dataset';
|
import { retainResearchDataset } from '../../scripts/import-research-dataset';
|
||||||
import { packageBuiltinStrategies } from '../../scripts/package-builtin-strategies';
|
import { packageBuiltinStrategies } from '../../scripts/package-builtin-strategies';
|
||||||
|
|
@ -81,7 +81,7 @@ async function fixture(applyWorkspace = true, maxConnections = 10) {
|
||||||
Object.defineProperty(postgres, 'connectionPool', { get: () => pool });
|
Object.defineProperty(postgres, 'connectionPool', { get: () => pool });
|
||||||
Object.defineProperty(postgres, 'query', { value: pool.query.bind(pool) });
|
Object.defineProperty(postgres, 'query', { value: pool.query.bind(pool) });
|
||||||
const container = { postgres, logger };
|
const container = { postgres, logger };
|
||||||
const service = new ResearchService(container);
|
const service = createResearchServices(container).research;
|
||||||
const backtests = new BacktestServiceV2(container);
|
const backtests = new BacktestServiceV2(container);
|
||||||
const catalog = new StrategyCatalogService(container);
|
const catalog = new StrategyCatalogService(container);
|
||||||
const legacy = async (status = 'completed') => {
|
const legacy = async (status = 'completed') => {
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,10 @@ import { PostgresBacktestRunRepository } from '../../apps/stock/orchestrator/src
|
||||||
import { RustBacktestAdapter } from '../../apps/stock/orchestrator/src/backtest/RustBacktestAdapter';
|
import { RustBacktestAdapter } from '../../apps/stock/orchestrator/src/backtest/RustBacktestAdapter';
|
||||||
import { createExperimentRoutes } from '../../apps/stock/web-api/src/routes/experiments.routes';
|
import { createExperimentRoutes } from '../../apps/stock/web-api/src/routes/experiments.routes';
|
||||||
import { BacktestServiceV2 } from '../../apps/stock/web-api/src/services/backtest-v2.service';
|
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 { ExperimentError } from '../../apps/stock/web-api/src/services/experiment-input';
|
import { ExperimentError } from '../../apps/stock/web-api/src/services/experiment-input';
|
||||||
import { ExperimentsService } from '../../apps/stock/web-api/src/services/experiments.service';
|
import { ExperimentsService } from '../../apps/stock/web-api/src/services/experiments.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 { StrategyCatalogService } from '../../apps/stock/web-api/src/services/strategy-catalog.service';
|
||||||
import { WalkForwardService } from '../../apps/stock/web-api/src/services/walk-forward.service';
|
|
||||||
import { retainResearchDataset } from '../../scripts/import-research-dataset';
|
import { retainResearchDataset } from '../../scripts/import-research-dataset';
|
||||||
import { packageBuiltinStrategies } from '../../scripts/package-builtin-strategies';
|
import { packageBuiltinStrategies } from '../../scripts/package-builtin-strategies';
|
||||||
import { canonicalSettings } from '../fixtures/canonical-research';
|
import { canonicalSettings } from '../fixtures/canonical-research';
|
||||||
|
|
@ -158,7 +157,8 @@ async function fixture(poolMax = 1, withWalkForward = true) {
|
||||||
}
|
}
|
||||||
return rows;
|
return rows;
|
||||||
};
|
};
|
||||||
const validations = new ChronologicalValidationService(container);
|
const services = createResearchServices(container);
|
||||||
|
const validations = services.validations;
|
||||||
const repository = new PostgresBacktestRunRepository(postgres);
|
const repository = new PostgresBacktestRunRepository(postgres);
|
||||||
const execute = async (id: string) => {
|
const execute = async (id: string) => {
|
||||||
const engine = new RustBacktestAdapter({
|
const engine = new RustBacktestAdapter({
|
||||||
|
|
@ -192,7 +192,7 @@ async function fixture(poolMax = 1, withWalkForward = true) {
|
||||||
{ autoStart: false }
|
{ autoStart: false }
|
||||||
),
|
),
|
||||||
validations,
|
validations,
|
||||||
walks: new WalkForwardService(container),
|
walks: services.walkForwards,
|
||||||
repository,
|
repository,
|
||||||
execute,
|
execute,
|
||||||
api,
|
api,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue