Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions tests/unit/infrastructure/di/container.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ describe('createContainer', () => {
assert.ok(cradle.contextService);
assert.ok(cradle.liberateService);
assert.ok(cradle.sessionCaptureService);
assert.ok(cradle.memoryContextLoader);
assert.ok(cradle.contextFormatter);
});

it('should return singletons within container scope', () => {
Expand Down Expand Up @@ -160,6 +162,17 @@ describe('createContainer', () => {
});
});

describe('hook services', () => {
it('should resolve hook services with expected interfaces', () => {
const container = createContainer();
const { memoryContextLoader, contextFormatter, sessionCaptureService } = container.cradle;

assert.equal(typeof memoryContextLoader.load, 'function');
assert.equal(typeof contextFormatter.format, 'function');
assert.equal(typeof sessionCaptureService.capture, 'function');
Comment on lines +170 to +172
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assertion pattern here is inconsistent with the existing pattern in this file. On lines 141-143, the eventBus tests use assert.ok(typeof x === 'function') to check for function types. For consistency, these assertions should follow the same pattern.

Suggested change
assert.equal(typeof memoryContextLoader.load, 'function');
assert.equal(typeof contextFormatter.format, 'function');
assert.equal(typeof sessionCaptureService.capture, 'function');
assert.ok(typeof memoryContextLoader.load === 'function');
assert.ok(typeof contextFormatter.format === 'function');
assert.ok(typeof sessionCaptureService.capture === 'function');

Copilot uses AI. Check for mistakes.
});
});

describe('service wiring', () => {
it('should wire memoryService to use correct repository', () => {
const container = createContainer();
Expand Down
39 changes: 39 additions & 0 deletions tests/unit/infrastructure/events/EventBus.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { EventBus } from '../../../../src/infrastructure/events/EventBus';
import type { HookEvent } from '../../../../src/domain/events/HookEvents';
import type { IEventHandler } from '../../../../src/domain/interfaces/IEventHandler';
import type { IEventResult } from '../../../../src/domain/interfaces/IEventResult';
import type { ILogger } from '../../../../src/domain/interfaces/ILogger';

function createSessionStartEvent(overrides?: Partial<HookEvent>): HookEvent {
return {
Expand Down Expand Up @@ -131,6 +132,44 @@ describe('EventBus', () => {

assert.deepEqual(results, []);
});

it('should log warning when handler fails', async () => {
const warnCalls: { message: string; context?: Record<string, unknown> }[] = [];
const mockLogger: ILogger = {
trace: () => {},
debug: () => {},
info: () => {},
warn: (message: string, context?: Record<string, unknown>) => {
warnCalls.push({ message, context });
},
error: () => {},
fatal: () => {},
child: () => mockLogger,
isLevelEnabled: () => true,
};

const bus = new EventBus(mockLogger);
bus.on('session:start', createFailingHandler('BrokenHandler', new Error('oops')));

await bus.emit(createSessionStartEvent());

assert.equal(warnCalls.length, 1);
assert.equal(warnCalls[0].message, 'Event handler failed');
assert.equal(warnCalls[0].context?.event, 'session:start');
assert.equal(warnCalls[0].context?.handler, 'BrokenHandler');
assert.equal(warnCalls[0].context?.error, 'oops');
});

it('should not crash without logger when handler fails', async () => {
const bus = new EventBus(); // no logger
bus.on('session:start', createFailingHandler('NoLogHandler', new Error('fail')));

const results = await bus.emit(createSessionStartEvent());

assert.equal(results.length, 1);
assert.equal(results[0].success, false);
assert.equal(results[0].handler, 'NoLogHandler');
});
});

describe('on', () => {
Expand Down
Loading