diff --git a/src/config/plugin-auto-enable.channels.test.ts b/src/config/plugin-auto-enable.channels.test.ts index 876443ca6ac..7de980b7587 100644 --- a/src/config/plugin-auto-enable.channels.test.ts +++ b/src/config/plugin-auto-enable.channels.test.ts @@ -273,6 +273,37 @@ describe("applyPluginAutoEnable channels", () => { ); }); + it("keeps built-in channel enablement when a same-id plugin does not claim the channel", () => { + const result = materializePluginAutoEnableCandidates({ + config: { + channels: { + telegram: { + botToken: "token", + }, + }, + }, + candidates: [ + { + pluginId: "telegram", + kind: "channel-configured", + channelId: "telegram", + }, + ], + env: makeIsolatedEnv(), + manifestRegistry: makeRegistry([ + { + id: "telegram", + channels: ["unrelated-channel"], + origin: "global", + }, + ]), + }); + + expect(result.config.channels?.telegram?.enabled).toBe(true); + expect(result.config.plugins?.entries?.telegram).toBeUndefined(); + expect(result.changes).toContain("Telegram configured, enabled automatically."); + }); + it("uses the plugin manifest id, not the channel id, for plugins.entries", () => { const result = applyWithApnChannelConfig(); diff --git a/src/config/plugin-auto-enable.shared.ts b/src/config/plugin-auto-enable.shared.ts index 0abb20f8529..a4d716d07ab 100644 --- a/src/config/plugin-auto-enable.shared.ts +++ b/src/config/plugin-auto-enable.shared.ts @@ -868,7 +868,13 @@ function resolveAutoEnableChannelId(params: { (record) => record.id === params.entry.pluginId, ); if (plugin && plugin.origin !== "bundled") { - return null; + if (params.entry.kind !== "channel-configured") { + return null; + } + const channelId = normalizeManifestChannelId(params.entry.channelId); + if ((plugin.channels ?? []).some((id) => normalizeManifestChannelId(id) === channelId)) { + return null; + } } const builtInChannelId = normalizeChatChannelId(params.entry.pluginId); if (builtInChannelId) {