Skip to content

Commit eaeef7d

Browse files
committed
refactor(core): align websocket runtime logger contract
1 parent 3ff5e91 commit eaeef7d

9 files changed

Lines changed: 35 additions & 24 deletions

ACTIVE_REFACTOR_PLAN.md

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,16 @@ Historical detail is archived elsewhere and should not be copied here.
4141
9. Do not run separate test-only cleanup campaigns.
4242

4343
## Latest Completed
44-
- 2026-05-28: completed `packages/core/src/interfaces/IRuntimeSources.ts runtime source contract consolidation follow-up`.
45-
- 2026-05-28: completed `packages/core/src/interfaces/ITradingBotServices.ts trading bot service contract consolidation follow-up`.
46-
- 2026-05-28: completed `packages/core/src/interfaces/IBotInitializerServices.ts initializer service contract consolidation follow-up`.
47-
- Canonical narrow runtime slices now live in the consumer-facing interface files, and `IRuntimeSources.ts` reuses them instead of repeating inline `Pick` contracts.
48-
- The initializer runtime contract now makes exchange, market-data, execution, session, and resilience ownership explicit while preserving adapter compatibility with the broader runtime source state.
49-
- Functional/source guardrails now pin the shared runtime contract layer, and related runtime-source tests now read exchange ownership from the top-level runtime source contract.
44+
- 2026-05-28: completed `packages/core/src/interfaces/IWebSocketEventHandlerServices.ts websocket handler contract consolidation follow-up`.
45+
- The websocket handler contract now follows the same ownership model as the other runtime slices by exposing `coreServices.logger` instead of a standalone logger field.
46+
- Adapter and functional guardrail coverage now pin the narrowed websocket runtime boundary so consumers keep reusing the shared core logger through the grouped contract.
5047

5148
## Latest Verification
52-
- 2026-05-28: `npm test -- --runInBand runtime-contracts.functional.test.ts runtime-service-adapters.functional.test.ts bot-initializer.test.ts services/bot-initializer.functional.test.ts bot-factory.test.ts services/bot-factory.service.test.ts services/bot-factory.error-handling.test.ts` (7 suites, 97 tests)
53-
- 2026-05-28: `npm test -- --runInBand position-monitor` (4 suites, 54 tests)
54-
- 2026-05-28: `npm run build`
49+
- 2026-05-28: `npm test -- --runInBand runtime-service-adapters.functional.test.ts services/websocket-event-handler.functional.test.ts` (2 suites, 7 tests)
5550

5651
## Next Step
5752
- Continue with the next active component from `REFACTOR_COMPONENT_CHECKLIST.md`.
58-
- Start with `packages/core/src/interfaces/IWebSocketEventHandlerServices.ts websocket handler contract consolidation follow-up`.
53+
- Start with `packages/core/src/factories/create-runtime-bundle.ts runtime bundle assembly boundary follow-up`.
5954
- Keep the next batch component-sized: each active item should be a real runtime/initializer/websocket boundary slice, not a single-line alias or naming-only task.
6055

6156
## Archive

NEXT_SESSION_PROMPT.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ Work directly on local `main`. Do not create worktrees. If the current branch is
1414

1515
## Current Batch
1616
Start with these three active queue items:
17-
1. `packages/core/src/interfaces/IWebSocketEventHandlerServices.ts websocket handler contract consolidation follow-up`
18-
2. `packages/core/src/factories/create-runtime-bundle.ts runtime bundle assembly boundary follow-up`
19-
3. `packages/core/src/bot-factory.ts runtime bundle handoff boundary follow-up`
17+
1. `packages/core/src/factories/create-runtime-bundle.ts runtime bundle assembly boundary follow-up`
18+
2. `packages/core/src/bot-factory.ts runtime bundle handoff boundary follow-up`
19+
3. `packages/core/src/factories/create-trading-bot-runtime.ts runtime factory boundary follow-up`
2020

2121
If one of these turns out to be too small, merge it with the next adjacent runtime,
2222
initializer, or websocket boundary item from `REFACTOR_COMPONENT_CHECKLIST.md` and keep
@@ -53,13 +53,12 @@ After all three slices are complete:
5353
5. Commit the batch after tests, smoke, build, and docs updates pass.
5454

5555
## Last Completed
56+
- 2026-05-28: completed `packages/core/src/interfaces/IWebSocketEventHandlerServices.ts websocket handler contract consolidation follow-up`.
5657
- 2026-05-28: completed `packages/core/src/interfaces/IRuntimeSources.ts runtime source contract consolidation follow-up`.
5758
- 2026-05-28: completed `packages/core/src/interfaces/ITradingBotServices.ts trading bot service contract consolidation follow-up`.
5859
- 2026-05-28: completed `packages/core/src/interfaces/IBotInitializerServices.ts initializer service contract consolidation follow-up`.
60+
- The websocket runtime contract now reuses `coreServices.logger` instead of flattening logger ownership, keeping the grouped runtime boundary consistent across TradingBot, BotInitializer, and WebSocketEventHandlerManager.
5961
- Canonical narrow runtime slices now live in the consumer-facing interface files, and `IRuntimeSources.ts` now reuses them instead of repeating inline runtime `Pick` contracts.
60-
- Adapter compatibility remains intact for the broader bot factory runtime source while initializer/runtime tests now read exchange ownership from the top-level runtime source contract.
6162

6263
## Last Verification
63-
- `npm test -- --runInBand runtime-contracts.functional.test.ts runtime-service-adapters.functional.test.ts bot-initializer.test.ts services/bot-initializer.functional.test.ts bot-factory.test.ts services/bot-factory.service.test.ts services/bot-factory.error-handling.test.ts`
64-
- `npm test -- --runInBand position-monitor`
65-
- `npm run build`
64+
- `npm test -- --runInBand runtime-service-adapters.functional.test.ts services/websocket-event-handler.functional.test.ts`

REFACTOR_COMPONENT_CHECKLIST.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ Legend:
1515
- `func` = functional test exists
1616

1717
## Active Components
18-
- [ ] `packages/core/src/interfaces/IWebSocketEventHandlerServices.ts websocket handler contract consolidation follow-up`
1918
- [ ] `packages/core/src/factories/create-runtime-bundle.ts runtime bundle assembly boundary follow-up`
2019
- [ ] `packages/core/src/bot-factory.ts runtime bundle handoff boundary follow-up`
2120
- [ ] `packages/core/src/factories/create-trading-bot-runtime.ts runtime factory boundary follow-up`

REFACTOR_COMPONENT_CHECKLIST_ARCHIVE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Archived completed items moved out of REFACTOR_COMPONENT_CHECKLIST.md to keep the active queue short.
44

55
## Completed History
6+
- [x] `packages/core/src/interfaces/IWebSocketEventHandlerServices.ts websocket handler contract consolidation follow-up` | prod: yes | tests: yes | func: yes
67
- [x] `packages/core/src/interfaces/IRuntimeSources.ts runtime source contract consolidation follow-up` | prod: yes | tests: yes | func: yes
78
- [x] `packages/core/src/interfaces/ITradingBotServices.ts trading bot service contract consolidation follow-up` | prod: yes | tests: yes | func: yes
89
- [x] `packages/core/src/interfaces/IBotInitializerServices.ts initializer service contract consolidation follow-up` | prod: yes | tests: yes | func: yes

packages/core/src/__tests__/runtime-service-adapters.functional.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,13 @@ describe('runtime dependency adapter boundary', () => {
8080
expect(initializerServices.monitoringServices).not.toBe(services.monitoringServices);
8181
expect('bybitService' in initializerServices.marketDataServices).toBe(false);
8282

83+
expect(eventHandlerServices.coreServices.logger).toBe(services.coreServices.logger);
8384
expect(eventHandlerServices.marketDataServices.publicWebSocket).toBe(services.marketDataServices.publicWebSocket);
8485
expect(eventHandlerServices.executionServices.positionMonitor).toBe(services.executionServices.positionMonitor);
86+
expect(eventHandlerServices.coreServices).not.toBe(services.coreServices);
8587
expect(eventHandlerServices.marketDataServices).not.toBe(services.marketDataServices);
8688
expect(eventHandlerServices.executionServices).not.toBe(services.executionServices);
89+
expect('logger' in eventHandlerServices).toBe(false);
8790
expect('bybitService' in eventHandlerServices.marketDataServices).toBe(false);
8891
expect('positionExitingService' in eventHandlerServices.executionServices).toBe(false);
8992
expect('orderStateMachine' in eventHandlerServices.executionServices).toBe(false);

packages/core/src/__tests__/services/websocket-event-handler.functional.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,16 @@ describe('WebSocketEventHandlerManager functional boundary', () => {
6060
expect(stopLossSpy).toHaveBeenCalledTimes(1);
6161
expect(positionUpdateSpy).toHaveBeenCalledTimes(1);
6262
});
63+
64+
test('reuses the shared core logger through the websocket boundary contract', () => {
65+
const { config, services } = createInitializerHarness();
66+
const runtimeDependencies = createTradingBotRuntimeDependencies(services);
67+
const manager = new WebSocketEventHandlerManager(runtimeDependencies.eventHandlerServices, config);
68+
69+
expect(runtimeDependencies.eventHandlerServices.coreServices.logger).toBe(
70+
services.coreServices.logger,
71+
);
72+
expect('logger' in runtimeDependencies.eventHandlerServices).toBe(false);
73+
expect(manager).toBeInstanceOf(WebSocketEventHandlerManager);
74+
});
6375
});

packages/core/src/interfaces/IWebSocketEventHandlerServices.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type { ImbalanceAnalysis } from '../types/legacy';
1010
import type { IMarketDataServices } from './IMarketDataServices';
1111
import type { IExecutionServices } from './IExecutionServices';
1212
import type { IEventHandlerServices } from './IEventHandlerServices';
13-
import type { LoggerService } from '../services/logger.service';
13+
import type { ICoreServices } from './ICoreServices';
1414

1515
export type IWebSocketEventHandlerExecutionServices = Pick<
1616
IExecutionServices,
@@ -23,7 +23,7 @@ export type IWebSocketEventHandlerMarketDataServices = Pick<
2323
>;
2424

2525
export interface IWebSocketEventHandlerServices {
26-
logger: LoggerService;
26+
coreServices: Pick<ICoreServices, 'logger'>;
2727
eventHandlerServices: IEventHandlerServices;
2828
executionServices: IWebSocketEventHandlerExecutionServices;
2929
marketDataServices: IWebSocketEventHandlerMarketDataServices;

packages/core/src/services/runtime-service-adapters.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ export const createBotInitializerServices = (
136136
export const createWebSocketEventHandlerServices = (
137137
runtimeSource: IWebSocketEventHandlerRuntimeSource,
138138
): IWebSocketEventHandlerServices => ({
139-
logger: runtimeSource.coreServices.logger,
139+
coreServices: {
140+
logger: runtimeSource.coreServices.logger,
141+
},
140142
eventHandlerServices: runtimeSource.eventHandlerServices,
141143
executionServices: createWebSocketEventHandlerExecutionServices(runtimeSource),
142144
marketDataServices: createWebSocketEventHandlerMarketDataServices(runtimeSource),

packages/core/src/services/websocket-event-handler-manager.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import { ICONS } from '../cli/cli-runtime';
3434
* keeping the bot class focused on orchestration.
3535
*/
3636
export class WebSocketEventHandlerManager {
37-
private logger: IWebSocketEventHandlerServices['logger'];
37+
private logger: IWebSocketEventHandlerServices['coreServices']['logger'];
3838
private lastOrderbookAnalysis: number = 0;
3939
private whaleDetector: RealTimeWhaleDetector;
4040

@@ -46,9 +46,9 @@ export class WebSocketEventHandlerManager {
4646
}> = [];
4747

4848
constructor(private services: IWebSocketEventHandlerServices, private config: Config) {
49-
this.logger = services.logger;
49+
this.logger = services.coreServices.logger;
5050
this.whaleDetector = new RealTimeWhaleDetector({
51-
logger: services.logger,
51+
logger: services.coreServices.logger,
5252
tradingOrchestrator: services.executionServices.tradingOrchestrator,
5353
}, config);
5454
}

0 commit comments

Comments
 (0)