import assert from "node:assert/strict"; import { spawnSync } from "node:child_process"; import fs from "node:fs"; import os from "node:os"; import path from "node:path"; import test from "node:test"; function runCli(args: string[], root = fs.mkdtempSync(path.join(os.tmpdir(), "gori-cli-"))) { return spawnSync(process.execPath, ["--import", "tsx", path.resolve("src/cli.ts"), ...args], { cwd: path.resolve("."), encoding: "utf8", env: { ...process.env, GORI_AGENT_ROOT: root, GORI_GATEWAY_CONFIG: "" } }); } test("CLI help exposes only direct instance commands", () => { const result = runCli(["--help"]); assert.equal(result.status, 0); for (const command of ["init", "setup", "start", "stop", "restart", "status", "logs", "doctor"]) { assert.match(result.stdout, new RegExp(`gori-agent ${command} `)); } assert.match(result.stdout, /gori-agent list/); assert.doesNotMatch(result.stdout, /gori-agent instance|--config|--json|discover-backends|print feishu/); }); test("CLI dispatches direct commands and rejects removed entry points", () => { assert.equal(runCli(["list"]).status, 0); for (const command of ["setup", "start", "stop", "restart", "status", "logs", "doctor"]) { const result = runCli([command, "missing-bot"]); assert.equal(result.status, 1); assert.match(result.stderr, /Runtime config does not exist/); } const init = runCli(["init", "INVALID"]); assert.equal(init.status, 1); assert.match(init.stderr, /Invalid bot ID/); for (const removed of [["instance", "list"], ["discover-backends"], ["discover-agents"], ["print", "feishu"]]) { const result = runCli(removed); assert.equal(result.status, 1); assert.match(result.stderr, /Unknown command/); } }); test("CLI rejects options and invalid command argument counts", () => { for (const args of [["status", "bot", "--config", "config.json"], ["list", "--json"], ["start", "--bogus"]]) { const result = runCli(args); assert.equal(result.status, 1); assert.match(result.stderr, /Unknown option/); } const missing = runCli(["setup"]); assert.equal(missing.status, 1); assert.match(missing.stderr, /setup requires exactly one /); const extra = runCli(["doctor", "one", "two"]); assert.equal(extra.status, 1); assert.match(extra.stderr, /doctor requires exactly one /); });