Files
openclaw/src/commands/onboard-interactive.test.ts
0xRain 93411b74a0 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>
2026-02-11 13:07:30 -05:00

62 lines
1.8 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from "vitest";
import type { RuntimeEnv } from "../runtime.js";
const mocks = vi.hoisted(() => ({
createClackPrompter: vi.fn(),
runOnboardingWizard: vi.fn(),
restoreTerminalState: vi.fn(),
}));
vi.mock("../wizard/clack-prompter.js", () => ({
createClackPrompter: mocks.createClackPrompter,
}));
vi.mock("../wizard/onboarding.js", () => ({
runOnboardingWizard: mocks.runOnboardingWizard,
}));
vi.mock("../terminal/restore.js", () => ({
restoreTerminalState: mocks.restoreTerminalState,
}));
import { WizardCancelledError } from "../wizard/prompts.js";
import { runInteractiveOnboarding } from "./onboard-interactive.js";
const runtime: RuntimeEnv = {
log: vi.fn(),
error: vi.fn(),
exit: vi.fn(),
};
describe("runInteractiveOnboarding", () => {
beforeEach(() => {
mocks.createClackPrompter.mockReset();
mocks.runOnboardingWizard.mockReset();
mocks.restoreTerminalState.mockReset();
runtime.log.mockClear();
runtime.error.mockClear();
runtime.exit.mockClear();
mocks.createClackPrompter.mockReturnValue({});
});
it("exits with code 1 when the wizard is cancelled", async () => {
mocks.runOnboardingWizard.mockRejectedValue(new WizardCancelledError());
await runInteractiveOnboarding({} as never, runtime);
expect(runtime.exit).toHaveBeenCalledWith(1);
expect(mocks.restoreTerminalState).toHaveBeenCalledWith("onboarding finish");
});
it("rethrows non-cancel errors", async () => {
const err = new Error("boom");
mocks.runOnboardingWizard.mockRejectedValue(err);
await expect(runInteractiveOnboarding({} as never, runtime)).rejects.toThrow("boom");
expect(runtime.exit).not.toHaveBeenCalled();
expect(mocks.restoreTerminalState).toHaveBeenCalledWith("onboarding finish");
});
});