File size: 1,533 Bytes
bc575bc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | import { describe, expect, test, vi } from "vitest";
import { cli } from "../src/cli/experimental/cli.ts";
describe("experimental CLI command composition", () => {
test("requires an experimental subcommand", () => {
expect(cli.parse([])).toEqual({
ok: false,
errors: ["Expected experimental command: server or client"],
});
});
test("passes server options to the command action", async () => {
const runServer = vi.fn(() => undefined);
const result = await cli.execute(
[
"server",
"--server-id",
"00000000-0000-4000-8000-000000000001",
"--session-dir",
"./sessions",
"--provider",
"anthropic",
"--model",
"claude-sonnet-4-5",
],
{ runServer, runClient: vi.fn(() => undefined) },
);
const command = {
command: "server" as const,
serverId: "00000000-0000-4000-8000-000000000001",
sessionDir: "./sessions",
provider: "anthropic",
model: "claude-sonnet-4-5",
};
expect(result).toEqual({ ok: true, command });
expect(runServer).toHaveBeenCalledWith(command);
});
test.each(["server", "client"] as const)("executes the parsed %s command", async (name) => {
const context = {
runServer: vi.fn(() => undefined),
runClient: vi.fn(() => undefined),
};
const result = await cli.execute([name], context);
expect(result).toEqual({ ok: true, command: { command: name } });
expect(context.runServer).toHaveBeenCalledTimes(name === "server" ? 1 : 0);
expect(context.runClient).toHaveBeenCalledTimes(name === "client" ? 1 : 0);
});
});
|