LINE: avoid runtime lookup during onboarding (#49960)

This commit is contained in:
darkamenosa 2026-03-19 01:27:21 +07:00 committed by GitHub
parent 8f0727d75c
commit 4b5487ee85
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 37 additions and 12 deletions

View File

@ -1,13 +1,11 @@
import { createScopedChannelConfigAdapter } from "openclaw/plugin-sdk/channel-config-helpers";
import type { OpenClawConfig, ResolvedLineAccount } from "../api.js";
import { getLineRuntime } from "./runtime.js";
function resolveLineRuntimeAccount(cfg: OpenClawConfig, accountId?: string | null) {
return getLineRuntime().channel.line.resolveLineAccount({
cfg,
accountId: accountId ?? undefined,
});
}
import {
listLineAccountIds,
resolveDefaultLineAccountId,
resolveLineAccount,
type OpenClawConfig,
type ResolvedLineAccount,
} from "../runtime-api.js";
export function normalizeLineAllowFrom(entry: string): string {
return entry.replace(/^line:(?:user:)?/i, "");
@ -19,9 +17,10 @@ export const lineConfigAdapter = createScopedChannelConfigAdapter<
OpenClawConfig
>({
sectionKey: "line",
listAccountIds: (cfg) => getLineRuntime().channel.line.listLineAccountIds(cfg),
resolveAccount: (cfg, accountId) => resolveLineRuntimeAccount(cfg, accountId),
defaultAccountId: (cfg) => getLineRuntime().channel.line.resolveDefaultLineAccountId(cfg),
listAccountIds: listLineAccountIds,
resolveAccount: (cfg, accountId) =>
resolveLineAccount({ cfg, accountId: accountId ?? undefined }),
defaultAccountId: resolveDefaultLineAccountId,
clearBaseFields: ["channelSecret", "tokenFile", "secretFile"],
resolveAllowFrom: (account) => account.config.allowFrom,
formatAllowFrom: (allowFrom) =>

View File

@ -277,6 +277,32 @@ describe("setupChannels", () => {
expect(multiselect).not.toHaveBeenCalled();
});
it("renders the QuickStart channel picker without requiring the LINE runtime", async () => {
const select = vi.fn(async ({ message }: { message: string }) => {
if (message === "Select channel (QuickStart)") {
return "__skip__";
}
return "__done__";
});
const { multiselect, text } = createUnexpectedPromptGuards();
const prompter = createPrompter({
select: select as unknown as WizardPrompter["select"],
multiselect,
text,
});
await expect(
runSetupChannels({} as OpenClawConfig, prompter, {
quickstartDefaults: true,
}),
).resolves.toEqual({} as OpenClawConfig);
expect(select).toHaveBeenCalledWith(
expect.objectContaining({ message: "Select channel (QuickStart)" }),
);
expect(multiselect).not.toHaveBeenCalled();
});
it("continues Telegram setup when the plugin registry is empty", async () => {
// Simulate missing registry entries (the scenario reported in #25545).
setActivePluginRegistry(createEmptyPluginRegistry());