mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 16:40:42 +00:00
88 lines
2.7 KiB
TypeScript
88 lines
2.7 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
const hoisted = vi.hoisted(() => ({
|
|
resolveRuntimePluginRegistry: vi.fn(),
|
|
getActivePluginRuntimeSubagentMode: vi.fn<() => "default" | "explicit" | "gateway-bindable">(
|
|
() => "default",
|
|
),
|
|
}));
|
|
|
|
vi.mock("../plugins/loader.js", () => ({
|
|
resolveRuntimePluginRegistry: hoisted.resolveRuntimePluginRegistry,
|
|
}));
|
|
|
|
vi.mock("../plugins/runtime.js", () => ({
|
|
getActivePluginRuntimeSubagentMode: hoisted.getActivePluginRuntimeSubagentMode,
|
|
}));
|
|
|
|
describe("ensureRuntimePluginsLoaded", () => {
|
|
let ensureRuntimePluginsLoaded: typeof import("./runtime-plugins.js").ensureRuntimePluginsLoaded;
|
|
|
|
beforeEach(async () => {
|
|
hoisted.resolveRuntimePluginRegistry.mockReset();
|
|
hoisted.resolveRuntimePluginRegistry.mockReturnValue(undefined);
|
|
hoisted.getActivePluginRuntimeSubagentMode.mockReset();
|
|
hoisted.getActivePluginRuntimeSubagentMode.mockReturnValue("default");
|
|
vi.resetModules();
|
|
({ ensureRuntimePluginsLoaded } = await import("./runtime-plugins.js"));
|
|
});
|
|
|
|
it("does not reactivate plugins when a process already has an active registry", async () => {
|
|
hoisted.resolveRuntimePluginRegistry.mockReturnValue({});
|
|
|
|
ensureRuntimePluginsLoaded({
|
|
config: {} as never,
|
|
workspaceDir: "/tmp/workspace",
|
|
allowGatewaySubagentBinding: true,
|
|
});
|
|
|
|
expect(hoisted.resolveRuntimePluginRegistry).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it("resolves runtime plugins through the shared runtime helper", async () => {
|
|
ensureRuntimePluginsLoaded({
|
|
config: {} as never,
|
|
workspaceDir: "/tmp/workspace",
|
|
allowGatewaySubagentBinding: true,
|
|
});
|
|
|
|
expect(hoisted.resolveRuntimePluginRegistry).toHaveBeenCalledWith({
|
|
config: {} as never,
|
|
workspaceDir: "/tmp/workspace",
|
|
runtimeOptions: {
|
|
allowGatewaySubagentBinding: true,
|
|
},
|
|
});
|
|
});
|
|
|
|
it("does not enable gateway subagent binding for normal runtime loads", async () => {
|
|
ensureRuntimePluginsLoaded({
|
|
config: {} as never,
|
|
workspaceDir: "/tmp/workspace",
|
|
});
|
|
|
|
expect(hoisted.resolveRuntimePluginRegistry).toHaveBeenCalledWith({
|
|
config: {} as never,
|
|
workspaceDir: "/tmp/workspace",
|
|
runtimeOptions: undefined,
|
|
});
|
|
});
|
|
|
|
it("inherits gateway-bindable mode from an active gateway registry", async () => {
|
|
hoisted.getActivePluginRuntimeSubagentMode.mockReturnValue("gateway-bindable");
|
|
|
|
ensureRuntimePluginsLoaded({
|
|
config: {} as never,
|
|
workspaceDir: "/tmp/workspace",
|
|
});
|
|
|
|
expect(hoisted.resolveRuntimePluginRegistry).toHaveBeenCalledWith({
|
|
config: {} as never,
|
|
workspaceDir: "/tmp/workspace",
|
|
runtimeOptions: {
|
|
allowGatewaySubagentBinding: true,
|
|
},
|
|
});
|
|
});
|
|
});
|