feat(research): isolate candidates and add reviewed paper promotion

This commit is contained in:
Boki 2026-10-24 18:46:55 -04:00
parent 26b97265c6
commit 25b5cbf481
128 changed files with 13038 additions and 1388 deletions

View file

@ -1,9 +1,12 @@
import { asFunction, createContainer as createDiContainer } from 'awilix';
import { asFunction, asValue, createContainer as createDiContainer } from 'awilix';
import { expect, test } from 'bun:test';
import type { ServiceCradle } from '@stock-bot/di';
import { ServiceContainerBuilder, type ServiceCradle } from '@stock-bot/di';
import type { StockAppConfig } from '@stock-bot/stock-config';
import { registerOrchestratorServices } from '../../apps/stock/orchestrator/src/container';
import type { PaperConfigurationInput } from '../../apps/stock/orchestrator/src/contracts/paper-runtime';
import { createContainer } from '../../apps/stock/orchestrator/src/simple-container';
import type { OrchestratorServices } from '../../apps/stock/orchestrator/src/types';
import { logger } from '../fixtures/execution';
import { paperFeedConfiguration } from '../fixtures/paper-feed';
test('canonical paper rejects invalid role/configuration before resolving services', async () => {
@ -44,3 +47,83 @@ test('live defaults, research canonical configuration and missing custody fail b
createContainer(config({ defaultMode: 'paper', canonicalPaper: paperFeedConfiguration() }))
).rejects.toThrow('requires durable PostgreSQL');
});
test('reviewed deployment host is explicit, exclusive, durable and never enabled for research', async () => {
const container = createDiContainer<ServiceCradle>();
let resolved = 0;
container.register({
serviceContainer: asFunction(() => {
resolved++;
throw new Error('Unexpected service resolution');
}),
});
await expect(
registerOrchestratorServices(container, {
role: 'research-only',
paperDeploymentHost: { enabled: true },
})
).rejects.toThrow('requires a paper composition');
await expect(
registerOrchestratorServices(container, {
role: 'paper',
canonicalPaper: paperFeedConfiguration(),
paperDeploymentHost: { enabled: true },
})
).rejects.toThrow('never two account owners');
await expect(
registerOrchestratorServices(container, {
role: 'paper',
paperDeploymentHost: { enabled: true, deploymentId: 'not-a-uuid' },
})
).rejects.toThrow();
await expect(
registerOrchestratorServices(container, {
role: 'paper',
canonicalPaper: { ...paperFeedConfiguration(), version: 2 } as PaperConfigurationInput,
})
).rejects.toThrow('reviewed deployment host');
expect(resolved).toBe(0);
const config = {
services: { orchestrator: { defaultMode: 'paper', paperDeploymentHost: { enabled: true } } },
} as StockAppConfig;
await expect(createContainer(config)).rejects.toThrow('requires durable PostgreSQL');
});
test('explicit deployment host initializes unbound without account reads, writes or activation', async () => {
const container = await new ServiceContainerBuilder()
.withOptions({
enableCache: false,
enableQueue: false,
enableMongoDB: false,
enablePostgres: false,
enableQuestDB: false,
enableBrowser: false,
enableProxy: false,
})
.build();
let transactions = 0;
const services: OrchestratorServices = {
logger,
postgres: {
transaction() {
transactions++;
throw new Error('Unbound host must not access account state');
},
} as unknown as NonNullable<OrchestratorServices['postgres']>,
};
container.register({ serviceContainer: asValue(services) });
try {
await registerOrchestratorServices(container, {
role: 'paper',
paperDeploymentHost: { enabled: true },
});
expect(services.custom?.PaperDeploymentHost).toBeDefined();
expect(services.custom?.CanonicalPaperRuntime).toBeUndefined();
expect(() => services.custom!.PaperDeploymentHost!.runtime()).toThrow('not bound');
expect(transactions).toBe(0);
} finally {
await services.custom?.PaperDeploymentHost?.shutdown();
await services.custom?.BacktestRunner?.shutdown();
await container.dispose();
}
});