Skip to content

Commit ccee629

Browse files
authored
refactor(plugins): delete registry compat scaffolding (#117749)
* refactor(plugins): delete registry compat scaffolding * test(plugins): update CLI registry handle mock * fix(plugins): preserve explicitly initialized hook registries * test(plugins): update registry ownership fixtures * fix(channels): restore registry snapshot memo
1 parent a084763 commit ccee629

129 files changed

Lines changed: 1645 additions & 6688 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎extensions/feishu/src/outbound-delivery.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { sendDurableMessageBatch } from "openclaw/plugin-sdk/channel-outbound";
33
import {
44
createOutboundTestPlugin,
55
createTestRegistry,
6-
releasePinnedPluginChannelRegistry,
6+
resetPluginRuntimeStateForTest,
77
resetGlobalHookRunner,
88
setActivePluginRegistry,
99
} from "openclaw/plugin-sdk/channel-test-helpers";
@@ -56,7 +56,7 @@ describe("Feishu outbound shared delivery", () => {
5656

5757
afterEach(() => {
5858
resetGlobalHookRunner();
59-
releasePinnedPluginChannelRegistry();
59+
resetPluginRuntimeStateForTest();
6060
});
6161

6262
it("routes oversized presentation media through one media send and chunked fallback text", async () => {

‎extensions/imessage/src/test-plugin.test.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from "openclaw/plugin-sdk/channel-outbound";
1111
import {
1212
createTestRegistry,
13-
releasePinnedPluginChannelRegistry,
13+
resetPluginRuntimeStateForTest,
1414
setActivePluginRegistry,
1515
} from "openclaw/plugin-sdk/channel-test-helpers";
1616
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
@@ -483,7 +483,7 @@ describe("createIMessageTestPlugin", () => {
483483
expect(runCliJson).toHaveBeenCalledTimes(1);
484484
});
485485
} finally {
486-
releasePinnedPluginChannelRegistry();
486+
resetPluginRuntimeStateForTest();
487487
}
488488
});
489489

@@ -539,7 +539,7 @@ describe("createIMessageTestPlugin", () => {
539539
expect(captionRequest).not.toHaveBeenCalled();
540540
});
541541
} finally {
542-
releasePinnedPluginChannelRegistry();
542+
resetPluginRuntimeStateForTest();
543543
}
544544
});
545545

‎extensions/mattermost/src/outbound-delivery.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
createEmptyPluginRegistry,
66
createTestRegistry,
77
initializeGlobalHookRunner,
8-
releasePinnedPluginChannelRegistry,
8+
resetPluginRuntimeStateForTest,
99
resetGlobalHookRunner,
1010
setActivePluginRegistry,
1111
type PluginHookRegistration,
@@ -40,7 +40,7 @@ describe("Mattermost outbound delivery", () => {
4040

4141
afterEach(() => {
4242
resetGlobalHookRunner();
43-
releasePinnedPluginChannelRegistry();
43+
resetPluginRuntimeStateForTest();
4444
});
4545

4646
it.each([

‎extensions/slack/src/outbound-delivery.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
createOutboundTestPlugin,
77
createTestRegistry,
88
initializeGlobalHookRunner,
9-
releasePinnedPluginChannelRegistry,
9+
resetPluginRuntimeStateForTest,
1010
resetGlobalHookRunner,
1111
setActivePluginRegistry,
1212
type PluginHookRegistration,
@@ -54,7 +54,7 @@ describe("slack outbound shared hook wiring", () => {
5454

5555
afterEach(() => {
5656
resetGlobalHookRunner();
57-
releasePinnedPluginChannelRegistry();
57+
resetPluginRuntimeStateForTest();
5858
});
5959

6060
it("fires message_sending once with shared routing fields", async () => {

‎extensions/tlon/src/outbound-tool-trace-sanitize.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { expectDefined } from "@openclaw/normalization-core";
66
import { sendDurableMessageBatch } from "openclaw/plugin-sdk/channel-outbound";
77
import {
88
createTestRegistry,
9-
releasePinnedPluginChannelRegistry,
9+
resetPluginRuntimeStateForTest,
1010
setActivePluginRegistry,
1111
} from "openclaw/plugin-sdk/channel-test-helpers";
1212
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
@@ -82,7 +82,7 @@ describe("tlon outbound assistant-visible sanitization", () => {
8282
});
8383

8484
afterEach(async () => {
85-
releasePinnedPluginChannelRegistry();
85+
resetPluginRuntimeStateForTest();
8686
vi.restoreAllMocks();
8787
server.closeAllConnections();
8888
await new Promise<void>((resolve, reject) => {

‎extensions/whatsapp/src/send.delivery-recovery.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
createEmptyPluginRegistry,
55
createOutboundTestPlugin,
66
createTestRegistry,
7-
releasePinnedPluginChannelRegistry,
7+
resetPluginRuntimeStateForTest,
88
setActivePluginRegistry,
99
} from "openclaw/plugin-sdk/channel-test-helpers";
1010
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
@@ -70,7 +70,7 @@ describe("WhatsApp delivery recovery", () => {
7070

7171
afterEach(() => {
7272
runtimeContextMocks.controllers.clear();
73-
releasePinnedPluginChannelRegistry();
73+
resetPluginRuntimeStateForTest();
7474
setActivePluginRegistry(createEmptyPluginRegistry());
7575
});
7676

‎src/agents/agent-tools.before-tool-call.embedded-mode.test.ts‎

Lines changed: 2 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,10 @@ import {
1212
EmbeddedPluginApprovalBroker,
1313
setEmbeddedPluginApprovalBroker,
1414
} from "../infra/embedded-plugin-approval-broker.js";
15-
import {
16-
getGlobalHookRunner,
17-
initializeGlobalHookRunner,
18-
resetGlobalHookRunner,
19-
} from "../plugins/hook-runner-global.js";
15+
import { getGlobalHookRunner, resetGlobalHookRunner } from "../plugins/hook-runner-global.js";
2016
import type { HookRunner } from "../plugins/hooks.js";
2117
import { createEmptyPluginRegistry } from "../plugins/registry-empty.js";
22-
import {
23-
pinActivePluginChannelRegistry,
24-
releasePinnedPluginChannelRegistry,
25-
setActivePluginRegistry,
26-
} from "../plugins/runtime.js";
18+
import { setActivePluginRegistry } from "../plugins/runtime.js";
2719
import { PluginApprovalResolutions } from "../plugins/types.js";
2820
import { runBeforeToolCallHook } from "./agent-tools.before-tool-call.js";
2921
import { callGatewayTool } from "./tools/gateway.js";
@@ -711,94 +703,6 @@ describe("runBeforeToolCallHook — embedded mode approvals", () => {
711703
expect(runBeforeToolCallMock).not.toHaveBeenCalled();
712704
});
713705

714-
it("runs trusted policies from the global hook registry after the active registry changes", async () => {
715-
const evaluatePolicy = vi.fn(() => ({
716-
block: true,
717-
blockReason: "gateway registry policy blocked",
718-
}));
719-
const gatewayRegistry = createEmptyPluginRegistry();
720-
gatewayRegistry.trustedToolPolicies = [
721-
{
722-
pluginId: "gateway-policy",
723-
pluginName: "Gateway Policy",
724-
source: "test",
725-
policy: {
726-
id: "gateway-block",
727-
description: "Gateway policy",
728-
evaluate: evaluatePolicy,
729-
},
730-
},
731-
];
732-
initializeGlobalHookRunner(gatewayRegistry);
733-
setActivePluginRegistry(createEmptyPluginRegistry());
734-
runBeforeToolCallMock.mockResolvedValue(undefined);
735-
736-
const result = await runBeforeToolCallHook({
737-
toolName: "bash",
738-
params: { command: "deploy" },
739-
toolCallId: "call-gateway-policy",
740-
ctx: { agentId: "main", sessionKey: "main" },
741-
});
742-
743-
expect(result).toEqual({
744-
blocked: true,
745-
kind: "veto",
746-
deniedReason: "plugin-before-tool-call",
747-
reason: "gateway registry policy blocked",
748-
params: { command: "deploy" },
749-
});
750-
expect(evaluatePolicy).toHaveBeenCalledTimes(1);
751-
expect(runBeforeToolCallMock).not.toHaveBeenCalled();
752-
});
753-
754-
it("runs pinned gateway trusted policies after a later global runner initialization", async () => {
755-
const evaluatePolicy = vi.fn(() => ({
756-
block: true,
757-
blockReason: "pinned gateway policy blocked",
758-
}));
759-
const gatewayRegistry = createEmptyPluginRegistry();
760-
gatewayRegistry.trustedToolPolicies = [
761-
{
762-
pluginId: "gateway-policy",
763-
pluginName: "Gateway Policy",
764-
source: "test",
765-
policy: {
766-
id: "gateway-block",
767-
description: "Gateway policy",
768-
evaluate: evaluatePolicy,
769-
},
770-
},
771-
];
772-
setActivePluginRegistry(gatewayRegistry);
773-
initializeGlobalHookRunner(gatewayRegistry);
774-
pinActivePluginChannelRegistry(gatewayRegistry);
775-
try {
776-
const laterRegistry = createEmptyPluginRegistry();
777-
setActivePluginRegistry(laterRegistry);
778-
initializeGlobalHookRunner(laterRegistry);
779-
runBeforeToolCallMock.mockResolvedValue(undefined);
780-
781-
const result = await runBeforeToolCallHook({
782-
toolName: "bash",
783-
params: { command: "deploy" },
784-
toolCallId: "call-pinned-gateway-policy",
785-
ctx: { agentId: "main", sessionKey: "main" },
786-
});
787-
788-
expect(result).toEqual({
789-
blocked: true,
790-
kind: "veto",
791-
deniedReason: "plugin-before-tool-call",
792-
reason: "pinned gateway policy blocked",
793-
params: { command: "deploy" },
794-
});
795-
expect(evaluatePolicy).toHaveBeenCalledTimes(1);
796-
expect(runBeforeToolCallMock).not.toHaveBeenCalled();
797-
} finally {
798-
releasePinnedPluginChannelRegistry(gatewayRegistry);
799-
}
800-
});
801-
802706
it("does not require skill_workshop lifecycle approval by default", async () => {
803707
(hookRunner.hasHooks as ReturnType<typeof vi.fn>).mockReturnValue(false);
804708

‎src/agents/conversation-capability-profile.test.ts‎

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import fs from "node:fs";
22
import os from "node:os";
33
import path from "node:path";
4-
import { afterAll, beforeAll, describe, expect, it } from "vitest";
4+
import { beforeEach, describe, expect, it } from "vitest";
55
import { createAccountListHelpers } from "../channels/plugins/account-helpers.js";
66
import { replaceSessionEntry } from "../config/sessions/session-accessor.js";
77
import type { SessionEntry } from "../config/sessions/types.js";
88
import type { OpenClawConfig } from "../config/types.openclaw.js";
99
import { createAccountCronScheduledToolPolicy } from "../cron/scheduled-tool-policy.js";
10-
import { PLUGIN_REGISTRY_STATE } from "../plugins/runtime-state-key.js";
10+
import { setActivePluginRegistry } from "../plugins/runtime.js";
11+
import { createTestRegistry } from "../test-utils/channel-plugins.js";
1112
import { INTERNAL_MESSAGE_CHANNEL } from "../utils/message-channel.js";
1213
import { resolveConversationCapabilityProfile } from "./conversation-capability-profile.js";
1314
import { isToolAllowedByPolicyName } from "./tool-policy-match.js";
@@ -382,31 +383,21 @@ describe("resolveConversationCapabilityProfile", () => {
382383

383384
describe("resolveConversationCapabilityProfile scheduled account authority", () => {
384385
const ownerSessionKey = "agent:main:whatsapp:group:safe-room";
385-
const globalState = globalThis as Record<symbol, unknown>;
386-
let previousRegistryState: unknown;
387386

388-
beforeAll(() => {
389-
previousRegistryState = globalState[PLUGIN_REGISTRY_STATE];
390-
globalState[PLUGIN_REGISTRY_STATE] = {
391-
channel: {
392-
version: 1,
393-
registry: {
394-
channels: [
395-
{
396-
plugin: {
397-
id: "whatsapp",
398-
meta: {},
399-
config: createAccountListHelpers("whatsapp"),
400-
},
401-
},
402-
],
387+
beforeEach(() => {
388+
setActivePluginRegistry(
389+
createTestRegistry([
390+
{
391+
pluginId: "whatsapp",
392+
source: "test",
393+
plugin: {
394+
id: "whatsapp",
395+
meta: {},
396+
config: createAccountListHelpers("whatsapp"),
397+
},
403398
},
404-
},
405-
};
406-
});
407-
408-
afterAll(() => {
409-
globalState[PLUGIN_REGISTRY_STATE] = previousRegistryState;
399+
]),
400+
);
410401
});
411402

412403
function scheduledProfile(accounts: Record<string, unknown>) {

‎src/agents/harness/native-hook-relay-events.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ export function nativeHookRelayEventToolMatcher(
8080
if (nativePreToolUseMayRunLoopDetection(registration)) {
8181
return undefined;
8282
}
83-
// Relay selection and policy execution must read the same composed registry
84-
// so active, pinned, and isolated plugin sources cannot diverge.
83+
// Relay selection and policy execution must read the same scoped/root registry.
8584
const policyRegistry = getGlobalHookRunnerRegistry();
8685
const scope = mergePluginToolMatcherScopes([
8786
getGlobalToolHookMatcherScope("before_tool_call"),

0 commit comments

Comments
 (0)