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
9 changes: 6 additions & 3 deletions src/cli/dispatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { restoreNativeCodexAsync } from "../codex/inject";
import { stripGrokConfig } from "../grok/inject";
import { afterCatalogWriteHandleAppServers } from "../codex/app-server-processes";
import { normalizeUpdateChannel, runGuiUpdateWorker } from "../update/job";
import { serviceCommand } from "../service";

export interface CliDispatchDeps {
args: string[];
Expand All @@ -45,6 +44,7 @@ export interface CliDispatchDeps {
handleStatus: () => Promise<void>;
handleRecoverHistory: () => Promise<void>;
handleReady: (args: ReadyArgs) => Promise<number>;
serviceCommand: (...args: string[]) => Promise<void>;
}

type CommandRunner = (deps: CliDispatchDeps) => Promise<number>;
Expand Down Expand Up @@ -261,8 +261,11 @@ const commandRunners: Record<string, CommandRunner> = {
return 0;
},
service: async deps => {
await serviceCommand(...deps.args.slice(1));
return 0;
process.exitCode = 0;
await deps.serviceCommand(...deps.args.slice(1));
// serviceCommand uses process.exitCode for recoverable install/stop failures
// that must finish cleanup before the single top-level process.exit runs.
return Number(process.exitCode ?? 0);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
},
tray: async deps => {
const { windowsTrayCommand } = await import("../tray/windows");
Expand Down
1 change: 1 addition & 0 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -941,4 +941,5 @@ process.exit(await dispatchCommand(head, {
handleStatus,
handleRecoverHistory,
handleReady,
serviceCommand,
}));
41 changes: 41 additions & 0 deletions tests/cli-dispatch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,45 @@ describe("dispatchCommand exit codes", () => {
expect(await dispatchCommand(head, fakeDeps), `${name} must be unknown`).toBe(1);
}
});

test("forwards service arguments and preserves handler exit codes", async () => {
const previousExitCode = process.exitCode;
try {
process.exitCode = 7;
const successCalls: string[][] = [];
const successDeps = {
...fakeDeps,
args: ["service", "install", "--scheduler"],
serviceCommand: async (...args: string[]) => {
successCalls.push(args);
},
};

expect(await dispatchCommand(
{ kind: "command", command: "service", args: successDeps.args },
successDeps,
)).toBe(0);
expect(successCalls).toEqual([["install", "--scheduler"]]);

for (const expected of [1, 2]) {
const calls: string[][] = [];
const deps = {
...fakeDeps,
args: ["service", "install", "--scheduler"],
serviceCommand: async (...args: string[]) => {
calls.push(args);
process.exitCode = expected;
},
};

expect(await dispatchCommand(
{ kind: "command", command: "service", args: deps.args },
deps,
)).toBe(expected);
expect(calls).toEqual([["install", "--scheduler"]]);
}
} finally {
process.exitCode = previousExitCode ?? 0;
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
});
});
Loading