diff --git a/src/cli/help.test.ts b/src/cli/help.test.ts index 1c97ada..2c6f129 100644 --- a/src/cli/help.test.ts +++ b/src/cli/help.test.ts @@ -1,6 +1,6 @@ import { describe, expect, test } from "bun:test"; import { extractHelpRequest, renderHelp } from "./help.js"; -import { runCli } from "./runner.js"; +import { KNOWN_AREAS, runCli } from "./runner.js"; describe("extractHelpRequest", () => { test("detects global help from empty command or help option", () => { @@ -126,3 +126,60 @@ describe("CLI help execution via runCli", () => { 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"); + }); +}); diff --git a/src/cli/help.ts b/src/cli/help.ts index f1e9749..fe4f4f3 100644 --- a/src/cli/help.ts +++ b/src/cli/help.ts @@ -462,6 +462,7 @@ export const HELP_REGISTRY: AreaHelp[] = [ }, { name: "get", + aliases: ["status"], summary: "Display current global configuration", usage: ["seal-use config get"] }, @@ -472,6 +473,7 @@ export const HELP_REGISTRY: AreaHelp[] = [ }, { name: "test-dir", + aliases: ["test-enterprises-dir"], summary: "Set or clear global test enterprises directory", usage: ["seal-use config test-dir [|--clear]"] }, @@ -802,6 +804,55 @@ export const HELP_REGISTRY: AreaHelp[] = [ } ] }, + { + area: "service", + title: "Background HTTP service lifecycle", + description: "Start, stop, restart, inspect, and read logs from the standalone seal-use HTTP service daemon.", + commands: [ + { + name: "start", + summary: "Start the background service daemon", + usage: ["seal-use service start [--port 8787] [--host 127.0.0.1]"] + }, + { + name: "stop", + summary: "Stop the background service daemon", + usage: ["seal-use service stop"] + }, + { + name: "restart", + summary: "Restart the background service daemon", + usage: ["seal-use service restart [--port 8787] [--host 127.0.0.1]"] + }, + { + name: "status", + summary: "Show service daemon status", + usage: ["seal-use service status"] + }, + { + name: "logs", + summary: "Print recent service daemon logs", + usage: ["seal-use service logs [--lines 50]"] + }, + { + name: "run", + summary: "Run the service in the foreground", + usage: ["seal-use service run [--port 8787] [--host 127.0.0.1]"] + } + ] + }, + { + area: "stop", + title: "Stop the background service", + description: "Shortcut for stopping the background seal-use HTTP service daemon.", + commands: [ + { + name: "", + summary: "Stop the background service daemon", + usage: ["seal-use stop"] + } + ] + }, { area: "openapi", title: "OpenAPI specification", @@ -820,7 +871,7 @@ export function extractHelpRequest(args: ParsedArgs): { isHelp: boolean; target: const hasHelpOption = Boolean(args.options.help || args.options.h); if (!args.command.length) { - return hasHelpOption ? { isHelp: true, target: [] } : { isHelp: true, target: [] }; + return { isHelp: true, target: [] }; } if (args.command[0] === "help") { @@ -878,6 +929,7 @@ function normalizeArea(area: string): string { if (lower === "changelog") return "update"; if (lower === "serve") return "http"; if (lower === "mcp-config") return "mcp"; + if (lower === "server") return "mcp"; return lower; } @@ -945,132 +997,27 @@ function renderAreaHelp(areaEntry: AreaHelp): string { lines.push(` ${usage}`); } } - lines.push(""); - lines.push(`Run 'seal-use ${areaEntry.area} --help' for details on a specific command.`); + if (areaEntry.commands.some((cmd) => cmd.name)) { + lines.push(""); + lines.push(`Run 'seal-use ${areaEntry.area} --help' for details on a specific command.`); + } return lines.join("\n"); } export function renderGlobalHelp(): string { - return `seal-use CLI - -Usage: - seal-use version - seal-use mcp - seal-use mcp config - seal-use mcp-config - seal-use skill dump - seal-use skill install [--dir |--local] - seal-use skill status - seal-use http [--port 8787] [--host 127.0.0.1] - seal-use serve [--port 8787] - seal-use openapi - seal-use probe [] - seal-use config paths - seal-use config get - seal-use config mode [--corp ] - seal-use config test-dir [|--clear] - seal-use config lint [status|enable|disable] [--linter ] [--min-score ] - seal-use update [--check] [--force] [--version ] - seal-use update check - seal-use update changelog [--limit ] - seal-use changelog [--limit ] - seal-use tools list - seal-use corps list [--corp ] - seal-use corps current [--corp ] - seal-use corps switch - seal-use corps mark --env [--confirm] - seal-use corps bind-test [--confirm] [--force] - seal-use corps unbind-test [] [--confirm] - seal-use corps sync-test [] [--dry-run] [--yes] [--version-name ] - seal-use corps add-hose --json '{"name":"企业名称","domain":"https://app.ekuaibao.com","appKey":"...","appSecurity":"...","proxyStaffBizId":"corpId:staffId"}' - seal-use corps add-seal --json '{"sealUrl":"https://tenant.sealai.cc","token":"seal-bearer-token"}' - seal-use corps add-link [--name ] [--overwrite] - seal-use auth diagnose [--corp ] - seal-use auth hose-link [--corp ] [--expire 7200] - seal-use delegation list [--corp ] - seal-use delegation create [--note ] [--from-link ] [--corp ] - seal-use delegation revoke [--corp ] - seal-use users create --name --phone [--dept ] [--corp ] - seal-use users search [--corp ] - seal-use users delegation [--note ] [--corp ] - seal-use users reset-password [--corp ] - seal-use users get [--corp ] - seal-use users delete [--corp ] - seal-use contacts departments [] [--corp ] - seal-use contacts children [--corp ] - seal-use contacts users [--corp ] - seal-use contacts sync-time [--corp ] - seal-use data expenses [--search ] [--start-date ] [--end-date ] [--offset ] [--limit ] [--corp ] - seal-use data invoices [--search ] [--start-date ] [--end-date ] [--offset ] [--limit ] [--corp ] - seal-use llm config [--corp ] - seal-use llm providers [--corp ] - seal-use permissions available [--corp ] - seal-use permissions configs [--corp ] - seal-use billing status [--corp ] - seal-use billing plans [--corp ] - seal-use billing features [--corp ] - seal-use webhook ready [<材料包.zip>] [--webhook ] [--corp ] - seal-use webhook status [<材料包.zip>] [--corp ] - seal-use webhook list [--query ] [--show-secret] [--corp ] - seal-use webhook get|find [--show-secret] [--corp ] - seal-use webhook add --name --result-url [--mode assisted|semi_automatic|fully_automatic] [--auto-approval-rate 60] [--secret ] [--min-file-size 500] [--max-file-size ] [--allowed-extensions <.pdf,.xlsx,...>] [--dry-run] [--corp ] - seal-use webhook update [--name ] [--result-url ] [--mode assisted|semi_automatic|fully_automatic] [--auto-approval-rate 60] [--secret |--rotate-secret] [--min-file-size ] [--max-file-size ] [--allowed-extensions <.pdf,.xlsx,...>] [--clear-max-file-size] [--dry-run] [--corp ] - seal-use webhook delete [--yes|--dry-run] [--corp ] - seal-use webhook material-pack preview <材料包.zip|信息表.xlsx> [--min-file-size ] [--max-file-size ] [--allowed-extensions <.pdf,.xlsx,...>] [--corp ] - seal-use webhook material-pack push <材料包.zip|信息表.xlsx> [--webhook ] [--corp ] - seal-use deploy hosecloud requirements [--corp ] - seal-use deploy hosecloud list [--corp ] - seal-use deploy hosecloud get [--corp ] - seal-use deploy hosecloud status [--corp ] - seal-use deploy hosecloud configure --json '{...}' [--dry-run] [--corp ] - seal-use deploy hosecloud sync [--corp ] - seal-use preference get [--corp ] - seal-use preference decision update --json '{\"explicitApprove\":\"...\"}' [--dry-run] [--corp ] - seal-use preference thinking-depth set --default [--dry-run] [--corp ] - seal-use preference thinking-depth policies list [--corp ] - seal-use preference thinking-depth policies upsert --json '{...}' [--dry-run] [--corp ] - seal-use preference thinking-depth policies remove [--dry-run] [--corp ] - seal-use source config [--corp ] - seal-use tool [--corp ] [--json '{\"key\":\"value\"}'] - seal-use rules count [--corp ] - seal-use rules list [--summary] [--count] [--limit 20] [--offset 0] [--corp ] - seal-use rules clear [--corp ] [--dry-run|--yes] - seal-use rules versions [--corp ] - seal-use rules version [--corp ] - seal-use rules get --corp --version --code '#0038' - seal-use rules get --corp --record-id --runtime-id rule-205 - seal-use rules search [--version ] [--maxResults 20] [--corp ] - seal-use context [--ruleVersion ] [--documentLimit 50] [--corp ] - seal-use approval-runs summary [--date YYYY-MM-DD] [--timezone Asia/Shanghai] [--corp ] - seal-use approval-runs stats [--since 3months] [--dedupe-by sourceDocumentSN|sourceDocumentId|id] [--corp ] - seal-use approval-runs count [--status APPROVED] [--corp ] - seal-use approval-runs export [--start ] [--end ] [--limit ] [--downloads] [--out ] [--corp ] - seal-use approval-runs list|search [--query text] [--humanResult 驳回] [--manualApprovalStatus TERMINATED] [--startDate ms] [--endDate ms] [--limit 20] [--includeBridge true] [--corp ] - seal-use approval-runs pick --sn [--batch ] [--latest] [--fields recordId,status,aiDecision] [--corp ] - seal-use approval-runs get [--summary] [--fields metadata|document.fields,result.summary] [--full] [--output-file file.json] [--corp ] - seal-use approval-runs cited-rules [--corp ] - seal-use approval-runs document-summary [--corp ] - seal-use approval-runs attachments [--summary] [--corp ] - seal-use approval-runs attachments download [--all] [--name ] [--out-dir ] [--corp ] - seal-use approval-runs result [--summary] [--corp ] - seal-use analytics insight [--start-date ] [--end-date ] [--limit ] [--corp ] - seal-use approval-runs url [--corp ] - seal-use approval-runs url [--corp ] - seal-use approval-runs url --sourceDocumentSN B26022501 [--corp ] - seal-use approval-runs bridge [--sourceDocumentSN B26001887] [--corp ] - seal-use simulation batch-records [--corp ] - seal-use simulation create --mode hosecloud --flow-ids \"B26017701,B26022501\" [--reject-node 财务] [--thinking-depth default|medium|high] [--skip-invoice-generation|--skip-invoice-generation false] [--no-wait] [--corp ] - seal-use simulation create --mode material_pack --package-ids [--template-id conference_reimbursement_v1] [--schema-config file.json] [--corp ] - seal-use simulation create --source-system weaver --request-ids \"req-01,req-02\" [--corp ] - seal-use simulation status [--corp ] - seal-use simulation wait [--timeout 10m] [--poll-interval 2s] [--corp ] - seal-use simulation clean [--corp ] - seal-use simulation specifications [--integration ] [--corp ] - seal-use simulation approval-definitions [--corp ] - seal-use simulation list [--limit 50] [--corp ] - seal-use simulation get [--corp ] - seal-use simulation templates [--corp ] - seal-use simulation integrations [--corp ] - seal-use simulation package-upload <材料包.zip> [--corp ] -`; + const lines: string[] = []; + lines.push("seal-use CLI"); + lines.push(""); + lines.push("Usage:"); + lines.push(" seal-use version"); + for (const area of HELP_REGISTRY) { + for (const command of area.commands) { + for (const usage of command.usage) { + lines.push(` ${usage}`); + } + } + } + lines.push(""); + lines.push("Run 'seal-use --help' for details on a specific command."); + return lines.join("\n"); } diff --git a/src/cli/runner.ts b/src/cli/runner.ts index 3986548..ca0e169 100755 --- a/src/cli/runner.ts +++ b/src/cli/runner.ts @@ -53,7 +53,7 @@ import { import type { CliResult, CliRunOptions, CliRuntime } from "./types.js"; const DEFAULT_APP_ROOT = dirname(dirname(dirname(fileURLToPath(import.meta.url)))); -const KNOWN_AREAS = new Set([ +export const KNOWN_AREAS = new Set([ "config", "service", "stop",