Files
openclaw/src/cli/command-bootstrap.test.ts
T
Vito Cappello ab9b40daa3 fix(cli): prevent node/device RPCs from corrupting shared state (#123674)
* fix(cli): prevent node/device RPCs from corrupting shared state

* fix(cli): keep gateway RPC transport state read-only

* fix(cli): preserve doctor lint config isolation

* fix(cli): keep gateway RPC transport state read-only

* fix(gateway): keep auth preflight state read-only

* fix(cli): preserve SQLite artifacts in read-only RPCs

* fix(infra): remove stale identity store import

---------

Co-authored-by: VACInc <3279061+VACInc@users.noreply.github.com>
Co-authored-by: Patrick Erichsen <patrick.a.erichsen@gmail.com>
2026-08-16 19:40:46 -07:00

154 lines
4.5 KiB
TypeScript

// Command bootstrap tests cover CLI command bootstrap sequencing and side effects.
import { beforeEach, describe, expect, it, vi } from "vitest";
const ensureConfigReadyMock = vi.hoisted(() => vi.fn(async () => {}));
const ensureCliPluginRegistryLoadedMock = vi.hoisted(() => vi.fn(async () => {}));
vi.mock("./program/config-guard.js", () => ({
ensureConfigReady: ensureConfigReadyMock,
}));
vi.mock("./plugin-registry-loader.js", () => ({
ensureCliPluginRegistryLoaded: ensureCliPluginRegistryLoadedMock,
}));
describe("ensureCliCommandBootstrap", () => {
let ensureCliCommandBootstrap: typeof import("./command-bootstrap.js").ensureCliCommandBootstrap;
beforeEach(async () => {
vi.clearAllMocks();
vi.resetModules();
({ ensureCliCommandBootstrap } = await import("./command-bootstrap.js"));
});
it("runs config guard and plugin loading with shared options", async () => {
const runtime = {} as never;
await ensureCliCommandBootstrap({
runtime,
commandPath: ["agents", "list"],
suppressDoctorStdout: true,
allowInvalid: true,
loadPlugins: true,
});
expect(ensureConfigReadyMock).toHaveBeenCalledWith({
runtime,
commandPath: ["agents", "list"],
measure: expect.any(Function),
allowInvalid: true,
suppressDoctorStdout: true,
});
expect(ensureCliPluginRegistryLoadedMock).toHaveBeenCalledWith({
scope: "all",
routeLogsToStderr: true,
});
});
it("forwards prepared pristine migration facts to the config guard", async () => {
const runtime = {} as never;
await ensureCliCommandBootstrap({
runtime,
commandPath: ["gateway"],
loadPlugins: false,
skipPristineCoreStateMigrations: true,
skipPristineStartupStateMigrations: true,
});
expect(ensureConfigReadyMock).toHaveBeenCalledWith({
runtime,
commandPath: ["gateway"],
measure: expect.any(Function),
skipPristineCoreStateMigrations: true,
skipPristineStartupStateMigrations: true,
});
});
it("skips config guard without skipping plugin loading", async () => {
await ensureCliCommandBootstrap({
runtime: {} as never,
commandPath: ["memory", "search"],
suppressDoctorStdout: true,
skipConfigGuard: true,
loadPlugins: true,
pluginRegistry: { scope: "memory" },
});
expect(ensureConfigReadyMock).not.toHaveBeenCalled();
expect(ensureCliPluginRegistryLoadedMock).toHaveBeenCalledWith({
scope: "memory",
routeLogsToStderr: true,
});
});
it("forwards validation-only config guards without state migration", async () => {
const runtime = {} as never;
await ensureCliCommandBootstrap({
runtime,
commandPath: ["nodes", "approve"],
validateConfigOnly: true,
loadPlugins: false,
});
expect(ensureConfigReadyMock).toHaveBeenCalledWith({
runtime,
commandPath: ["nodes", "approve"],
measure: expect.any(Function),
validateConfigOnly: true,
});
});
it("loads configured channel plugins with repair enabled for operational channel commands", async () => {
await ensureCliCommandBootstrap({
runtime: {} as never,
commandPath: ["channels", "send"],
loadPlugins: true,
});
expect(ensureCliPluginRegistryLoadedMock).toHaveBeenCalledWith({
scope: "configured-channels",
routeLogsToStderr: undefined,
});
});
it("loads configured channel plugins without package-manager repair for read-only channel commands", async () => {
await ensureCliCommandBootstrap({
runtime: {} as never,
commandPath: ["channels", "resolve"],
loadPlugins: true,
});
expect(ensureCliPluginRegistryLoadedMock).toHaveBeenCalledWith({
scope: "configured-channels",
routeLogsToStderr: undefined,
});
});
it("loads agent command plugins without package-manager repair", async () => {
await ensureCliCommandBootstrap({
runtime: {} as never,
commandPath: ["agent"],
loadPlugins: true,
});
expect(ensureCliPluginRegistryLoadedMock).toHaveBeenCalledWith({
scope: "all",
routeLogsToStderr: undefined,
});
});
it("does not evaluate config or plugin runtimes for a gateway-backed agent turn", async () => {
await ensureCliCommandBootstrap({
runtime: {} as never,
commandPath: ["agent"],
skipConfigGuard: true,
loadPlugins: false,
});
expect(ensureConfigReadyMock).not.toHaveBeenCalled();
expect(ensureCliPluginRegistryLoadedMock).not.toHaveBeenCalled();
});
});