Files
openclaw/src/cli/program.smoke.test.ts
Peter Steinberger 96f0983a85 fix(onboarding): skip setup for configured gateways and require inference first (#102883)
* fix(crestodian): keep onboarding RPCs restart-safe

* fix(profiles): isolate approval state migrations

* fix(crestodian): bypass configured gateway setup

* test(crestodian): type onboarding mocks

* fix(onboarding): require inference before Crestodian

* fix(onboarding): enforce verified inference handoff

* fix(macos): reset setup on gateway endpoint edits

* chore(i18n): refresh native source inventory

* fix(gateway): keep socket on request cancellation

* test(packaging): require workspace templates

* fix(onboarding): bind setup to verified inference

* fix(onboarding): align inference gate contracts

* fix(crestodian): classify concurrent policy rejection

* test(crestodian): expect registry restoration

* fix(onboarding): bind setup to configured gateways

* fix(codex): preserve startup phase deadlines

* test(crestodian): match fail-closed policy ordering

* test(onboarding): assert bound gateway handoff

* fix(codex): bind runtime resolution to spawn cwd

* test(crestodian): assert policy rejection order

* fix(cli): preserve gateway routing across restarts

* fix(macos): fail closed during gateway edits

* test(macos): cover gateway route generation races

* chore: keep release notes out of onboarding PR

* fix(ci): refresh onboarding generated checks

* style(swift): align gateway channel formatting

* fix(ci): refresh plugin SDK surface budgets

* fix(ci): resync native string inventory

* refactor(swift): split gateway channel support

* test(doctor): isolate plugin compatibility registry

* test(macos): isolate gateway onboarding fixtures

* test(macos): assert gateway lease health ordering

* fix(codex): reconcile computer-use startup changes
2026-07-11 10:25:14 -07:00

102 lines
3.2 KiB
TypeScript

// Program smoke tests cover core CLI command registration and startup behavior.
import { beforeEach, describe, expect, it, vi } from "vitest";
import { buildProgram } from "./program.js";
import {
configureCommand,
ensureConfigReady,
runCrestodianWithInference,
runTui,
runtime,
setupCommand,
setupWizardCommand,
} from "./program.test-mocks.js";
vi.mock("./config-cli.js", () => ({
registerConfigCli: (program: {
command: (name: string) => { action: (fn: () => unknown) => void };
}) => {
program.command("config").action(() => configureCommand({}, runtime));
},
runConfigGet: vi.fn(),
runConfigUnset: vi.fn(),
}));
describe("cli program (smoke)", () => {
let program = createProgram();
function createProgram() {
return buildProgram();
}
async function runProgram(argv: string[]) {
await program.parseAsync(argv, { from: "user" });
}
function firstMockArg(mock: { mock: { calls: ReadonlyArray<ReadonlyArray<unknown>> } }): unknown {
const call = mock.mock.calls[0];
if (!call) {
throw new Error("expected mock to have at least one call");
}
return call[0];
}
beforeEach(() => {
program = createProgram();
vi.clearAllMocks();
runTui.mockResolvedValue(undefined);
runCrestodianWithInference.mockResolvedValue(undefined);
ensureConfigReady.mockResolvedValue(undefined);
});
it("registers message + status commands", () => {
const names = program.commands.map((command) => command.name());
expect(names).toContain("message");
expect(names).toContain("status");
});
it("runs tui with explicit timeout override", async () => {
await runProgram(["tui", "--timeout-ms", "45000"]);
const options = firstMockArg(runTui) as {
timeoutMs?: number;
forceProcessExitOnReturn?: boolean;
};
expect(options?.timeoutMs).toBe(45000);
expect(options?.forceProcessExitOnReturn).toBe(true);
});
it("runs crestodian one-shot requests", async () => {
await runProgram(["crestodian", "--message", "status"]);
const options = firstMockArg(runCrestodianWithInference) as {
message?: string;
yes?: boolean;
json?: boolean;
};
expect(options?.message).toBe("status");
expect(options?.yes).toBe(false);
expect(options?.json).toBe(false);
expect(runCrestodianWithInference).toHaveBeenCalledWith(options, runtime);
});
it("warns and ignores invalid tui timeout override", async () => {
await runProgram(["tui", "--timeout-ms", "nope"]);
expect(runtime.error).toHaveBeenCalledWith('warning: invalid --timeout-ms "nope"; ignoring');
const options = firstMockArg(runTui) as { timeoutMs?: number };
expect(options?.timeoutMs).toBeUndefined();
});
it("rejects partial tui history limits", async () => {
await expect(runProgram(["tui", "--history-limit", "10x"])).rejects.toThrow("exit");
expect(runtime.error).toHaveBeenCalledWith(
"Error: --history-limit must be a positive integer.",
);
expect(runTui).not.toHaveBeenCalled();
});
it("runs setup wizard when wizard flags are present", async () => {
await runProgram(["setup", "--remote-url", "ws://example"]);
expect(setupCommand).not.toHaveBeenCalled();
expect(setupWizardCommand).toHaveBeenCalledTimes(1);
});
});