mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 11:10:45 +00:00
Twitch: align normalized token lookup
This commit is contained in:
@@ -202,4 +202,32 @@ describe("resolveTwitchAccountContext", () => {
|
||||
expect(context.accountId).toBe("secondary");
|
||||
expect(context.account?.username).toBe("second-bot");
|
||||
});
|
||||
|
||||
it("keeps account and token lookup aligned after account id normalization", () => {
|
||||
const context = resolveTwitchAccountContext(
|
||||
{
|
||||
channels: {
|
||||
twitch: {
|
||||
accounts: {
|
||||
Secondary: {
|
||||
username: "second-bot",
|
||||
accessToken: "oauth:second-token",
|
||||
clientId: "second-client",
|
||||
channel: "#second",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
} as Parameters<typeof resolveTwitchAccountContext>[0],
|
||||
"secondary",
|
||||
);
|
||||
|
||||
expect(context.accountId).toBe("secondary");
|
||||
expect(context.account?.username).toBe("second-bot");
|
||||
expect(context.tokenResolution).toEqual({
|
||||
token: "oauth:second-token",
|
||||
source: "config",
|
||||
});
|
||||
expect(context.configured).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -65,6 +65,27 @@ describe("token", () => {
|
||||
expect(result.source).toBe("config");
|
||||
});
|
||||
|
||||
it("should resolve token from normalized account id", () => {
|
||||
const result = resolveTwitchToken(
|
||||
{
|
||||
channels: {
|
||||
twitch: {
|
||||
accounts: {
|
||||
Secondary: {
|
||||
username: "secondary",
|
||||
accessToken: "oauth:secondary-token",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
} as unknown as OpenClawConfig,
|
||||
{ accountId: "secondary" },
|
||||
);
|
||||
|
||||
expect(result.token).toBe("oauth:secondary-token");
|
||||
expect(result.source).toBe("config");
|
||||
});
|
||||
|
||||
it("should prioritize config token over env var (simplified config)", () => {
|
||||
process.env.OPENCLAW_TWITCH_ACCESS_TOKEN = "oauth:env-token";
|
||||
|
||||
|
||||
@@ -9,8 +9,12 @@
|
||||
* 2. Environment variable: OPENCLAW_TWITCH_ACCESS_TOKEN (default account only)
|
||||
*/
|
||||
|
||||
import {
|
||||
DEFAULT_ACCOUNT_ID,
|
||||
normalizeAccountId,
|
||||
resolveNormalizedAccountEntry,
|
||||
} from "openclaw/plugin-sdk/account-resolution";
|
||||
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-runtime";
|
||||
import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "openclaw/plugin-sdk/routing";
|
||||
|
||||
export type TwitchTokenSource = "env" | "config" | "none";
|
||||
|
||||
@@ -56,10 +60,8 @@ export function resolveTwitchToken(
|
||||
|
||||
// Get merged account config (handles both simplified and multi-account patterns)
|
||||
const twitchCfg = cfg?.channels?.twitch;
|
||||
const accountCfg =
|
||||
accountId === DEFAULT_ACCOUNT_ID
|
||||
? (twitchCfg?.accounts?.[DEFAULT_ACCOUNT_ID] as Record<string, unknown> | undefined)
|
||||
: (twitchCfg?.accounts?.[accountId] as Record<string, unknown> | undefined);
|
||||
const accounts = twitchCfg?.accounts as Record<string, Record<string, unknown>> | undefined;
|
||||
const accountCfg = resolveNormalizedAccountEntry(accounts, accountId, normalizeAccountId);
|
||||
|
||||
// For default account, also check base-level config
|
||||
let token: string | undefined;
|
||||
|
||||
Reference in New Issue
Block a user