fix(onboard): avoid false 'telegram plugin not available' block

This commit is contained in:
suko
2026-02-24 21:56:49 +01:00
committed by Peter Steinberger
parent b0bb3cca8a
commit b3e6653503
3 changed files with 91 additions and 7 deletions

View File

@@ -1,5 +1,7 @@
import { beforeEach, describe, expect, it, vi } from "vitest"; import { beforeEach, describe, expect, it, vi } from "vitest";
import type { OpenClawConfig } from "../config/config.js"; import type { OpenClawConfig } from "../config/config.js";
import { createEmptyPluginRegistry } from "../plugins/registry.js";
import { setActivePluginRegistry } from "../plugins/runtime.js";
import type { WizardPrompter } from "../wizard/prompts.js"; import type { WizardPrompter } from "../wizard/prompts.js";
import { setDefaultChannelPluginRegistryForTests } from "./channel-test-helpers.js"; import { setDefaultChannelPluginRegistryForTests } from "./channel-test-helpers.js";
import { setupChannels } from "./onboard-channels.js"; import { setupChannels } from "./onboard-channels.js";
@@ -42,6 +44,15 @@ vi.mock("./onboard-helpers.js", () => ({
detectBinary: vi.fn(async () => false), detectBinary: vi.fn(async () => false),
})); }));
vi.mock("./onboarding/plugin-install.js", async (importOriginal) => {
const actual = await importOriginal();
return {
...(actual as Record<string, unknown>),
// Allow tests to simulate an empty plugin registry during onboarding.
reloadOnboardingPluginRegistry: vi.fn(() => {}),
};
});
describe("setupChannels", () => { describe("setupChannels", () => {
beforeEach(() => { beforeEach(() => {
setDefaultChannelPluginRegistryForTests(); setDefaultChannelPluginRegistryForTests();
@@ -81,6 +92,45 @@ describe("setupChannels", () => {
expect(multiselect).not.toHaveBeenCalled(); expect(multiselect).not.toHaveBeenCalled();
}); });
it("continues Telegram onboarding even when plugin registry is empty (avoids 'plugin not available' block)", async () => {
// Simulate missing registry entries (the scenario reported in #25545).
setActivePluginRegistry(createEmptyPluginRegistry());
// Avoid accidental env-token configuration changing the prompt path.
process.env.TELEGRAM_BOT_TOKEN = "";
const note = vi.fn(async (_message?: string, _title?: string) => {});
const select = vi.fn(async ({ message }: { message: string }) => {
if (message === "Select channel (QuickStart)") {
return "telegram";
}
return "__done__";
});
const text = vi.fn(async () => "123:token");
const prompter = createPrompter({
note,
select: select as unknown as WizardPrompter["select"],
text: text as unknown as WizardPrompter["text"],
});
const runtime = createExitThrowingRuntime();
await setupChannels({} as OpenClawConfig, runtime, prompter, {
skipConfirm: true,
quickstartDefaults: true,
});
// The new flow should not stop setup with a hard "plugin not available" note.
const sawHardStop = note.mock.calls.some((call) => {
const message = call[0];
const title = call[1];
return (
title === "Channel setup" && String(message).trim() === "telegram plugin not available."
);
});
expect(sawHardStop).toBe(false);
});
it("shows explicit dmScope config command in channel primer", async () => { it("shows explicit dmScope config command in channel primer", async () => {
const note = vi.fn(async (_message?: string, _title?: string) => {}); const note = vi.fn(async (_message?: string, _title?: string) => {});
const select = vi.fn(async () => "__done__"); const select = vi.fn(async () => "__done__");

View File

@@ -467,6 +467,20 @@ export async function setupChannels(
workspaceDir, workspaceDir,
}); });
if (!getChannelPlugin(channel)) { if (!getChannelPlugin(channel)) {
// Some installs/environments can fail to populate the plugin registry during onboarding,
// even for built-in channels. If the channel supports onboarding, proceed with config
// so setup isn't blocked; the gateway can still load plugins on startup.
const adapter = getChannelOnboardingAdapter(channel);
if (adapter) {
await prompter.note(
`${channel} plugin not available (continuing with onboarding). If the channel still doesn't work after setup, run \`${formatCliCommand(
"openclaw plugins list",
)}\` and \`${formatCliCommand("openclaw plugins enable " + channel)}\`, then restart the gateway.`,
"Channel setup",
);
await refreshStatus(channel);
return true;
}
await prompter.note(`${channel} plugin not available.`, "Channel setup"); await prompter.note(`${channel} plugin not available.`, "Channel setup");
return false; return false;
} }

View File

@@ -1,16 +1,36 @@
import { listChannelPlugins } from "../../channels/plugins/index.js"; import { listChannelPlugins } from "../../channels/plugins/index.js";
import { discordOnboardingAdapter } from "../../channels/plugins/onboarding/discord.js";
import { imessageOnboardingAdapter } from "../../channels/plugins/onboarding/imessage.js";
import { signalOnboardingAdapter } from "../../channels/plugins/onboarding/signal.js";
import { slackOnboardingAdapter } from "../../channels/plugins/onboarding/slack.js";
import { telegramOnboardingAdapter } from "../../channels/plugins/onboarding/telegram.js";
import { whatsappOnboardingAdapter } from "../../channels/plugins/onboarding/whatsapp.js";
import type { ChannelChoice } from "../onboard-types.js"; import type { ChannelChoice } from "../onboard-types.js";
import type { ChannelOnboardingAdapter } from "./types.js"; import type { ChannelOnboardingAdapter } from "./types.js";
const CHANNEL_ONBOARDING_ADAPTERS = () => const BUILTIN_ONBOARDING_ADAPTERS: ChannelOnboardingAdapter[] = [
new Map<ChannelChoice, ChannelOnboardingAdapter>( telegramOnboardingAdapter,
listChannelPlugins() whatsappOnboardingAdapter,
.map((plugin) => (plugin.onboarding ? ([plugin.id, plugin.onboarding] as const) : null)) discordOnboardingAdapter,
.filter((entry): entry is readonly [ChannelChoice, ChannelOnboardingAdapter] => slackOnboardingAdapter,
Boolean(entry), signalOnboardingAdapter,
), imessageOnboardingAdapter,
];
const CHANNEL_ONBOARDING_ADAPTERS = () => {
const fromRegistry = listChannelPlugins()
.map((plugin) => (plugin.onboarding ? ([plugin.id, plugin.onboarding] as const) : null))
.filter((entry): entry is readonly [ChannelChoice, ChannelOnboardingAdapter] => Boolean(entry));
// Fall back to built-in adapters to keep onboarding working even when the plugin registry
// fails to populate (see #25545).
const fromBuiltins = BUILTIN_ONBOARDING_ADAPTERS.map(
(adapter) => [adapter.channel, adapter] as const,
); );
return new Map<ChannelChoice, ChannelOnboardingAdapter>([...fromBuiltins, ...fromRegistry]);
};
export function getChannelOnboardingAdapter( export function getChannelOnboardingAdapter(
channel: ChannelChoice, channel: ChannelChoice,
): ChannelOnboardingAdapter | undefined { ): ChannelOnboardingAdapter | undefined {