



























@@ -23,7 +23,11 @@ import {
2323} from "../tasks/detached-task-runtime-state.js";
2424import { withEnv } from "../test-utils/env.js";
2525import { clearPluginCommands, getPluginCommandSpecs } from "./command-registry-state.js";
26-import { getGlobalHookRunner, resetGlobalHookRunner } from "./hook-runner-global.js";
26+import {
27+getGlobalHookRunner,
28+getGlobalPluginRegistry,
29+resetGlobalHookRunner,
30+} from "./hook-runner-global.js";
2731import { createHookRunner } from "./hooks.js";
2832import {
2933clearPluginInteractiveHandlerRegistrations,
@@ -3594,6 +3598,66 @@ module.exports = { id: "throws-after-import", register() {} };`,
35943598resetGlobalHookRunner();
35953599});
359636003601+it("preserves the gateway-bindable hook runner across later default-mode activating loads", () => {
3602+useNoBundledPlugins();
3603+const gatewayPlugin = writePlugin({
3604+id: "gateway-hook-surface",
3605+filename: "gateway-hook-surface.cjs",
3606+body: `module.exports = { id: "gateway-hook-surface", register(api) {
3607+ api.on("subagent_ended", () => undefined);
3608+ } };`,
3609+});
3610+const defaultPlugin = writePlugin({
3611+id: "default-hook-surface",
3612+filename: "default-hook-surface.cjs",
3613+body: `module.exports = { id: "default-hook-surface", register(api) {
3614+ api.on("message_sent", () => undefined);
3615+ } };`,
3616+});
3617+3618+const gatewayRegistry = loadOpenClawPlugins({
3619+workspaceDir: gatewayPlugin.dir,
3620+config: {
3621+plugins: {
3622+load: { paths: [gatewayPlugin.file] },
3623+allow: ["gateway-hook-surface"],
3624+entries: {
3625+"gateway-hook-surface": {
3626+enabled: true,
3627+hooks: { allowConversationAccess: true },
3628+},
3629+},
3630+},
3631+},
3632+runtimeOptions: {
3633+allowGatewaySubagentBinding: true,
3634+},
3635+});
3636+expect(getGlobalPluginRegistry()).toBe(gatewayRegistry);
3637+expect(getGlobalHookRunner()?.hasHooks("subagent_ended")).toBe(true);
3638+3639+const defaultRegistry = loadOpenClawPlugins({
3640+workspaceDir: defaultPlugin.dir,
3641+config: {
3642+plugins: {
3643+load: { paths: [defaultPlugin.file] },
3644+allow: ["default-hook-surface"],
3645+entries: {
3646+"default-hook-surface": {
3647+enabled: true,
3648+hooks: { allowConversationAccess: true },
3649+},
3650+},
3651+},
3652+},
3653+});
3654+3655+expect(getActivePluginRegistry()).toBe(defaultRegistry);
3656+expect(getGlobalPluginRegistry()).toBe(gatewayRegistry);
3657+expect(getGlobalHookRunner()?.hasHooks("subagent_ended")).toBe(true);
3658+expect(getGlobalHookRunner()?.hasHooks("message_sent")).toBe(false);
3659+});
3660+35973661it.each([
35983662{
35993663name: "does not reuse cached bundled plugin registries across env changes",
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。