mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-13 12:53:43 +02:00
55 lines
2.0 KiB
TypeScript
55 lines
2.0 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
shouldEagerRegisterSubcommands,
|
|
shouldRegisterPrimaryCommandOnly,
|
|
shouldRegisterPrimarySubcommandOnly,
|
|
shouldSkipPluginCommandRegistration,
|
|
} from "./command-registration-policy.js";
|
|
|
|
describe("command-registration-policy", () => {
|
|
it("matches primary command registration policy", () => {
|
|
expect(shouldRegisterPrimaryCommandOnly(["node", "openclaw", "status"])).toBe(true);
|
|
expect(shouldRegisterPrimaryCommandOnly(["node", "openclaw", "status", "--help"])).toBe(false);
|
|
expect(shouldRegisterPrimaryCommandOnly(["node", "openclaw", "-V"])).toBe(false);
|
|
expect(shouldRegisterPrimaryCommandOnly(["node", "openclaw", "acp", "-v"])).toBe(true);
|
|
});
|
|
|
|
it("matches plugin registration skip policy", () => {
|
|
expect(
|
|
shouldSkipPluginCommandRegistration({
|
|
argv: ["node", "openclaw", "--help"],
|
|
primary: null,
|
|
hasBuiltinPrimary: false,
|
|
}),
|
|
).toBe(true);
|
|
expect(
|
|
shouldSkipPluginCommandRegistration({
|
|
argv: ["node", "openclaw", "config", "--help"],
|
|
primary: "config",
|
|
hasBuiltinPrimary: true,
|
|
}),
|
|
).toBe(true);
|
|
expect(
|
|
shouldSkipPluginCommandRegistration({
|
|
argv: ["node", "openclaw", "voicecall", "--help"],
|
|
primary: "voicecall",
|
|
hasBuiltinPrimary: false,
|
|
}),
|
|
).toBe(false);
|
|
});
|
|
|
|
it("matches lazy subcommand registration policy", () => {
|
|
expect(shouldEagerRegisterSubcommands({ OPENCLAW_DISABLE_LAZY_SUBCOMMANDS: "1" })).toBe(true);
|
|
expect(shouldEagerRegisterSubcommands({ OPENCLAW_DISABLE_LAZY_SUBCOMMANDS: "0" })).toBe(false);
|
|
expect(shouldRegisterPrimarySubcommandOnly(["node", "openclaw", "acp"], {})).toBe(true);
|
|
expect(shouldRegisterPrimarySubcommandOnly(["node", "openclaw", "acp", "--help"], {})).toBe(
|
|
false,
|
|
);
|
|
expect(
|
|
shouldRegisterPrimarySubcommandOnly(["node", "openclaw", "acp"], {
|
|
OPENCLAW_DISABLE_LAZY_SUBCOMMANDS: "1",
|
|
}),
|
|
).toBe(false);
|
|
});
|
|
});
|