Files
paseo/packages/cli/src/utils/command-options.test.ts
T
Mohamed Boudra a835136854 Let CLI host selection work globally (#4238)
* feat(cli): accept host as a global option

Keep the command-local position for compatibility while letting users place one daemon target before the command and reuse it while changing verbs. Local daemon lifecycle commands continue to operate locally.

* fix(cli): preserve project host resolution boundary

Project creation already handled PASEO_HOST directly. Avoid routing that established behavior through a newly exported client helper so its isolated command tests keep their existing dependency boundary.

* test(cli): allow scaffold typecheck under CI load

* test(cli): provide remote cwd in schedule e2e

* docs(cli): teach only global host syntax
2026-09-02 22:53:55 +02:00

46 lines
1.5 KiB
TypeScript

import { Command } from "commander";
import { describe, expect, it } from "vitest";
import { addDaemonHostOption, withGlobalOptions } from "./command-options.js";
async function parseHost(argv: string[]): Promise<string | undefined> {
const program = new Command().exitOverride().option("--host <host>");
let receivedHost: string | undefined;
addDaemonHostOption(program.command("ls")).action(
withGlobalOptions((options: { host?: string }) => {
receivedHost = options.host;
}),
);
await program.parseAsync(argv, { from: "user" });
return receivedHost;
}
describe("global command options", () => {
it("passes a host declared before the command to its handler", async () => {
await expect(parseHost(["--host", "global:6767", "ls"])).resolves.toBe("global:6767");
});
it("preserves the command-local host position", async () => {
await expect(parseHost(["ls", "--host", "local:6767"])).resolves.toBe("local:6767");
});
it("uses the last explicit host", async () => {
await expect(parseHost(["--host", "first:6767", "ls", "--host", "last:6767"])).resolves.toBe(
"last:6767",
);
});
it("lets local-only commands ignore a global host", async () => {
const program = new Command().exitOverride().option("--host <host>");
let called = false;
program.command("status").action(() => {
called = true;
});
await program.parseAsync(["--host", "ignored:6767", "status"], { from: "user" });
expect(called).toBe(true);
});
});