Skip to content
Draft
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ coverage/
.claude/settings.local.json
localdocs/
execplan/
.worktrees/

# Generated npm bundle output (local)
cli/npm/main/
Expand Down
22 changes: 20 additions & 2 deletions cli/src/codex/codexRemoteLauncher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import type { EnhancedMode } from './loop';
const harness = vi.hoisted(() => ({
notifications: [] as Array<{ method: string; params: unknown }>,
registerRequestCalls: [] as string[],
initializeCalls: [] as unknown[]
initializeCalls: [] as unknown[],
turnCompletion: { status: 'Completed' } as { status: string; message?: string }
}));

vi.mock('./codexAppServerClient', () => {
Expand Down Expand Up @@ -40,7 +41,7 @@ vi.mock('./codexAppServerClient', () => {
harness.notifications.push({ method: 'turn/started', params: started });
this.notificationHandler?.('turn/started', started);

const completed = { status: 'Completed', turn: {} };
const completed = { ...harness.turnCompletion, turn: {} };
harness.notifications.push({ method: 'turn/completed', params: completed });
this.notificationHandler?.('turn/completed', completed);

Expand Down Expand Up @@ -168,6 +169,7 @@ describe('codexRemoteLauncher', () => {
harness.notifications = [];
harness.registerRequestCalls = [];
harness.initializeCalls = [];
harness.turnCompletion = { status: 'Completed' };
});

it('finishes a turn and emits ready when task lifecycle events omit turn_id', async () => {
Expand Down Expand Up @@ -198,4 +200,20 @@ describe('codexRemoteLauncher', () => {
expect(thinkingChanges).toContain(true);
expect(session.thinking).toBe(false);
});

it('persists failed terminal events so the hub can notify for attention', async () => {
harness.turnCompletion = { status: 'Failed', message: 'boom' };
const {
session,
codexMessages
} = createSessionStub();

const exitReason = await codexRemoteLauncher(session as never);

expect(exitReason).toBe('exit');
expect(codexMessages).toContainEqual(expect.objectContaining({
type: 'task_failed',
error: 'boom'
}));
});
});
4 changes: 4 additions & 0 deletions cli/src/codex/codexRemoteLauncher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ class CodexRemoteLauncher extends RemoteLauncherBase {
allowAnonymousTerminalEvent = false;
}

if (msgType === 'turn_aborted' || msgType === 'task_failed') {
session.sendAgentMessage(msg);
}

if (msgType === 'agent_message') {
const message = asString(msg.message);
if (message) {
Expand Down
10 changes: 7 additions & 3 deletions cli/src/utils/spawnHappyCLI.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { beforeAll, afterAll, beforeEach, describe, expect, it, vi } from 'vitest';
import type { SpawnOptions } from 'child_process';
import { join } from 'node:path';
import { projectPath } from '@/projectPath';

const spawnMock = vi.fn((..._args: any[]) => ({ pid: 12345 } as any));

Expand Down Expand Up @@ -100,14 +102,16 @@ describe('spawnHappyCLI windowsHide behavior', () => {

const command = getHappyCliCommand(['mcp', '--url', 'http://127.0.0.1:1234/']);
const isBunRuntime = Boolean((process.versions as Record<string, string | undefined>).bun);
const expectedProjectRoot = projectPath().replace(/\\/g, '/');
const expectedEntrypoint = join(projectPath(), 'src', 'index.ts').replace(/\\/g, '/');

expect(command.command).toBe(process.execPath);
if (isBunRuntime) {
expect(command.args[0]).toBe('--cwd');
expect(command.args[1].replace(/\\/g, '/')).toMatch(/\/hapi\/cli$/);
expect(command.args[2].replace(/\\/g, '/')).toMatch(/\/hapi\/cli\/src\/index\.ts$/);
expect(command.args[1].replace(/\\/g, '/')).toBe(expectedProjectRoot);
expect(command.args[2].replace(/\\/g, '/')).toBe(expectedEntrypoint);
} else {
expect(command.args.some((arg) => arg.replace(/\\/g, '/').endsWith('/hapi/cli/src/index.ts'))).toBe(true);
expect(command.args.map((arg) => arg.replace(/\\/g, '/'))).toContain(expectedEntrypoint);
}
});

Expand Down
Loading
Loading