Open History to see the last commit
1import { describe, expect, it } from "vitest";
2
3import { parseCliArgs } from "./cliArgs.ts";
4
5describe("parseCliArgs", () => {
6 it("returns empty result for empty string", () => {
7 expect(parseCliArgs("")).toEqual({ flags: {}, positionals: [] });
8 });
9
10 it("returns empty result for whitespace-only string", () => {
11 expect(parseCliArgs(" ")).toEqual({ flags: {}, positionals: [] });
12 });
13
14 it("returns empty result for empty array", () => {
15 expect(parseCliArgs([])).toEqual({ flags: {}, positionals: [] });
16 });
17
18 it("parses --chrome boolean flag", () => {
19 expect(parseCliArgs("--chrome")).toEqual({
20 flags: { chrome: null },
21 positionals: [],
22 });
23 });
24
25 it("parses --chrome with --verbose", () => {
26 expect(parseCliArgs("--chrome --verbose")).toEqual({
27 flags: { chrome: null, verbose: null },
28 positionals: [],
29 });
30 });
31
32 it("parses --effort with a value", () => {
33 expect(parseCliArgs("--effort high")).toEqual({
34 flags: { effort: "high" },
35 positionals: [],
36 });
37 });
38
39 it("parses --chrome --effort high --debug", () => {
40 expect(parseCliArgs("--chrome --effort high --debug")).toEqual({
41 flags: { chrome: null, effort: "high", debug: null },
42 positionals: [],
43 });
44 });
45
46 it("parses --model with full model name", () => {
47 expect(parseCliArgs("--model claude-sonnet-4-6")).toEqual({
48 flags: { model: "claude-sonnet-4-6" },
49 positionals: [],
50 });
51 });
52
53 it("parses --append-system-prompt with value and --chrome", () => {
54 expect(parseCliArgs("--append-system-prompt always-think-step-by-step --chrome")).toEqual({
55 flags: { "append-system-prompt": "always-think-step-by-step", chrome: null },
56 positionals: [],
57 });
58 });
59
60 it("parses --max-budget-usd with numeric value", () => {
61 expect(parseCliArgs("--chrome --max-budget-usd 5.00")).toEqual({
62 flags: { chrome: null, "max-budget-usd": "5.00" },
63 positionals: [],
64 });
65 });
66
67 it("parses --effort=high syntax", () => {
68 expect(parseCliArgs("--effort=high")).toEqual({
69 flags: { effort: "high" },
70 positionals: [],
71 });
72 });
73
74 it("parses --key=value mixed with boolean flags", () => {
75 expect(parseCliArgs("--chrome --model=claude-sonnet-4-6 --debug")).toEqual({
76 flags: { chrome: null, model: "claude-sonnet-4-6", debug: null },
77 positionals: [],
78 });
79 });
80
81 it("collects positional arguments", () => {
82 expect(parseCliArgs("1.2.3")).toEqual({
83 flags: {},
84 positionals: ["1.2.3"],
85 });
86 });
87
88 it("collects positionals mixed with flags (argv array)", () => {
89 expect(parseCliArgs(["1.2.3", "--root", "/path", "--github-output"])).toEqual({
90 flags: { root: "/path", "github-output": null },
91 positionals: ["1.2.3"],
92 });
93 });
94
95 it("handles extra whitespace between tokens", () => {
96 expect(parseCliArgs(" --chrome --verbose ")).toEqual({
97 flags: { chrome: null, verbose: null },
98 positionals: [],
99 });
100 });
101
102 it("ignores bare -- with no flag name", () => {
103 expect(parseCliArgs("--")).toEqual({ flags: {}, positionals: [] });
104 });
105
106 it("boolean flag does not consume next token as value", () => {
107 expect(parseCliArgs(["--github-output", "1.2.3"], { booleanFlags: ["github-output"] })).toEqual(
108 {
109 flags: { "github-output": null },
110 positionals: ["1.2.3"],
111 },
112 );
113 });
114
115 it("non-boolean flag still consumes next token", () => {
116 expect(parseCliArgs(["--root", "/path", "1.2.3"], { booleanFlags: ["github-output"] })).toEqual(
117 {
118 flags: { root: "/path" },
119 positionals: ["1.2.3"],
120 },
121 );
122 });
123
124 it("mixes boolean and value flags with positionals", () => {
125 expect(
126 parseCliArgs(["--github-output", "--root", "/path", "1.2.3"], {
127 booleanFlags: ["github-output"],
128 }),
129 ).toEqual({
130 flags: { "github-output": null, root: "/path" },
131 positionals: ["1.2.3"],
132 });
133 });
134});