From 4453e698e51537b987dced7e5065395318ef7f8d Mon Sep 17 00:00:00 2001 From: Gustavo Madeira Santana Date: Fri, 17 Apr 2026 03:43:31 -0400 Subject: [PATCH] Twitch: normalize setup account ids --- extensions/twitch/src/setup-surface.test.ts | 24 +++++++++++++++++++++ extensions/twitch/src/setup-surface.ts | 10 +++++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/extensions/twitch/src/setup-surface.test.ts b/extensions/twitch/src/setup-surface.test.ts index 16fe106b8e2..3f2ef0f01c1 100644 --- a/extensions/twitch/src/setup-surface.test.ts +++ b/extensions/twitch/src/setup-surface.test.ts @@ -20,6 +20,7 @@ import { promptRefreshTokenSetup, promptToken, promptUsername, + setTwitchAccount, twitchSetupPlugin, twitchSetupWizard, } from "./setup-surface.js"; @@ -315,6 +316,29 @@ describe("setup surface helpers", () => { }); describe("setup wizard account routing", () => { + it("normalizes account ids before using them as config keys", () => { + const cfg = setTwitchAccount( + {} as Parameters[0], + { + username: "normalized-bot", + accessToken: "oauth:normalized", + clientId: "normalized-client", + channel: "#normalized", + }, + "__proto__", + ); + + expect(cfg.channels?.twitch?.accounts?.default?.username).toBe("normalized-bot"); + expect(Object.prototype).not.toHaveProperty("username"); + expect( + twitchSetupWizard.status?.resolveStatusLines?.({ + cfg: {}, + accountId: "Alerts\r\n\u001b[31m", + configured: false, + } as never), + ).toEqual(["Twitch (alerts-31m): needs username, token, and clientId"]); + }); + it("reports account-scoped DM policy config keys", () => { expect( twitchSetupWizard.dmPolicy?.resolveConfigKeys?.( diff --git a/extensions/twitch/src/setup-surface.ts b/extensions/twitch/src/setup-surface.ts index d49a36475b1..818e16d6857 100644 --- a/extensions/twitch/src/setup-surface.ts +++ b/extensions/twitch/src/setup-surface.ts @@ -10,6 +10,7 @@ import { type ChannelSetupWizard, type OpenClawConfig, type WizardPrompter, + normalizeAccountId, } from "openclaw/plugin-sdk/setup"; import { DEFAULT_ACCOUNT_ID, @@ -26,11 +27,11 @@ const channel = "twitch" as const; function resolveSetupAccountId(cfg: OpenClawConfig, requestedAccountId?: string): string { const requested = requestedAccountId?.trim(); if (requested) { - return requested; + return normalizeAccountId(requested); } const preferred = cfg.channels?.twitch?.defaultAccount?.trim(); - return preferred || resolveDefaultTwitchAccountId(cfg); + return preferred ? normalizeAccountId(preferred) : resolveDefaultTwitchAccountId(cfg); } export function setTwitchAccount( @@ -38,7 +39,8 @@ export function setTwitchAccount( account: Partial, accountId: string = resolveSetupAccountId(cfg), ): OpenClawConfig { - const existing = getAccountConfig(cfg, accountId); + const resolvedAccountId = normalizeAccountId(accountId); + const existing = getAccountConfig(cfg, resolvedAccountId); const merged: TwitchAccountConfig = { username: account.username ?? existing?.username ?? "", accessToken: account.accessToken ?? existing?.accessToken ?? "", @@ -67,7 +69,7 @@ export function setTwitchAccount( ...(( (cfg.channels as Record)?.twitch as Record | undefined )?.accounts as Record | undefined), - [accountId]: merged, + [resolvedAccountId]: merged, }, }, },