fix(cli): exit with non-zero code when configure/agents-add wizards are cancelled (#14156)

* fix(cli): exit with non-zero code when configure/agents-add wizards are cancelled

Follow-up to the onboard cancel fix. The configure wizard and
agents add wizard also caught WizardCancelledError and exited with
code 0, which signals success to callers. Change to exit(1) for
consistency — user cancellation is not a successful completion.

This ensures scripts that chain these commands with set -e will
correctly stop when the user cancels.

* fix(cli): make wizard cancellations exit non-zero (#14156) (thanks @0xRaini)

---------

Co-authored-by: Rain <rain@Rains-MBA-M4.local>
Co-authored-by: Sebastian <19554889+sebslight@users.noreply.github.com>
This commit is contained in:
0xRain
2026-02-12 02:07:30 +08:00
committed by GitHub
parent 6758b6bfe4
commit 93411b74a0
7 changed files with 116 additions and 3 deletions

View File

@@ -6,6 +6,10 @@ const configMocks = vi.hoisted(() => ({
writeConfigFile: vi.fn().mockResolvedValue(undefined),
}));
const wizardMocks = vi.hoisted(() => ({
createClackPrompter: vi.fn(),
}));
vi.mock("../config/config.js", async (importOriginal) => {
const actual = await importOriginal<typeof import("../config/config.js")>();
return {
@@ -15,6 +19,11 @@ vi.mock("../config/config.js", async (importOriginal) => {
};
});
vi.mock("../wizard/clack-prompter.js", () => ({
createClackPrompter: wizardMocks.createClackPrompter,
}));
import { WizardCancelledError } from "../wizard/prompts.js";
import { agentsAddCommand } from "./agents.js";
const runtime: RuntimeEnv = {
@@ -38,6 +47,7 @@ describe("agents add command", () => {
beforeEach(() => {
configMocks.readConfigFileSnapshot.mockReset();
configMocks.writeConfigFile.mockClear();
wizardMocks.createClackPrompter.mockReset();
runtime.log.mockClear();
runtime.error.mockClear();
runtime.exit.mockClear();
@@ -64,4 +74,20 @@ describe("agents add command", () => {
expect(runtime.exit).toHaveBeenCalledWith(1);
expect(configMocks.writeConfigFile).not.toHaveBeenCalled();
});
it("exits with code 1 when the interactive wizard is cancelled", async () => {
configMocks.readConfigFileSnapshot.mockResolvedValue({ ...baseSnapshot });
wizardMocks.createClackPrompter.mockReturnValue({
intro: vi.fn().mockRejectedValue(new WizardCancelledError()),
text: vi.fn(),
confirm: vi.fn(),
note: vi.fn(),
outro: vi.fn(),
});
await agentsAddCommand({}, runtime);
expect(runtime.exit).toHaveBeenCalledWith(1);
expect(configMocks.writeConfigFile).not.toHaveBeenCalled();
});
});