- Remove ~44k LOC of dead code, legacy v1 TS simulator/strategy stack, event-bus, analytics FastAPI prototype, legacy calculation archives, and unused deps (data-ingestion provider API handlers untouched) - Extract @stock-bot/di/http-security and isolate @stock-bot/browser to data-ingestion via ServiceContainerBuilder.withRegistrations() - Harden @stock-bot/mongodb read-only proxies, flatten @stock-bot/postgres with unified master+research migrations, and fix @stock-bot/config EnvLoader, ServiceApplication worker lifecycle, NamespacedCache.clear(), and BatchProcessor error propagation - Flatten workspace root (remove apps/stock/package.json) and collapse orchestrator re-export shims - Pin all Docker image versions, add shm_size/nofile/RAM caps and docker-compose.quant.yml, fix 05-add-visible-column.sql view recreation, and decouple dev/QA Compose project names for side-by-side execution - Update PLATFORM-PLAN, DATA-CONTRACTS (bars_1m PARTITION BY MONTH, Rust bulk ETL, DuckDB limits), MILESTONES, and servers docs
133 lines
4.8 KiB
TypeScript
133 lines
4.8 KiB
TypeScript
import { describe, expect, it } from 'bun:test';
|
|
import { ZodError } from 'zod';
|
|
import { baseAppSchema } from '@stock-bot/config';
|
|
import { ServiceContainerBuilder } from '../src/container/builder';
|
|
|
|
// Production schemas and registrations, with initialization disabled: no module
|
|
// mocks, environment credentials, sockets or a second config implementation.
|
|
function configuration() {
|
|
return baseAppSchema.parse({
|
|
name: 'di-test',
|
|
version: '1.0.0',
|
|
environment: 'test',
|
|
service: { name: 'TestService', port: 3000 },
|
|
log: { level: 'fatal' },
|
|
database: {
|
|
dragonfly: { enabled: false },
|
|
mongodb: { enabled: false, uri: 'mongodb://localhost/test', database: 'fixture' },
|
|
postgres: { enabled: false, database: 'fixture', user: 'fixture', password: 'fixture' },
|
|
questdb: { enabled: false, ilpPort: 19009 },
|
|
},
|
|
});
|
|
}
|
|
|
|
async function compose(config = configuration()) {
|
|
return new ServiceContainerBuilder().withConfig(config).skipInitialization().build();
|
|
}
|
|
|
|
describe('ServiceContainerBuilder production configuration', () => {
|
|
it('normalizes nested configuration and registers real services without connecting', async () => {
|
|
const container = await compose();
|
|
try {
|
|
const config = container.resolve('config');
|
|
expect(config.service?.serviceName).toBe('test-service');
|
|
expect(config.mongodb.database).toBe('fixture');
|
|
expect(config.postgres.database).toBe('fixture');
|
|
expect(config.questdb?.influxPort).toBe(19009);
|
|
for (const name of ['cache', 'mongoClient', 'postgresClient', 'questdbClient']) {
|
|
expect(container.resolve(name)).toBeNull();
|
|
}
|
|
expect(container.resolve('handlerRegistry')).toBeDefined();
|
|
expect(container.resolve('handlerScanner')).toBeDefined();
|
|
expect(container.hasRegistration('serviceContainer')).toBe(true);
|
|
} finally {
|
|
await container.dispose();
|
|
}
|
|
});
|
|
|
|
it('uses flat database settings in preference to nested ones', async () => {
|
|
const config = {
|
|
...configuration(),
|
|
redis: { enabled: false, host: 'flat.test', port: 16379, db: 2 },
|
|
};
|
|
const container = await compose(config);
|
|
try {
|
|
expect(container.resolve('config').redis).toMatchObject(config.redis);
|
|
} finally {
|
|
await container.dispose();
|
|
}
|
|
});
|
|
|
|
it('keeps optional service defaults and honors disabled optional services', async () => {
|
|
const defaults = await compose();
|
|
try {
|
|
expect(defaults.resolve('config').queue).toMatchObject({
|
|
enabled: true,
|
|
workers: 1,
|
|
concurrency: 1,
|
|
});
|
|
expect(defaults.resolve('config').browser).toMatchObject({ headless: true, timeout: 30000 });
|
|
} finally {
|
|
await defaults.dispose();
|
|
}
|
|
const container = await new ServiceContainerBuilder()
|
|
.withConfig(configuration())
|
|
.withOptions({
|
|
enableQueue: false,
|
|
enableBrowser: false,
|
|
enableProxy: false,
|
|
enableQuestDB: false,
|
|
})
|
|
.skipInitialization()
|
|
.build();
|
|
try {
|
|
const config = container.resolve('config');
|
|
expect(config.queue).toBeUndefined();
|
|
expect(config.browser).toBeUndefined();
|
|
expect(config.proxy).toBeUndefined();
|
|
expect(config.questdb).toBeUndefined();
|
|
} finally {
|
|
await container.dispose();
|
|
}
|
|
});
|
|
|
|
it('uses the last complete configuration when the builder is reused', async () => {
|
|
const builder = new ServiceContainerBuilder().withConfig(configuration());
|
|
const next = { ...configuration(), service: { name: 'replacement', port: 3100 } };
|
|
const container = await builder.withConfig(next).skipInitialization().build();
|
|
try {
|
|
expect(container.resolve('config').service?.name).toBe('replacement');
|
|
} finally {
|
|
await container.dispose();
|
|
}
|
|
});
|
|
|
|
it('allows service-specific capability overrides via withRegistrations', async () => {
|
|
const fakeBrowser = { close: async () => {} } as never;
|
|
const container = await new ServiceContainerBuilder()
|
|
.withConfig(configuration())
|
|
.withRegistrations((diContainer, _cfg, { asValue }) => {
|
|
diContainer.register({ browser: asValue(fakeBrowser) });
|
|
})
|
|
.skipInitialization()
|
|
.build();
|
|
try {
|
|
expect(container.resolve('browser')).toBe(fakeBrowser);
|
|
expect(container.resolve('serviceContainer').browser).toBe(fakeBrowser);
|
|
} finally {
|
|
await container.dispose();
|
|
}
|
|
});
|
|
|
|
it('rejects invalid settings and missing required app fields with schema errors', () => {
|
|
expect(() =>
|
|
new ServiceContainerBuilder().withConfig({
|
|
...configuration(),
|
|
redis: { enabled: 'wrong' },
|
|
} as never)
|
|
).toThrow(ZodError);
|
|
expect(() =>
|
|
new ServiceContainerBuilder().withConfig({ service: { name: 'incomplete' } } as never)
|
|
).toThrow(ZodError);
|
|
});
|
|
});
|