From 16043ad6183389dd3024ad6a4464caba6aab9b23 Mon Sep 17 00:00:00 2001 From: Alexander Davydov Date: Wed, 18 Mar 2026 14:08:17 +0300 Subject: [PATCH] Onboarding: honor generic token for GigaChat OAuth --- .../auth-choice.api-key-providers.test.ts | 43 +++++++++++++++++++ .../local/auth-choice.api-key-providers.ts | 2 +- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/commands/onboard-non-interactive/local/auth-choice.api-key-providers.test.ts b/src/commands/onboard-non-interactive/local/auth-choice.api-key-providers.test.ts index 50d89f78d86..1352038499a 100644 --- a/src/commands/onboard-non-interactive/local/auth-choice.api-key-providers.test.ts +++ b/src/commands/onboard-non-interactive/local/auth-choice.api-key-providers.test.ts @@ -74,4 +74,47 @@ describe("applySimpleNonInteractiveApiKeyChoice", () => { }, ); }); + + it("accepts the generic --token input for GigaChat non-interactive OAuth", async () => { + const nextConfig = { agents: { defaults: {} } } as OpenClawConfig; + const resolveApiKey = vi.fn(async () => ({ + key: "gigachat-token-credentials", + source: "flag" as const, + })); + const maybeSetResolvedApiKey = vi.fn(async (resolved, setter) => { + await setter(resolved.key); + return true; + }); + + await applySimpleNonInteractiveApiKeyChoice({ + authChoice: "gigachat-oauth", + nextConfig, + baseConfig: nextConfig, + opts: { token: "gigachat-token-credentials" } as never, + runtime: { error: vi.fn(), exit: vi.fn(), log: vi.fn() } as never, + apiKeyStorageOptions: undefined, + resolveApiKey, + maybeSetResolvedApiKey, + }); + + expect(resolveApiKey).toHaveBeenCalledWith( + expect.objectContaining({ + provider: "gigachat", + flagValue: "gigachat-token-credentials", + flagName: "--gigachat-api-key", + envVar: "GIGACHAT_CREDENTIALS", + allowProfile: false, + }), + ); + expect(setGigachatApiKey).toHaveBeenCalledWith( + "gigachat-token-credentials", + undefined, + undefined, + { + authMode: "oauth", + insecureTls: "false", + scope: "GIGACHAT_API_PERS", + }, + ); + }); }); diff --git a/src/commands/onboard-non-interactive/local/auth-choice.api-key-providers.ts b/src/commands/onboard-non-interactive/local/auth-choice.api-key-providers.ts index 57ab0588ea9..fef8693588e 100644 --- a/src/commands/onboard-non-interactive/local/auth-choice.api-key-providers.ts +++ b/src/commands/onboard-non-interactive/local/auth-choice.api-key-providers.ts @@ -39,7 +39,7 @@ async function applyGigachatNonInteractiveApiKeyChoice(params: { const resolved = await params.resolveApiKey({ provider: "gigachat", cfg: params.baseConfig, - flagValue: params.opts.gigachatApiKey, + flagValue: params.opts.gigachatApiKey ?? params.opts.token, flagName: "--gigachat-api-key", envVar: "GIGACHAT_CREDENTIALS", runtime: params.runtime,