fix: clone setup channels for owned ids

This commit is contained in:
Gustavo Madeira Santana
2026-04-21 00:45:05 -04:00
parent 86dd59f914
commit 1fe988433e
2 changed files with 44 additions and 0 deletions

View File

@@ -216,6 +216,40 @@ describe("listReadOnlyChannelPluginsForConfig", () => {
expect(fs.existsSync(fullMarker)).toBe(false);
});
it("clones setup-only plugins for every configured owned channel when setup id matches one channel", () => {
const { pluginDir, fullMarker, setupMarker } = writeExternalSetupChannelPlugin({
pluginId: "external-chat-plugin",
channelId: "alpha-chat",
manifestChannelIds: ["alpha-chat", "beta-chat"],
setupChannelId: "alpha-chat",
});
const plugins = listReadOnlyChannelPluginsForConfig(
{
channels: {
"alpha-chat": { token: "configured" },
"beta-chat": { token: "configured" },
},
plugins: {
load: { paths: [pluginDir] },
allow: ["external-chat-plugin"],
},
} as never,
{
env: { ...process.env },
includePersistedAuthState: false,
},
);
const alphaPlugin = plugins.find((entry) => entry.id === "alpha-chat");
const betaPlugin = plugins.find((entry) => entry.id === "beta-chat");
expect(alphaPlugin?.meta.id).toBe("alpha-chat");
expect(betaPlugin?.meta.id).toBe("beta-chat");
expect(alphaPlugin?.meta.blurb).toBe("setup entry");
expect(betaPlugin?.meta.blurb).toBe("setup entry");
expect(fs.existsSync(setupMarker)).toBe(true);
expect(fs.existsSync(fullMarker)).toBe(false);
});
it("keeps configured external channels visible when no setup entry exists", () => {
const { pluginDir, fullMarker, setupMarker } = writeExternalSetupChannelPlugin({
setupEntry: false,

View File

@@ -101,6 +101,16 @@ function addSetupChannelPlugins(
onlyIds: new Set(ownedMissingChannelIds),
allowOverwrite: false,
});
addChannelPlugins(
byId,
ownedMissingChannelIds
.filter((channelId) => channelId !== setup.plugin.id)
.map((channelId) => cloneChannelPluginForChannelId(setup.plugin, channelId)),
{
onlyIds: new Set(ownedMissingChannelIds),
allowOverwrite: false,
},
);
continue;
}
if (setup.plugin.id !== setup.pluginId) {