Simplify instance lifecycle commands
This commit is contained in:
+47
-14
@@ -1,26 +1,59 @@
|
||||
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[]) {
|
||||
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_GATEWAY_CONFIG: "" }
|
||||
env: { ...process.env, GORI_AGENT_ROOT: root, GORI_GATEWAY_CONFIG: "" }
|
||||
});
|
||||
}
|
||||
|
||||
test("CLI rejects unknown flags and command-specific extra arguments", () => {
|
||||
const unknown = runCli(["status", "--bogus"]);
|
||||
assert.equal(unknown.status, 1);
|
||||
assert.match(unknown.stderr, /Unknown option: --bogus/);
|
||||
|
||||
const extra = runCli(["doctor", "extra"]);
|
||||
assert.equal(extra.status, 1);
|
||||
assert.match(extra.stderr, /doctor accepts only --config/);
|
||||
|
||||
const instanceFlag = runCli(["instance", "list", "--config", "config.json"]);
|
||||
assert.equal(instanceFlag.status, 1);
|
||||
assert.match(instanceFlag.stderr, /instance commands do not accept/);
|
||||
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} <bot-id>`));
|
||||
}
|
||||
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 <bot-id>/);
|
||||
|
||||
const extra = runCli(["doctor", "one", "two"]);
|
||||
assert.equal(extra.status, 1);
|
||||
assert.match(extra.stderr, /doctor requires exactly one <bot-id>/);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user