refactor: unify CLI flag parsing across interactive and headless (#1137)

Co-authored-by: cpacker <packercharles@gmail.com>
This commit is contained in:
Devansh Jain
2026-02-25 18:29:56 -08:00
committed by GitHub
parent 17a70d6586
commit c8fb2cc3b1
9 changed files with 1091 additions and 379 deletions

View File

@@ -0,0 +1,51 @@
import { describe, expect, test } from "bun:test";
import {
parseCsvListFlag,
parseJsonArrayFlag,
parsePositiveIntFlag,
resolveImportFlagAlias,
} from "../../cli/flagUtils";
describe("flag utils", () => {
test("parseCsvListFlag handles undefined and none", () => {
expect(parseCsvListFlag(undefined)).toBeUndefined();
expect(parseCsvListFlag("none")).toEqual([]);
expect(parseCsvListFlag("a, b ,c")).toEqual(["a", "b", "c"]);
});
test("resolveImportFlagAlias prefers --import", () => {
expect(
resolveImportFlagAlias({
importFlagValue: "@author/agent",
fromAfFlagValue: "path.af",
}),
).toBe("@author/agent");
expect(
resolveImportFlagAlias({
importFlagValue: undefined,
fromAfFlagValue: "path.af",
}),
).toBe("path.af");
});
test("parsePositiveIntFlag validates positive integers", () => {
expect(
parsePositiveIntFlag({
rawValue: "3",
flagName: "max-turns",
}),
).toBe(3);
expect(() =>
parsePositiveIntFlag({ rawValue: "0", flagName: "max-turns" }),
).toThrow("--max-turns must be a positive integer");
});
test("parseJsonArrayFlag parses arrays and rejects non-arrays", () => {
expect(
parseJsonArrayFlag('[{"label":"persona"}]', "memory-blocks"),
).toEqual([{ label: "persona" }]);
expect(() =>
parseJsonArrayFlag('{"label":"persona"}', "memory-blocks"),
).toThrow("memory-blocks must be a JSON array");
});
});