Files
openclaw/src/cli/plugin-registry-loader.test.ts
Peter Steinberger 250376f885 fix: simplify bundled runtime dependency repair (#75183)
Summary:
- Merged fix: simplify bundled runtime dependency repair after ClawSweeper review.

ClawSweeper fixups:
- Included follow-up commit: fix: verify cached bundled runtime roots
- Included follow-up commit: refactor: simplify plugin runtime startup paths
- Included follow-up commit: refactor: trim plugin startup policy helpers
- Included follow-up commit: refactor: trust package manager runtime deps materialization
- Included follow-up commit: fix: narrow channel runtime deps skip policy
- Included follow-up commit: refactor: defer startup plugin runtime deps
- Ran the ClawSweeper repair loop before final review.

Validation:
- ClawSweeper review passed for head 04dc566534.
- Required merge gates passed before the squash merge.

Prepared head SHA: 04dc566534
Review: https://github.com/openclaw/openclaw/pull/75183#issuecomment-4358383786

Co-authored-by: Peter Steinberger <steipete@gmail.com>
Co-authored-by: Shakker <shakkerdroid@gmail.com>
Co-authored-by: clawsweeper-repair <clawsweeper-repair@users.noreply.github.com>
2026-05-01 07:49:02 +00:00

90 lines
2.8 KiB
TypeScript

import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
const ensurePluginRegistryLoadedMock = vi.hoisted(() => vi.fn());
vi.mock("./plugin-registry.js", () => ({
ensurePluginRegistryLoaded: ensurePluginRegistryLoadedMock,
}));
describe("plugin-registry-loader", () => {
let originalForceStderr: boolean;
let ensureCliPluginRegistryLoaded: typeof import("./plugin-registry-loader.js").ensureCliPluginRegistryLoaded;
let loggingState: typeof import("../logging/state.js").loggingState;
beforeAll(async () => {
({ ensureCliPluginRegistryLoaded } = await import("./plugin-registry-loader.js"));
({ loggingState } = await import("../logging/state.js"));
});
beforeEach(() => {
vi.clearAllMocks();
originalForceStderr = loggingState.forceConsoleToStderr;
loggingState.forceConsoleToStderr = false;
});
afterEach(() => {
loggingState.forceConsoleToStderr = originalForceStderr;
});
it("routes plugin load logs to stderr and restores state", async () => {
const captured: boolean[] = [];
ensurePluginRegistryLoadedMock.mockImplementation(() => {
captured.push(loggingState.forceConsoleToStderr);
});
await ensureCliPluginRegistryLoaded({
scope: "configured-channels",
routeLogsToStderr: true,
});
expect(ensurePluginRegistryLoadedMock).toHaveBeenCalledWith({
scope: "configured-channels",
});
expect(captured).toEqual([true]);
expect(loggingState.forceConsoleToStderr).toBe(false);
});
it("keeps stdout routing unchanged when stderr routing is not requested", async () => {
const captured: boolean[] = [];
ensurePluginRegistryLoadedMock.mockImplementation(() => {
captured.push(loggingState.forceConsoleToStderr);
});
await ensureCliPluginRegistryLoaded({
scope: "all",
});
expect(captured).toEqual([false]);
expect(loggingState.forceConsoleToStderr).toBe(false);
});
it("forwards explicit config snapshots to plugin loading", async () => {
const config = { channels: { quietchat: { enabled: true } } } as never;
const activationSourceConfig = { channels: { quietchat: { enabled: true } } } as never;
await ensureCliPluginRegistryLoaded({
scope: "configured-channels",
config,
activationSourceConfig,
});
expect(ensurePluginRegistryLoadedMock).toHaveBeenCalledWith({
scope: "configured-channels",
config,
activationSourceConfig,
});
});
it("forwards explicit runtime dependency install policy", async () => {
await ensureCliPluginRegistryLoaded({
scope: "configured-channels",
installBundledRuntimeDeps: false,
});
expect(ensurePluginRegistryLoadedMock).toHaveBeenCalledWith({
scope: "configured-channels",
installBundledRuntimeDeps: false,
});
});
});