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