1import { describe, test, expect } from "bun:test";
2import { parseArgs } from "../src/cli/parse-args.js";
3
4describe("CLI --key=value parsing (issue #6)", () => {
5 test("--key=value with '=' in value preserves full value", () => {
6 const result = parseArgs(["node", "script", "web", "--key=a=b=c"]);
7 expect(result.options["key"]).toBe("a=b=c");
8 });
9
10 test("--key=value without extra '=' still works", () => {
11 const result = parseArgs(["node", "script", "web", "--model=openai:gpt-4"]);
12 expect(result.options["model"]).toBe("openai:gpt-4");
13 });
14
15 test("--flag without value is boolean true", () => {
16 const result = parseArgs(["node", "script", "web", "--verbose"]);
17 expect(result.options["verbose"]).toBe(true);
18 });
19
20 test("--key value (space-separated) works", () => {
21 const result = parseArgs(["node", "script", "web", "--model", "openai:gpt-4"]);
22 expect(result.options["model"]).toBe("openai:gpt-4");
23 });
24});
25
26describe("CLI -u short flag (issue #7)", () => {
27 test("-u does not swallow a following flag as its value", () => {
28 const result = parseArgs(["node", "script", "web", "-u", "--verbose"]);
29 expect(result.options["uri"]).toBeUndefined();
30 expect(result.options["verbose"]).toBe(true);
31 });
32
33 test("-u with valid URL works normally", () => {
34 const result = parseArgs(["node", "script", "web", "-u", "https://example.com"]);
35 expect(result.options["uri"]).toBe("https://example.com");
36 });
37
38 test("-u swallowing -f as value is prevented", () => {
39 const result = parseArgs(["node", "script", "repo", "-u", "-f"]);
40 expect(result.options["uri"]).toBeUndefined();
41 // -u with no valid value is a no-op, -f should be parsed as full flag
42 expect(result.options["full"]).toBe(true);
43 });
44
45 test("-u at end of args leaves uri unset (no stray option)", () => {
46 const result = parseArgs(["node", "script", "web", "-u"]);
47 expect(result.options["uri"]).toBeUndefined();
48 expect(result.options["u"]).toBeUndefined();
49 });
50});