Onboarding: honor generic token for GigaChat OAuth

This commit is contained in:
Alexander Davydov 2026-03-18 14:08:17 +03:00
parent 8fdece2b52
commit 16043ad618
2 changed files with 44 additions and 1 deletions

View File

@ -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",
},
);
});
});

View File

@ -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,