Files
openclaw/src/cli/program/routes.test.ts
Vincent Koc 38da2d076c CLI: add root --help fast path and lazy channel option resolution (#30975)
* CLI argv: add strict root help invocation guard

* Entry: add root help fast-path bootstrap bypass

* CLI context: lazily resolve channel options

* CLI context tests: cover lazy channel option resolution

* CLI argv tests: cover root help invocation detection

* Changelog: note additional startup path optimizations

* Changelog: split startup follow-up into #30975 entry

* CLI channel options: load precomputed startup metadata

* CLI channel options tests: cover precomputed metadata path

* Build: generate CLI startup metadata during build

* Build script: invoke CLI startup metadata generator

* CLI routes: preload plugins for routed health

* CLI routes tests: assert health plugin preload

* CLI: add experimental bundled entry and snapshot helper

* Tools: compare CLI startup entries in benchmark script

* Docs: add startup tuning notes for Pi and VM hosts

* CLI: drop bundled entry runtime toggle

* Build: remove bundled and snapshot scripts

* Tools: remove bundled-entry benchmark shortcut

* Docs: remove bundled startup bench examples

* Docs: remove Pi bundled entry mention

* Docs: remove VM bundled entry mention

* Changelog: remove bundled startup follow-up claims

* Build: remove snapshot helper script

* Build: remove CLI bundle tsdown config

* Doctor: add low-power startup optimization hints

* Doctor: run startup optimization hint checks

* Doctor tests: cover startup optimization host targeting

* Doctor tests: mock startup optimization note export

* CLI argv: require strict root-only help fast path

* CLI argv tests: cover mixed root-help invocations

* CLI channel options: merge metadata with runtime catalog

* CLI channel options tests: assert dynamic catalog merge

* Changelog: align #30975 startup follow-up scope

* Docs tests: remove secondary-entry startup bench note

* Docs Pi: add systemd recovery reference link

* Docs VPS: add systemd recovery reference link
2026-03-01 14:23:46 -08:00

96 lines
3.4 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { findRoutedCommand } from "./routes.js";
describe("program routes", () => {
function expectRoute(path: string[]) {
const route = findRoutedCommand(path);
expect(route).not.toBeNull();
return route;
}
async function expectRunFalse(path: string[], argv: string[]) {
const route = expectRoute(path);
await expect(route?.run(argv)).resolves.toBe(false);
}
it("matches status route and always loads plugins for security parity", () => {
const route = expectRoute(["status"]);
expect(route?.loadPlugins).toBe(true);
});
it("matches health route and preloads plugins for channel diagnostics", () => {
const route = expectRoute(["health"]);
expect(route?.loadPlugins).toBe(true);
});
it("returns false when status timeout flag value is missing", async () => {
await expectRunFalse(["status"], ["node", "openclaw", "status", "--timeout"]);
});
it("returns false for sessions route when --store value is missing", async () => {
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"]);
});
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();
});
it("does not match unknown routes", () => {
expect(findRoutedCommand(["definitely-not-real"])).toBeNull();
});
it("returns false for config get route when path argument is missing", async () => {
await expectRunFalse(["config", "get"], ["node", "openclaw", "config", "get", "--json"]);
});
it("returns false for config unset route when path argument is missing", async () => {
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"],
);
});
});