mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 11:30:43 +00:00
124 lines
3.7 KiB
TypeScript
124 lines
3.7 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { resolveCliCommandPathPolicy } from "./command-path-policy.js";
|
|
|
|
describe("command-path-policy", () => {
|
|
it("resolves status policy with shared startup semantics", () => {
|
|
expect(resolveCliCommandPathPolicy(["status"])).toEqual({
|
|
bypassConfigGuard: false,
|
|
routeConfigGuard: "when-suppressed",
|
|
loadPlugins: "never",
|
|
hideBanner: false,
|
|
ensureCliPath: false,
|
|
});
|
|
});
|
|
|
|
it("applies exact overrides after broader channel plugin rules", () => {
|
|
expect(resolveCliCommandPathPolicy(["channels", "send"])).toEqual({
|
|
bypassConfigGuard: false,
|
|
routeConfigGuard: "never",
|
|
loadPlugins: "always",
|
|
hideBanner: false,
|
|
ensureCliPath: true,
|
|
});
|
|
expect(resolveCliCommandPathPolicy(["channels", "add"])).toEqual({
|
|
bypassConfigGuard: false,
|
|
routeConfigGuard: "never",
|
|
loadPlugins: "never",
|
|
hideBanner: false,
|
|
ensureCliPath: true,
|
|
});
|
|
expect(resolveCliCommandPathPolicy(["channels", "status"])).toEqual({
|
|
bypassConfigGuard: false,
|
|
routeConfigGuard: "never",
|
|
loadPlugins: "never",
|
|
hideBanner: false,
|
|
ensureCliPath: true,
|
|
});
|
|
expect(resolveCliCommandPathPolicy(["channels", "list"])).toEqual({
|
|
bypassConfigGuard: false,
|
|
routeConfigGuard: "never",
|
|
loadPlugins: "never",
|
|
hideBanner: false,
|
|
ensureCliPath: true,
|
|
});
|
|
expect(resolveCliCommandPathPolicy(["channels", "logs"])).toEqual({
|
|
bypassConfigGuard: false,
|
|
routeConfigGuard: "never",
|
|
loadPlugins: "never",
|
|
hideBanner: false,
|
|
ensureCliPath: true,
|
|
});
|
|
});
|
|
|
|
it("keeps config-only agent commands on config-only startup", () => {
|
|
for (const commandPath of [
|
|
["agents", "bind"],
|
|
["agents", "bindings"],
|
|
["agents", "unbind"],
|
|
["agents", "set-identity"],
|
|
["agents", "delete"],
|
|
]) {
|
|
expect(resolveCliCommandPathPolicy(commandPath)).toEqual({
|
|
bypassConfigGuard: false,
|
|
routeConfigGuard: "never",
|
|
loadPlugins: "never",
|
|
hideBanner: false,
|
|
ensureCliPath: true,
|
|
});
|
|
}
|
|
});
|
|
|
|
it("resolves mixed startup-only rules", () => {
|
|
expect(resolveCliCommandPathPolicy(["configure"])).toEqual({
|
|
bypassConfigGuard: true,
|
|
routeConfigGuard: "never",
|
|
loadPlugins: "never",
|
|
hideBanner: false,
|
|
ensureCliPath: true,
|
|
});
|
|
expect(resolveCliCommandPathPolicy(["config", "validate"])).toEqual({
|
|
bypassConfigGuard: true,
|
|
routeConfigGuard: "never",
|
|
loadPlugins: "never",
|
|
hideBanner: false,
|
|
ensureCliPath: true,
|
|
});
|
|
expect(resolveCliCommandPathPolicy(["gateway", "status"])).toEqual({
|
|
bypassConfigGuard: false,
|
|
routeConfigGuard: "always",
|
|
loadPlugins: "never",
|
|
hideBanner: false,
|
|
ensureCliPath: true,
|
|
});
|
|
expect(resolveCliCommandPathPolicy(["plugins", "update"])).toEqual({
|
|
bypassConfigGuard: false,
|
|
routeConfigGuard: "never",
|
|
loadPlugins: "never",
|
|
hideBanner: true,
|
|
ensureCliPath: true,
|
|
});
|
|
for (const commandPath of [
|
|
["plugins", "install"],
|
|
["plugins", "list"],
|
|
["plugins", "inspect"],
|
|
["plugins", "registry"],
|
|
["plugins", "doctor"],
|
|
]) {
|
|
expect(resolveCliCommandPathPolicy(commandPath)).toEqual({
|
|
bypassConfigGuard: false,
|
|
routeConfigGuard: "never",
|
|
loadPlugins: "never",
|
|
hideBanner: false,
|
|
ensureCliPath: true,
|
|
});
|
|
}
|
|
expect(resolveCliCommandPathPolicy(["cron", "list"])).toEqual({
|
|
bypassConfigGuard: true,
|
|
routeConfigGuard: "never",
|
|
loadPlugins: "never",
|
|
hideBanner: false,
|
|
ensureCliPath: true,
|
|
});
|
|
});
|
|
});
|