- 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
171 lines
4.5 KiB
TypeScript
171 lines
4.5 KiB
TypeScript
import { asClass, asFunction, asValue, createContainer, InjectionMode } from 'awilix';
|
|
import { beforeEach, describe, expect, it, mock } from 'bun:test';
|
|
import { ServiceContainerBuilder } from '../src/container/builder';
|
|
import { HandlerScanner } from '../src/scanner/handler-scanner';
|
|
import { ServiceApplication } from '../src/service-application';
|
|
|
|
describe('Dependency Injection', () => {
|
|
describe('ServiceContainerBuilder', () => {
|
|
let builder: ServiceContainerBuilder;
|
|
|
|
beforeEach(() => {
|
|
builder = new ServiceContainerBuilder();
|
|
});
|
|
|
|
it('should create container with default configuration', async () => {
|
|
const config = {
|
|
name: 'test-service',
|
|
version: '1.0.0',
|
|
database: {
|
|
mongodb: { enabled: false, uri: 'mongodb://localhost/test', database: 'test' },
|
|
},
|
|
service: {
|
|
name: 'test-service',
|
|
type: 'WORKER' as const,
|
|
serviceName: 'test-service',
|
|
port: 3000,
|
|
},
|
|
log: {
|
|
level: 'info',
|
|
format: 'json',
|
|
},
|
|
};
|
|
|
|
builder.withConfig(config);
|
|
builder.skipInitialization(); // Skip initialization for testing
|
|
|
|
const container = await builder.build();
|
|
expect(container).toBeDefined();
|
|
});
|
|
|
|
it('should configure services', async () => {
|
|
const config = {
|
|
name: 'test-service',
|
|
version: '1.0.0',
|
|
database: {
|
|
mongodb: { enabled: false, uri: 'mongodb://localhost/test', database: 'test' },
|
|
},
|
|
service: {
|
|
name: 'test-service',
|
|
type: 'WORKER' as const,
|
|
serviceName: 'test-service',
|
|
port: 3000,
|
|
},
|
|
log: {
|
|
level: 'info',
|
|
format: 'json',
|
|
},
|
|
};
|
|
|
|
builder
|
|
.withConfig(config)
|
|
.withOptions({
|
|
enableCache: true,
|
|
enableQueue: false,
|
|
})
|
|
.skipInitialization();
|
|
|
|
const container = await builder.build();
|
|
expect(container).toBeDefined();
|
|
});
|
|
});
|
|
|
|
describe('Basic Container Operations', () => {
|
|
it('should register and resolve values', () => {
|
|
const container = createContainer({
|
|
injectionMode: InjectionMode.PROXY,
|
|
});
|
|
|
|
container.register({
|
|
testValue: asValue('test'),
|
|
});
|
|
|
|
expect(container.resolve('testValue')).toBe('test');
|
|
});
|
|
|
|
it('should register and resolve classes', () => {
|
|
class TestClass {
|
|
getValue() {
|
|
return 'test';
|
|
}
|
|
}
|
|
|
|
const container = createContainer({
|
|
injectionMode: InjectionMode.PROXY,
|
|
});
|
|
|
|
container.register({
|
|
testClass: asClass(TestClass),
|
|
});
|
|
|
|
const instance = container.resolve('testClass');
|
|
expect(instance).toBeInstanceOf(TestClass);
|
|
expect(instance.getValue()).toBe('test');
|
|
});
|
|
|
|
it('should handle dependencies', () => {
|
|
const container = createContainer({
|
|
injectionMode: InjectionMode.PROXY,
|
|
});
|
|
|
|
// Test with scoped container
|
|
container.register({
|
|
config: asValue({ host: 'localhost', port: 5432 }),
|
|
connection: asFunction(() => {
|
|
const config = container.resolve('config');
|
|
return `postgresql://${config.host}:${config.port}/mydb`;
|
|
}).scoped(),
|
|
});
|
|
|
|
const connection = container.resolve('connection');
|
|
expect(connection).toBe('postgresql://localhost:5432/mydb');
|
|
});
|
|
});
|
|
|
|
describe('HandlerScanner', () => {
|
|
it('should create scanner instance', () => {
|
|
const mockRegistry = {
|
|
register: mock(() => {}),
|
|
getHandlers: mock(() => []),
|
|
};
|
|
|
|
const mockContainer = createContainer({
|
|
injectionMode: InjectionMode.PROXY,
|
|
});
|
|
|
|
const scanner = new HandlerScanner(mockRegistry as any, mockContainer);
|
|
|
|
expect(scanner).toBeDefined();
|
|
expect(scanner.scanHandlers).toBeDefined();
|
|
});
|
|
});
|
|
|
|
describe('ServiceApplication', () => {
|
|
it('should create service application', () => {
|
|
const mockConfig = {
|
|
name: 'test-service',
|
|
version: '1.0.0',
|
|
service: {
|
|
name: 'test-service',
|
|
type: 'WORKER' as const,
|
|
serviceName: 'test-service',
|
|
port: 3000,
|
|
},
|
|
log: {
|
|
level: 'info',
|
|
format: 'json',
|
|
},
|
|
};
|
|
|
|
const serviceConfig = {
|
|
serviceName: 'test-service',
|
|
};
|
|
|
|
const app = new ServiceApplication(mockConfig, serviceConfig);
|
|
|
|
expect(app).toBeDefined();
|
|
expect(app.start).toBeDefined();
|
|
expect(app.stop).toBeDefined();
|
|
});
|
|
});
|
|
});
|