

























@@ -1,4 +1,5 @@
11import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
2+import { getBundledChannelSetupPlugin } from "../channels/plugins/bundled.js";
23import type { ChannelPluginCatalogEntry } from "../channels/plugins/catalog.js";
34import type { ChannelPlugin } from "../channels/plugins/types.js";
45import type { OpenClawConfig } from "../config/types.openclaw.js";
@@ -41,6 +42,11 @@ const pluginInstallRecordCommitMocks = vi.hoisted(() => ({
4142commitConfigWithPendingPluginInstalls: vi.fn(),
4243}));
434445+const bundledMocks = vi.hoisted(() => ({
46+getBundledChannelPlugin: vi.fn(() => undefined),
47+getBundledChannelSetupPlugin: vi.fn(() => undefined),
48+}));
49+4450vi.mock("../channels/plugins/catalog.js", () => ({
4551getChannelPluginCatalogEntry: catalogMocks.getChannelPluginCatalogEntry,
4652listChannelPluginCatalogEntries: catalogMocks.listChannelPluginCatalogEntries,
@@ -56,7 +62,8 @@ vi.mock("../channels/plugins/bundled.js", async () => {
5662);
5763return {
5864 ...actual,
59-getBundledChannelPlugin: vi.fn(() => undefined),
65+getBundledChannelPlugin: bundledMocks.getBundledChannelPlugin,
66+getBundledChannelSetupPlugin: bundledMocks.getBundledChannelSetupPlugin,
6067};
6168});
6269@@ -287,6 +294,10 @@ describe("channelsAddCommand", () => {
287294catalogMocks.listChannelPluginCatalogEntries.mockReturnValue([]);
288295discoveryMocks.isCatalogChannelInstalled.mockClear();
289296discoveryMocks.isCatalogChannelInstalled.mockReturnValue(false);
297+bundledMocks.getBundledChannelPlugin.mockReset();
298+bundledMocks.getBundledChannelPlugin.mockReturnValue(undefined);
299+bundledMocks.getBundledChannelSetupPlugin.mockReset();
300+bundledMocks.getBundledChannelSetupPlugin.mockReturnValue(undefined);
290301vi.mocked(ensureChannelSetupPluginInstalled).mockReset();
291302vi.mocked(ensureChannelSetupPluginInstalled).mockImplementation(async ({ cfg }) => ({
292303 cfg,
@@ -607,6 +618,57 @@ describe("channelsAddCommand", () => {
607618expect(runtime.exit).not.toHaveBeenCalled();
608619});
609620621+it("uses the bundled setup fallback when snapshots only see a runtime plugin", async () => {
622+configMocks.readConfigFileSnapshot.mockResolvedValue({ ...baseConfigSnapshot });
623+setActivePluginRegistry(
624+createTestRegistry([
625+{
626+pluginId: "telegram",
627+plugin: createChannelTestPluginBase({ id: "telegram", label: "Telegram" }),
628+source: "test",
629+},
630+]),
631+);
632+vi.mocked(getBundledChannelSetupPlugin).mockReturnValue({
633+ ...createChannelTestPluginBase({ id: "telegram", label: "Telegram" }),
634+setup: {
635+applyAccountConfig: ({ cfg, input }: ApplyAccountConfigParams) => ({
636+ ...cfg,
637+channels: {
638+ ...cfg.channels,
639+telegram: {
640+enabled: true,
641+botToken: input.token,
642+},
643+},
644+}),
645+},
646+});
647+648+await channelsAddCommand(
649+{
650+channel: "telegram",
651+token: "123456:token",
652+},
653+runtime,
654+{ hasFlags: true },
655+);
656+657+expect(getBundledChannelSetupPlugin).toHaveBeenCalledWith("telegram");
658+expect(configMocks.writeConfigFile).toHaveBeenCalledWith(
659+expect.objectContaining({
660+channels: expect.objectContaining({
661+telegram: expect.objectContaining({
662+enabled: true,
663+botToken: "123456:token",
664+}),
665+}),
666+}),
667+);
668+expect(runtime.error).not.toHaveBeenCalledWith("Channel telegram does not support add.");
669+expect(runtime.exit).not.toHaveBeenCalled();
670+});
671+610672it("falls back from untrusted workspace catalog shadows when adding by alias", async () => {
611673configMocks.readConfigFileSnapshot.mockResolvedValue({ ...baseConfigSnapshot });
612674setActivePluginRegistry(createTestRegistry());
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。