import { describe, it, expect } from "vitest"; import { parseVaultArgs, isSubcommand, getSubcommands, getSubcommandDescription, } from "../commands/parse-args.js"; describe("parseVaultArgs", () => { it("returns undefined for empty string", () => { expect(parseVaultArgs("")).toBeUndefined(); }); it("returns undefined for whitespace-only string", () => { expect(parseVaultArgs(" ")).toBeUndefined(); }); it("returns undefined for unrecognized subcommand", () => { expect(parseVaultArgs("bogus")).toBeUndefined(); }); it("parses a simple subcommand with no args", () => { const result = parseVaultArgs("show"); expect(result).toEqual({ subcommand: "show", args: [] }); }); it("normalizes case", () => { const result = parseVaultArgs("SHOW"); expect(result).toEqual({ subcommand: "show", args: [] }); }); it("trims leading and trailing whitespace", () => { const result = parseVaultArgs(" verify "); expect(result).toEqual({ subcommand: "verify", args: [] }); }); it("parses subcommand with one arg", () => { const result = parseVaultArgs("export age"); expect(result).toEqual({ subcommand: "export", args: ["age"] }); }); it("parses subcommand with multiple args", () => { const result = parseVaultArgs("export age --force"); expect(result).toEqual({ subcommand: "export", args: ["age", "--force"], }); }); it("handles multiple spaces between tokens", () => { const result = parseVaultArgs("export keychain"); expect(result).toEqual({ subcommand: "export", args: ["keychain"], }); }); it("recognizes all valid subcommands", () => { const subs = getSubcommands(); for (const sub of subs) { const result = parseVaultArgs(sub); expect(result).toBeDefined(); expect(result?.subcommand).toBe(sub); } }); }); describe("isSubcommand", () => { it("returns true for valid subcommands", () => { expect(isSubcommand("show")).toBe(true); expect(isSubcommand("verify")).toBe(true); expect(isSubcommand("export")).toBe(true); }); it("returns false for invalid strings", () => { expect(isSubcommand("bogus")).toBe(false); expect(isSubcommand("")).toBe(false); expect(isSubcommand("SHOW")).toBe(false); }); }); describe("getSubcommands", () => { it("returns all known subcommands", () => { const subs = getSubcommands(); expect(subs).toContain("show"); expect(subs).toContain("verify"); expect(subs).toContain("providers"); expect(subs).toContain("setup"); expect(subs).toContain("import"); expect(subs).toContain("export"); expect(subs).toContain("path"); expect(subs).toContain("help"); expect(subs).toHaveLength(8); }); }); describe("getSubcommandDescription", () => { it("returns a non-empty string for every subcommand", () => { for (const sub of getSubcommands()) { const desc = getSubcommandDescription(sub); expect(desc.length).toBeGreaterThan(0); } }); });