Skip to content
Closed
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
6 changes: 3 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,8 @@ const commandRunners: Record<string, CommandRunner> = {
return 0;
},
service: async deps => {
await serviceCommand(...deps.args.slice(1));
return 0;
await deps.serviceCommand(...deps.args.slice(1));
return Number(process.exitCode ?? 0);
},
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,
}));
21 changes: 21 additions & 0 deletions tests/cli-dispatch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,25 @@ describe("dispatchCommand exit codes", () => {
expect(await dispatchCommand(head, fakeDeps), `${name} must be unknown`).toBe(1);
}
});

test("preserves a failure exit code set by the service command", async () => {
const previousExitCode = process.exitCode;
try {
process.exitCode = undefined;
const deps = {
...fakeDeps,
args: ["service", "start"],
serviceCommand: async () => {
process.exitCode = 1;
},
};

expect(await dispatchCommand(
{ kind: "command", command: "service", args: deps.args },
deps,
)).toBe(1);
} finally {
process.exitCode = previousExitCode;
}
});
});
Loading