Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions tests/cli/agent-selection.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { describe, expect, test } from "bun:test";

import { parseAgentSelection } from "../../src/cli/agent-selection";
import { CliUsageError } from "../../src/cli/errors";

describe("parseAgentSelection", () => {
test("selects Codex by default", () => {
expect(parseAgentSelection(["Create", "a", "Workflow"])).toEqual({
agentName: "codex",
values: ["Create", "a", "Workflow"],
});
});

test("selects Claude from a separate option value", () => {
expect(parseAgentSelection(["--agent", "claude", "Create it"])).toEqual({
agentName: "claude",
values: ["Create it"],
});
});

test("selects Pi from an inline option value", () => {
expect(parseAgentSelection(["--agent=pi", "Create it"])).toEqual({
agentName: "pi",
values: ["Create it"],
});
});

test("rejects a missing option value", () => {
expect(() => parseAgentSelection(["--agent"])).toThrow(
new CliUsageError(
"Invalid --agent value: (missing). Expected codex, claude, or pi.",
),
);
});

test("rejects an unknown Agent", () => {
expect(() => parseAgentSelection(["--agent", "unknown"])).toThrow(
new CliUsageError(
"Invalid --agent value: unknown. Expected codex, claude, or pi.",
),
);
});

test("rejects duplicate Agent options", () => {
expect(() =>
parseAgentSelection(["--agent=pi", "--agent", "claude"]),
).toThrow(
new CliUsageError("The --agent option may only be specified once."),
);
});

test("preserves the order of remaining values", () => {
expect(
parseAgentSelection(["first", "--agent", "claude", "second", "third"]),
).toEqual({
agentName: "claude",
values: ["first", "second", "third"],
});
});
});