


















@@ -0,0 +1,116 @@
1+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
2+import { clearPluginLoaderCache, testing } from "../loader.js";
3+import { createEmptyPluginRegistry } from "../registry-empty.js";
4+import type { PluginRegistry } from "../registry-types.js";
5+import { resetPluginRuntimeStateForTest, setActivePluginRegistry } from "../runtime.js";
6+7+const loaderMocks = vi.hoisted(() => ({
8+loadOpenClawPlugins: vi.fn<typeof import("../loader.js").loadOpenClawPlugins>(),
9+}));
10+11+vi.mock("../loader.js", async (importOriginal) => {
12+const actual = await importOriginal<typeof import("../loader.js")>();
13+return {
14+ ...actual,
15+loadOpenClawPlugins: (...args: Parameters<typeof loaderMocks.loadOpenClawPlugins>) =>
16+loaderMocks.loadOpenClawPlugins(...args),
17+};
18+});
19+20+const { ensureStandaloneRuntimePluginRegistryLoaded } =
21+await import("./standalone-runtime-registry-loader.js");
22+23+function createRegistryWithPlugin(pluginId: string): PluginRegistry {
24+const registry = createEmptyPluginRegistry();
25+registry.plugins.push({
26+id: pluginId,
27+status: "loaded",
28+} as never);
29+return registry;
30+}
31+32+beforeEach(() => {
33+loaderMocks.loadOpenClawPlugins.mockReset();
34+});
35+36+afterEach(() => {
37+clearPluginLoaderCache();
38+resetPluginRuntimeStateForTest();
39+});
40+41+describe("ensureStandaloneRuntimePluginRegistryLoaded", () => {
42+it("reuses a compatible gateway startup registry for gateway-bindable dispatch load options", () => {
43+const activeRegistry = createRegistryWithPlugin("telegram");
44+activeRegistry.coreGatewayMethodNames = ["sessions.get", "sessions.list"];
45+const config = { plugins: { allow: ["telegram"] } };
46+const startupLoadOptions = {
47+ config,
48+activationSourceConfig: config,
49+autoEnabledReasons: {},
50+workspaceDir: "/tmp/ws",
51+onlyPluginIds: ["telegram"],
52+coreGatewayMethodNames: ["sessions.get", "sessions.list"],
53+runtimeOptions: {
54+allowGatewaySubagentBinding: true,
55+},
56+preferBuiltPluginArtifacts: true,
57+};
58+const { cacheKey } = testing.resolvePluginLoadCacheContext(startupLoadOptions);
59+setActivePluginRegistry(activeRegistry, cacheKey, "gateway-bindable", "/tmp/ws");
60+61+const result = ensureStandaloneRuntimePluginRegistryLoaded({
62+loadOptions: {
63+ config,
64+onlyPluginIds: ["telegram"],
65+runtimeOptions: {
66+allowGatewaySubagentBinding: true,
67+},
68+workspaceDir: "/tmp/ws",
69+},
70+});
71+72+expect(result).toBe(activeRegistry);
73+expect(loaderMocks.loadOpenClawPlugins).not.toHaveBeenCalled();
74+});
75+76+it("loads a fresh registry when dispatch config is not startup-compatible", () => {
77+const activeRegistry = createRegistryWithPlugin("telegram");
78+activeRegistry.coreGatewayMethodNames = ["sessions.get", "sessions.list"];
79+const config = { plugins: { allow: ["telegram"] } };
80+const startupLoadOptions = {
81+ config,
82+activationSourceConfig: config,
83+autoEnabledReasons: {},
84+workspaceDir: "/tmp/ws",
85+onlyPluginIds: ["telegram"],
86+coreGatewayMethodNames: ["sessions.get", "sessions.list"],
87+runtimeOptions: {
88+allowGatewaySubagentBinding: true,
89+},
90+preferBuiltPluginArtifacts: true,
91+};
92+const { cacheKey } = testing.resolvePluginLoadCacheContext(startupLoadOptions);
93+setActivePluginRegistry(activeRegistry, cacheKey, "gateway-bindable", "/tmp/ws");
94+const loadedRegistry = createRegistryWithPlugin("telegram");
95+loaderMocks.loadOpenClawPlugins.mockReturnValue(loadedRegistry);
96+97+const result = ensureStandaloneRuntimePluginRegistryLoaded({
98+loadOptions: {
99+config: {
100+plugins: {
101+allow: ["telegram"],
102+load: { paths: ["/tmp/changed.js"] },
103+},
104+},
105+onlyPluginIds: ["telegram"],
106+runtimeOptions: {
107+allowGatewaySubagentBinding: true,
108+},
109+workspaceDir: "/tmp/ws",
110+},
111+});
112+113+expect(result).toBe(loadedRegistry);
114+expect(loaderMocks.loadOpenClawPlugins).toHaveBeenCalledOnce();
115+});
116+});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。