Unify the visible command surface on one canonical spelling per semantic concept while keeping every legacy spelling working as a silent parser/dispatcher alias (per .agents/rules/cli-protocol.md §6): - Fix silent-ignore accept-set gaps: webhook resource-pack export now reads --out/--output-file and --downloads/--download; approval-runs and webhook read canonical --start-date/--end-date; webhook secret reveal accepts --reveal/-r alongside legacy --show-secret. - Add kebab-case parser registrations for camel-only flags (human-result, manual-approval-status, include-bridge, rule-version, document-limit, context-lines, source-document-sn/-id, simulation-batch-id) and read them in rules/documents search, context, approval-runs list/summary/ bridge/export. - Retire verbs on the visible surface only: webhook create (add), simulation delete (clean), preference thinking-depth policies delete (remove); dispatch keeps both. Runtime nextAction suggestions and doctor knowledge switch to canonical spellings. - Add src/cli/naming-charter.test.ts: help surface must be lowercase kebab-case and free of retired tokens; canonical/legacy spellings must both parse; P0 accept-sets pinned. - Document the charter in .agents/rules/cli-protocol.md §7; sync AGENTS.md, README, and skills/references docs; regenerate cli.md and embedded skill artifacts.
263 lines
12 KiB
TypeScript
263 lines
12 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import { extractHelpRequest, HELP_REGISTRY, 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("explains both recode phases without exposing internal activation timing", () => {
|
|
const help = renderHelp(["rules", "recode"]);
|
|
expect(help).toContain("一次性凭证");
|
|
expect(help).toContain("另一次调用");
|
|
expect(help).toContain("不执行重排");
|
|
expect(help).not.toContain("500");
|
|
expect(help).not.toContain("--confirm-code");
|
|
});
|
|
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 create");
|
|
});
|
|
|
|
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).toContain("发现与选择:");
|
|
expect(help).toContain("企业接入:");
|
|
expect(help).toContain("seal-use corps add-hose-persistent");
|
|
expect(help).toContain("seal-use corps add-seal-bearer");
|
|
expect(help).toContain("seal-use corps add-hose-web-session");
|
|
expect(help).toContain("Hose 专属能力:");
|
|
expect(help).toContain("seal-use corps probe-hose");
|
|
expect(help).toContain("seal-use corps hose-staffs");
|
|
expect(help).toContain("seal-use corps hose-extract-keys");
|
|
expect(help).toContain("seal-use corps hose-keys");
|
|
expect(help).not.toContain("seal-use webhook");
|
|
expect(help).not.toContain("seal-use simulation");
|
|
expect(help).not.toContain("seal-use billing");
|
|
});
|
|
|
|
test("renders Hose-specific auth and approval flow command names", () => {
|
|
const authHelp = renderHelp(["auth"]);
|
|
const approvalHelp = renderHelp(["approval-runs"]);
|
|
expect(authHelp).toContain("seal-use auth hose-extract-keys");
|
|
expect(authHelp).toContain("seal-use auth hose-keys");
|
|
expect(approvalHelp).toContain("seal-use approval-runs hose-flow");
|
|
});
|
|
|
|
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("documents the canonical Hose onboarding command", () => {
|
|
const help = renderHelp(["corps", "add-hose-persistent"]);
|
|
expect(help).toContain("seal-use corps add-hose-persistent");
|
|
expect(help).not.toContain("add-hose 仍可用");
|
|
});
|
|
|
|
test("documents the canonical Seal onboarding command", () => {
|
|
const help = renderHelp(["corps", "add-seal-bearer"]);
|
|
expect(help).toContain("seal-use corps add-seal-bearer");
|
|
expect(help).not.toContain("add-seal 仍可用");
|
|
});
|
|
|
|
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 webhook replay --help renders replay usage and options with exitCode 0", async () => {
|
|
const result = await runCli(["webhook", "replay", "--help"]);
|
|
expect(result.exitCode).toBe(0);
|
|
expect(result.isError).toBe(false);
|
|
expect(result.stdout).toContain("seal-use webhook replay");
|
|
expect(result.stdout).toContain("--sn-suffix");
|
|
expect(result.stdout).toContain("--dry-run");
|
|
});
|
|
|
|
test("seal-use approval-runs replay --help renders replay usage and options with exitCode 0", async () => {
|
|
const result = await runCli(["approval-runs", "replay", "--help"]);
|
|
expect(result.exitCode).toBe(0);
|
|
expect(result.isError).toBe(false);
|
|
expect(result.stdout).toContain("seal-use approval-runs replay");
|
|
expect(result.stdout).toContain("--sn-suffix");
|
|
expect(result.stdout).toContain("--dry-run");
|
|
});
|
|
|
|
test("seal-use corps replay-test --help renders replay-test usage and options with exitCode 0", async () => {
|
|
const result = await runCli(["corps", "replay-test", "--help"]);
|
|
expect(result.exitCode).toBe(0);
|
|
expect(result.isError).toBe(false);
|
|
expect(result.stdout).toContain("seal-use corps replay-test");
|
|
expect(result.stdout).toContain("--sn-suffix");
|
|
expect(result.stdout).toContain("--dry-run");
|
|
});
|
|
|
|
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("every help registry area is dispatchable", () => {
|
|
// The forward direction is checked above. The reverse catches a registry
|
|
// area that renders help but no longer reaches a handler table — the
|
|
// "documented for two releases after the dispatcher dropped it" failure
|
|
// mode this suite exists to prevent, applied to `seal-use help` itself.
|
|
const dead = HELP_REGISTRY.map((entry) => entry.area)
|
|
.filter((area) => !KNOWN_AREAS.has(area));
|
|
|
|
expect(dead).toEqual([]);
|
|
});
|
|
|
|
test("stop shortcut and server alias resolve to help", () => {
|
|
expect(renderHelp(["server"])).toContain("seal-use mcp");
|
|
});
|
|
|
|
test("global help is generated from the registry", () => {
|
|
const help = renderHelp([]);
|
|
expect(help).toContain("seal-use CLI");
|
|
expect(help).toContain("seal-use version");
|
|
});
|
|
|
|
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(["mcp-config"])).not.toContain("<command> --help");
|
|
expect(renderHelp(["probe"])).not.toContain("<command> --help");
|
|
expect(renderHelp(["corps"])).toContain("Run 'seal-use corps <command> --help'");
|
|
});
|
|
});
|
|
|
|
describe("CLI help execution for domain commands", () => {
|
|
test("approval-runs --help prints updated count and export parameter usage", async () => {
|
|
const result = await runCli(["approval-runs", "--help"]);
|
|
expect(result.exitCode).toBe(0);
|
|
expect(result.isError).toBe(false);
|
|
expect(result.stdout).toContain("approval-runs count [--status APPROVED] [--start-date <YYYY-MM-DD|ms>] [--end-date <YYYY-MM-DD|ms>]");
|
|
expect(result.stdout).toContain("approval-runs export [--sn <SN1,SN2>] [--start-date <YYYY-MM-DD|ms>] [--end-date <YYYY-MM-DD|ms>] [--force] [--status <status>] [--manual-status <status>] [--completed-only]");
|
|
});
|
|
|
|
test("analytics export --help prints force parameter usage", async () => {
|
|
const result = await runCli(["analytics", "export", "--help"]);
|
|
expect(result.exitCode).toBe(0);
|
|
expect(result.isError).toBe(false);
|
|
expect(result.stdout).toContain("--force");
|
|
expect(result.stdout).toContain("Force export when time range exceeds 180 days");
|
|
});
|
|
});
|