2026-02-15 02:01:47 +08:00
|
|
|
import { Command } from "commander";
|
|
|
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
|
import type { ProgramContext } from "./context.js";
|
2026-02-14 13:10:10 -05:00
|
|
|
import {
|
|
|
|
|
getCoreCliCommandNames,
|
|
|
|
|
registerCoreCliByName,
|
|
|
|
|
registerCoreCliCommands,
|
|
|
|
|
} from "./command-registry.js";
|
2026-02-15 02:01:47 +08:00
|
|
|
|
2026-02-14 13:10:10 -05:00
|
|
|
const testProgramContext: ProgramContext = {
|
2026-02-15 02:01:47 +08:00
|
|
|
programVersion: "0.0.0-test",
|
2026-02-14 13:10:10 -05:00
|
|
|
channelOptions: [],
|
|
|
|
|
messageChannelOptions: "",
|
2026-02-15 02:01:47 +08:00
|
|
|
agentChannelOptions: "web",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
describe("command-registry", () => {
|
|
|
|
|
it("includes both agent and agents in core CLI command names", () => {
|
|
|
|
|
const names = getCoreCliCommandNames();
|
|
|
|
|
expect(names).toContain("agent");
|
|
|
|
|
expect(names).toContain("agents");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("registerCoreCliByName resolves agents to the agent entry", async () => {
|
|
|
|
|
const program = new Command();
|
2026-02-14 13:10:10 -05:00
|
|
|
const found = await registerCoreCliByName(program, testProgramContext, "agents");
|
2026-02-15 02:01:47 +08:00
|
|
|
expect(found).toBe(true);
|
|
|
|
|
const agentsCmd = program.commands.find((c) => c.name() === "agents");
|
|
|
|
|
expect(agentsCmd).toBeDefined();
|
2026-02-14 13:10:10 -05:00
|
|
|
// The registrar also installs the singular "agent" command from the same entry.
|
2026-02-15 02:01:47 +08:00
|
|
|
const agentCmd = program.commands.find((c) => c.name() === "agent");
|
|
|
|
|
expect(agentCmd).toBeDefined();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("registerCoreCliByName returns false for unknown commands", async () => {
|
|
|
|
|
const program = new Command();
|
2026-02-14 13:10:10 -05:00
|
|
|
const found = await registerCoreCliByName(program, testProgramContext, "nonexistent");
|
2026-02-15 02:01:47 +08:00
|
|
|
expect(found).toBe(false);
|
|
|
|
|
});
|
2026-02-14 13:10:10 -05:00
|
|
|
|
|
|
|
|
it("registers doctor placeholder for doctor primary command", () => {
|
|
|
|
|
const program = new Command();
|
|
|
|
|
registerCoreCliCommands(program, testProgramContext, ["node", "openclaw", "doctor"]);
|
|
|
|
|
|
|
|
|
|
expect(program.commands.map((command) => command.name())).toEqual(["doctor"]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("treats maintenance commands as top-level builtins", async () => {
|
|
|
|
|
const program = new Command();
|
|
|
|
|
|
|
|
|
|
expect(await registerCoreCliByName(program, testProgramContext, "doctor")).toBe(true);
|
|
|
|
|
|
|
|
|
|
const names = getCoreCliCommandNames();
|
|
|
|
|
expect(names).toContain("doctor");
|
|
|
|
|
expect(names).toContain("dashboard");
|
|
|
|
|
expect(names).toContain("reset");
|
|
|
|
|
expect(names).toContain("uninstall");
|
|
|
|
|
expect(names).not.toContain("maintenance");
|
|
|
|
|
});
|
2026-02-15 02:01:47 +08:00
|
|
|
});
|