import { describe, expect, test } from "bun:test"; import { extractHelpRequest, renderHelp } from "./help.js"; import { KNOWN_AREAS, runCli } from "./runner.js"; describe("extractHelpRequest", () => { test("detects global help from empty command or help option", () => { expect(extractHelpRequest({ command: [], options: {} })).toEqual({ isHelp: true, target: [] }); expect(extractHelpRequest({ command: ["help"], options: {} })).toEqual({ isHelp: true, target: [] }); expect(extractHelpRequest({ command: [], options: { help: true } })).toEqual({ isHelp: true, target: [] }); expect(extractHelpRequest({ command: [], options: { h: true } })).toEqual({ isHelp: true, target: [] }); }); test("detects area help across various syntax styles", () => { expect(extractHelpRequest({ command: ["corps"], options: { help: true } })).toEqual({ isHelp: true, target: ["corps"] }); expect(extractHelpRequest({ command: ["corps"], options: { h: true } })).toEqual({ isHelp: true, target: ["corps"] }); expect(extractHelpRequest({ command: ["corps", "help"], options: {} })).toEqual({ isHelp: true, target: ["corps"] }); expect(extractHelpRequest({ command: ["help", "corps"], options: {} })).toEqual({ isHelp: true, target: ["corps"] }); }); test("detects subcommand help across various syntax styles", () => { expect(extractHelpRequest({ command: ["corps", "bind-test"], options: { help: true } })).toEqual({ isHelp: true, target: ["corps", "bind-test"] }); expect(extractHelpRequest({ command: ["corps", "bind-test"], options: { h: true } })).toEqual({ isHelp: true, target: ["corps", "bind-test"] }); expect(extractHelpRequest({ command: ["corps", "help", "bind-test"], options: {} })).toEqual({ isHelp: true, target: ["corps", "bind-test"] }); expect(extractHelpRequest({ command: ["help", "corps", "bind-test"], options: {} })).toEqual({ isHelp: true, target: ["corps", "bind-test"] }); }); test("returns isHelp: false for normal executions", () => { expect(extractHelpRequest({ command: ["corps", "list"], options: {} })).toEqual({ isHelp: false, target: [] }); expect(extractHelpRequest({ command: ["corps", "bind-test", "prod", "test"], options: { confirm: true } })).toEqual({ isHelp: false, target: [] }); }); }); describe("renderHelp", () => { test("renders global help when target is empty", () => { const help = renderHelp([]); expect(help).toContain("seal-use CLI"); expect(help).toContain("seal-use corps list"); expect(help).toContain("seal-use webhook add"); }); test("renders focused area help without polluting with other domains", () => { const help = renderHelp(["corps"]); expect(help).toContain("seal-use corps - Enterprise and tenant management"); expect(help).toContain("seal-use corps bind-test"); expect(help).toContain("seal-use corps sync-test"); expect(help).not.toContain("seal-use webhook"); expect(help).not.toContain("seal-use simulation"); expect(help).not.toContain("seal-use billing"); }); test("renders focused subcommand help with usage, options, and description", () => { const help = renderHelp(["corps", "bind-test"]); expect(help).toContain("seal-use corps bind-test"); expect(help).toContain("--confirm"); expect(help).toContain("--force"); expect(help).toContain("1-to-1 association"); expect(help).not.toContain("seal-use corps list"); expect(help).not.toContain("seal-use webhook"); }); test("throws usage error for unknown area or subcommand", () => { expect(() => renderHelp(["nonexistent-domain"])).toThrow(/Unknown command/); expect(() => renderHelp(["corps", "nonexistent-cmd"])).toThrow(/Unknown corps command/); }); }); describe("CLI help execution via runCli", () => { test("seal-use corps bind-test --help prints only bind-test help with exitCode 0", async () => { const result = await runCli(["corps", "bind-test", "--help"]); expect(result.exitCode).toBe(0); expect(result.isError).toBe(false); expect(result.stdout).toContain("seal-use corps bind-test"); expect(result.stdout).toContain("--confirm"); expect(result.stdout).toContain("--force"); expect(result.stdout).not.toContain("seal-use webhook"); expect(result.stdout).not.toContain("seal-use simulation"); expect(result.stdout).not.toContain("seal-use billing"); expect(result.stdout).not.toContain("seal-use preference"); }); test("seal-use corps --help prints only corps domain commands with exitCode 0", async () => { const result = await runCli(["corps", "--help"]); expect(result.exitCode).toBe(0); expect(result.isError).toBe(false); expect(result.stdout).toContain("seal-use corps - Enterprise and tenant management"); expect(result.stdout).toContain("seal-use corps list"); expect(result.stdout).toContain("seal-use corps bind-test"); expect(result.stdout).not.toContain("seal-use webhook"); expect(result.stdout).not.toContain("seal-use simulation"); }); test("seal-use corp --help resolves to corps domain commands with exitCode 0", async () => { const result = await runCli(["corp", "--help"]); expect(result.exitCode).toBe(0); expect(result.isError).toBe(false); expect(result.stdout).toContain("seal-use corps - Enterprise and tenant management"); expect(result.stdout).toContain("seal-use corps list"); expect(result.stdout).toContain("seal-use corps bind-test"); expect(result.stdout).not.toContain("seal-use webhook"); expect(result.stdout).not.toContain("seal-use simulation"); }); test("seal-use corps unknown-cmd --help exits with code 2", async () => { const result = await runCli(["corps", "unknown-cmd", "--help"]); expect(result.exitCode).toBe(2); expect(result.isError).toBe(true); expect(result.stderr).toContain("Unknown corps command: unknown-cmd"); }); }); describe("help coverage", () => { test("every dispatchable area resolves to help without throwing", () => { for (const area of KNOWN_AREAS) { expect(() => renderHelp([area])).not.toThrow(); } }); test("service lifecycle exposes area and command help", () => { const area = renderHelp(["service"]); expect(area).toContain("seal-use service - Background HTTP service lifecycle"); expect(area).toContain("seal-use service start"); expect(area).toContain("seal-use service logs"); expect(renderHelp(["service", "logs"])).toContain("seal-use service logs"); }); test("stop shortcut and server alias resolve to help", () => { expect(renderHelp(["stop"])).toContain("seal-use stop"); expect(renderHelp(["server"])).toContain("seal-use mcp"); }); test("global help is generated from the registry and lists lifecycle commands", () => { const help = renderHelp([]); expect(help).toContain("seal-use CLI"); expect(help).toContain("seal-use version"); expect(help).toContain("seal-use service start"); expect(help).toContain("seal-use stop"); }); test("config aliases resolve to the documented commands", () => { expect(renderHelp(["config", "status"])).toContain("seal-use config get"); expect(renderHelp(["config", "test-enterprises-dir"])).toContain("seal-use config test-dir"); }); test("singleton areas do not advertise a nonexistent subcommand help", () => { expect(renderHelp(["http"])).not.toContain(" --help"); expect(renderHelp(["stop"])).not.toContain(" --help"); expect(renderHelp(["corps"])).toContain("Run 'seal-use corps --help'"); }); }); describe("CLI help execution for lifecycle commands", () => { test("seal-use service --help prints service commands with exitCode 0", async () => { const result = await runCli(["service", "--help"]); expect(result.exitCode).toBe(0); expect(result.isError).toBe(false); expect(result.stdout).toContain("seal-use service start"); expect(result.stdout).toContain("seal-use service status"); }); test("seal-use stop --help prints stop help with exitCode 0", async () => { const result = await runCli(["stop", "--help"]); expect(result.exitCode).toBe(0); expect(result.isError).toBe(false); expect(result.stdout).toContain("seal-use stop"); }); });