2026-02-14 00:12:15 +00:00
|
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
|
import { findRoutedCommand } from "./routes.js";
|
|
|
|
|
|
|
|
|
|
describe("program routes", () => {
|
2026-02-21 20:00:40 +00:00
|
|
|
function expectRoute(path: string[]) {
|
|
|
|
|
const route = findRoutedCommand(path);
|
2026-02-14 00:12:15 +00:00
|
|
|
expect(route).not.toBeNull();
|
2026-02-21 20:00:40 +00:00
|
|
|
return route;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function expectRunFalse(path: string[], argv: string[]) {
|
|
|
|
|
const route = expectRoute(path);
|
|
|
|
|
await expect(route?.run(argv)).resolves.toBe(false);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-01 12:55:11 -08:00
|
|
|
it("matches status route and always loads plugins for security parity", () => {
|
2026-02-21 20:00:40 +00:00
|
|
|
const route = expectRoute(["status"]);
|
2026-03-01 12:55:11 -08:00
|
|
|
expect(route?.loadPlugins).toBe(true);
|
2026-03-01 11:59:31 -08:00
|
|
|
});
|
|
|
|
|
|
2026-03-01 14:23:46 -08:00
|
|
|
it("matches health route and preloads plugins for channel diagnostics", () => {
|
2026-03-01 11:59:31 -08:00
|
|
|
const route = expectRoute(["health"]);
|
2026-03-01 14:23:46 -08:00
|
|
|
expect(route?.loadPlugins).toBe(true);
|
2026-02-14 00:12:15 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("returns false when status timeout flag value is missing", async () => {
|
2026-02-21 20:00:40 +00:00
|
|
|
await expectRunFalse(["status"], ["node", "openclaw", "status", "--timeout"]);
|
2026-02-14 00:12:15 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("returns false for sessions route when --store value is missing", async () => {
|
2026-02-21 20:00:40 +00:00
|
|
|
await expectRunFalse(["sessions"], ["node", "openclaw", "sessions", "--store"]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("returns false for sessions route when --active value is missing", async () => {
|
|
|
|
|
await expectRunFalse(["sessions"], ["node", "openclaw", "sessions", "--active"]);
|
2026-02-14 00:12:15 +00:00
|
|
|
});
|
|
|
|
|
|
2026-02-23 17:39:48 -05:00
|
|
|
it("returns false for sessions route when --agent value is missing", async () => {
|
|
|
|
|
await expectRunFalse(["sessions"], ["node", "openclaw", "sessions", "--agent"]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("does not fast-route sessions subcommands", () => {
|
|
|
|
|
expect(findRoutedCommand(["sessions", "cleanup"])).toBeNull();
|
|
|
|
|
});
|
|
|
|
|
|
2026-02-14 00:12:15 +00:00
|
|
|
it("does not match unknown routes", () => {
|
|
|
|
|
expect(findRoutedCommand(["definitely-not-real"])).toBeNull();
|
|
|
|
|
});
|
2026-02-14 00:27:30 +00:00
|
|
|
|
|
|
|
|
it("returns false for config get route when path argument is missing", async () => {
|
2026-02-21 20:00:40 +00:00
|
|
|
await expectRunFalse(["config", "get"], ["node", "openclaw", "config", "get", "--json"]);
|
2026-02-14 00:27:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("returns false for config unset route when path argument is missing", async () => {
|
2026-02-21 20:00:40 +00:00
|
|
|
await expectRunFalse(["config", "unset"], ["node", "openclaw", "config", "unset"]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("returns false for memory status route when --agent value is missing", async () => {
|
|
|
|
|
await expectRunFalse(["memory", "status"], ["node", "openclaw", "memory", "status", "--agent"]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("returns false for models list route when --provider value is missing", async () => {
|
|
|
|
|
await expectRunFalse(["models", "list"], ["node", "openclaw", "models", "list", "--provider"]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("returns false for models status route when probe flags are missing values", async () => {
|
|
|
|
|
await expectRunFalse(
|
|
|
|
|
["models", "status"],
|
|
|
|
|
["node", "openclaw", "models", "status", "--probe-provider"],
|
|
|
|
|
);
|
|
|
|
|
await expectRunFalse(
|
|
|
|
|
["models", "status"],
|
|
|
|
|
["node", "openclaw", "models", "status", "--probe-timeout"],
|
|
|
|
|
);
|
|
|
|
|
await expectRunFalse(
|
|
|
|
|
["models", "status"],
|
|
|
|
|
["node", "openclaw", "models", "status", "--probe-concurrency"],
|
|
|
|
|
);
|
|
|
|
|
await expectRunFalse(
|
|
|
|
|
["models", "status"],
|
|
|
|
|
["node", "openclaw", "models", "status", "--probe-max-tokens"],
|
|
|
|
|
);
|
|
|
|
|
await expectRunFalse(
|
|
|
|
|
["models", "status"],
|
|
|
|
|
["node", "openclaw", "models", "status", "--probe-provider", "openai", "--agent"],
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("returns false for models status route when --probe-profile has no value", async () => {
|
|
|
|
|
await expectRunFalse(
|
|
|
|
|
["models", "status"],
|
|
|
|
|
["node", "openclaw", "models", "status", "--probe-profile"],
|
|
|
|
|
);
|
2026-02-14 00:27:30 +00:00
|
|
|
});
|
2026-02-14 00:12:15 +00:00
|
|
|
});
|