From e1ff24903f20dc6c08126a47552263d0c1b4ceca Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sun, 22 Mar 2026 08:48:53 -0700 Subject: [PATCH] fix(gateway): follow up startup import reviews (#52337) --- src/plugins/channel-plugin-ids.test.ts | 80 ++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 src/plugins/channel-plugin-ids.test.ts diff --git a/src/plugins/channel-plugin-ids.test.ts b/src/plugins/channel-plugin-ids.test.ts new file mode 100644 index 00000000000..6a09a2a23fe --- /dev/null +++ b/src/plugins/channel-plugin-ids.test.ts @@ -0,0 +1,80 @@ +import { beforeEach, describe, expect, it, vi } from "vitest"; +import type { OpenClawConfig } from "../config/config.js"; + +const listPotentialConfiguredChannelIds = vi.hoisted(() => vi.fn()); +const loadPluginManifestRegistry = vi.hoisted(() => vi.fn()); + +vi.mock("../channels/config-presence.js", () => ({ + listPotentialConfiguredChannelIds, +})); + +vi.mock("./manifest-registry.js", () => ({ + loadPluginManifestRegistry, +})); + +import { resolveGatewayStartupPluginIds } from "./channel-plugin-ids.js"; + +describe("resolveGatewayStartupPluginIds", () => { + beforeEach(() => { + listPotentialConfiguredChannelIds.mockReset().mockReturnValue(["discord"]); + loadPluginManifestRegistry.mockReset().mockReturnValue({ + plugins: [ + { + id: "discord", + channels: ["discord"], + origin: "bundled", + enabledByDefault: undefined, + }, + { + id: "amazon-bedrock", + channels: [], + origin: "bundled", + enabledByDefault: true, + }, + { + id: "diagnostics-otel", + channels: [], + origin: "bundled", + enabledByDefault: undefined, + }, + { + id: "custom-sidecar", + channels: [], + origin: "global", + enabledByDefault: undefined, + }, + ], + diagnostics: [], + }); + }); + + it("includes configured channels, explicit bundled sidecars, and enabled non-bundled sidecars", () => { + const config = { + plugins: { + entries: { + "diagnostics-otel": { enabled: true }, + }, + }, + } as OpenClawConfig; + + expect( + resolveGatewayStartupPluginIds({ + config, + workspaceDir: "/tmp", + env: process.env, + }), + ).toEqual(["discord", "diagnostics-otel", "custom-sidecar"]); + }); + + it("does not pull default-on bundled non-channel plugins into startup", () => { + const config = {} as OpenClawConfig; + + expect( + resolveGatewayStartupPluginIds({ + config, + workspaceDir: "/tmp", + env: process.env, + }), + ).toEqual(["discord", "custom-sidecar"]); + }); +});