CLI: preserve disabled channels during lazy setup

This commit is contained in:
Gustavo Madeira Santana
2026-04-17 03:08:45 -04:00
parent 204098b7fd
commit b0c46cbd76
2 changed files with 81 additions and 0 deletions

View File

@@ -314,4 +314,75 @@ describe("setupChannels workspace shadow exclusion", () => {
},
});
});
it("does not re-enable an explicitly disabled channel when selected lazily", async () => {
const setupWizard = {
channel: "telegram",
getStatus: vi.fn(async () => ({
channel: "telegram",
configured: true,
statusLines: [],
})),
configure: vi.fn(),
};
const telegramPlugin = {
id: "telegram",
meta: { id: "telegram", label: "Telegram", blurb: "" },
capabilities: {},
config: {
resolveAccount: vi.fn(() => ({ enabled: false })),
},
setupWizard,
};
resolveChannelSetupEntries.mockReturnValue({
entries: [
{
id: "telegram",
meta: { id: "telegram", label: "Telegram", blurb: "" },
},
],
installedCatalogEntries: [],
installableCatalogEntries: [],
installedCatalogById: new Map(),
installableCatalogById: new Map(),
});
loadChannelSetupPluginRegistrySnapshotForChannel.mockReturnValue({
channels: [{ plugin: telegramPlugin }],
channelSetups: [],
});
const select = vi.fn().mockResolvedValueOnce("telegram").mockResolvedValueOnce("__done__");
const cfg = {
channels: {
telegram: { enabled: false, token: "secret" },
},
};
const next = await setupChannels(
cfg as never,
{} as never,
{
confirm: vi.fn(async () => true),
note: vi.fn(async () => undefined),
select,
} as never,
{
deferStatusUntilSelection: true,
skipConfirm: true,
skipDmPolicyPrompt: true,
},
);
expect(loadChannelSetupPluginRegistrySnapshotForChannel).toHaveBeenCalledWith(
expect.objectContaining({
channel: "telegram",
workspaceDir: "/tmp/openclaw-workspace",
}),
);
expect(setupWizard.configure).not.toHaveBeenCalled();
expect(next).toEqual({
channels: {
telegram: { enabled: false, token: "secret" },
},
});
});
});

View File

@@ -323,6 +323,16 @@ export async function setupChannels(
await refreshStatus(channel);
return true;
}
const disabledHint = resolveConfigDisabledHint(channel);
if (disabledHint) {
const plugin = await loadScopedChannelPlugin(channel);
if (!plugin) {
await prompter.note(`${channel} plugin not available (${disabledHint}).`, "Channel setup");
return false;
}
await refreshStatus(channel);
return true;
}
const result = enablePluginInConfig(next, channel);
next = result.config;
if (!result.enabled) {