






















@@ -2,12 +2,16 @@ import { afterEach, describe, expect, it } from "vitest";
22import { createEmptyPluginRegistry } from "../plugins/registry-empty.js";
33import {
44pinActivePluginChannelRegistry,
5+getActivePluginChannelRegistryVersion,
56resetPluginRuntimeStateForTest,
67setActivePluginRegistry,
78} from "../plugins/runtime.js";
9+import { createTestRegistry } from "../test-utils/channel-plugins.js";
810import { listChatChannels } from "./chat-meta.js";
11+import { normalizeAnyChannelId as normalizeAnyChannelIdLight } from "./registry-normalize.js";
912import {
1013formatChannelSelectionLine,
14+getRegisteredChannelPluginMeta,
1115listRegisteredChannelPluginIds,
1216normalizeAnyChannelId,
1317} from "./registry.js";
@@ -32,6 +36,16 @@ describe("channel registry helpers", () => {
3236return label ?? path ?? "";
3337}
343839+function createRegistryWithRegisteredChannel(id: string, aliases: string[] = []) {
40+return createTestRegistry([
41+{
42+pluginId: id,
43+plugin: { id, meta: { aliases } },
44+source: "test",
45+},
46+]);
47+}
48+3549it("keeps Feishu first in the current default order", () => {
3650const channels = listChatChannels();
3751expect(channels[0]?.id).toBe("feishu");
@@ -53,47 +67,62 @@ describe("channel registry helpers", () => {
5367});
54685569it("prefers the pinned channel registry when resolving registered plugin channels", () => {
56-const startupRegistry = createEmptyPluginRegistry();
57-startupRegistry.channels = [
58-{
59-pluginId: "openclaw-weixin",
60-plugin: { id: "openclaw-weixin", meta: { aliases: ["weixin"] } },
61-source: "test",
62-},
63-] as never;
70+const startupRegistry = createRegistryWithRegisteredChannel("openclaw-weixin", ["weixin"]);
6471setActivePluginRegistry(startupRegistry);
6572pinActivePluginChannelRegistry(startupRegistry);
667367-const replacementRegistry = createEmptyPluginRegistry();
68-replacementRegistry.channels = [
69-{
70-pluginId: "qqbot",
71-plugin: { id: "qqbot", meta: { aliases: ["qq"] } },
72-source: "test",
73-},
74-] as never;
74+const replacementRegistry = createRegistryWithRegisteredChannel("qqbot", ["qq"]);
7575setActivePluginRegistry(replacementRegistry);
76767777expect(listRegisteredChannelPluginIds()).toEqual(["openclaw-weixin"]);
7878expect(normalizeAnyChannelId("weixin")).toBe("openclaw-weixin");
79+expect(getRegisteredChannelPluginMeta("OPENCLAW-WEIXIN")?.aliases).toEqual(["weixin"]);
7980});
80818182it("falls back to the active registry when the pinned channel registry has no channels", () => {
8283const startupRegistry = createEmptyPluginRegistry();
8384setActivePluginRegistry(startupRegistry);
8485pinActivePluginChannelRegistry(startupRegistry);
858686-const replacementRegistry = createEmptyPluginRegistry();
87-replacementRegistry.channels = [
88-{
89-pluginId: "qqbot",
90-plugin: { id: "qqbot", meta: { aliases: ["qq"] } },
91-source: "test",
92-},
93-] as never;
87+const replacementRegistry = createRegistryWithRegisteredChannel("qqbot", ["qq"]);
9488setActivePluginRegistry(replacementRegistry);
95899690expect(listRegisteredChannelPluginIds()).toEqual(["qqbot"]);
9791expect(normalizeAnyChannelId("qq")).toBe("qqbot");
9892});
93+94+it("rebuilds registered channel lookups when pinned-empty fallback active registry changes", () => {
95+const startupRegistry = createEmptyPluginRegistry();
96+setActivePluginRegistry(startupRegistry);
97+pinActivePluginChannelRegistry(startupRegistry);
98+99+const alphaRegistry = createRegistryWithRegisteredChannel("alpha", ["a"]);
100+setActivePluginRegistry(alphaRegistry);
101+102+const channelVersion = getActivePluginChannelRegistryVersion();
103+expect(normalizeAnyChannelId("a")).toBe("alpha");
104+expect(normalizeAnyChannelIdLight("a")).toBe("alpha");
105+106+const betaRegistry = createRegistryWithRegisteredChannel("beta", ["b"]);
107+setActivePluginRegistry(betaRegistry);
108+109+expect(getActivePluginChannelRegistryVersion()).not.toBe(channelVersion);
110+expect(normalizeAnyChannelId("a")).toBeNull();
111+expect(normalizeAnyChannelId("b")).toBe("beta");
112+expect(normalizeAnyChannelIdLight("a")).toBeNull();
113+expect(normalizeAnyChannelIdLight("b")).toBe("beta");
114+});
115+116+it("refreshes registered channel lookups when selected registry channels grow in place", () => {
117+const registry = createEmptyPluginRegistry();
118+setActivePluginRegistry(registry);
119+120+expect(normalizeAnyChannelId("a")).toBeNull();
121+expect(normalizeAnyChannelIdLight("a")).toBeNull();
122+123+registry.channels.push(createRegistryWithRegisteredChannel("alpha", ["a"]).channels[0]);
124+125+expect(normalizeAnyChannelId("a")).toBe("alpha");
126+expect(normalizeAnyChannelIdLight("a")).toBe("alpha");
127+});
99128});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。