Mirror Google API key env aliases into managed OpenCode.

OpenCode can mark Google connected via GEMINI_API_KEY while the Generative AI
SDK only reads GOOGLE_GENERATIVE_AI_API_KEY, so chat asked for a key that was
already present. Alias unset sibling names on managed launch for web and VS Code.

Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com>
This commit is contained in:
Cursor Agent
2026-08-03 13:18:27 +00:00
co-authored by Serhii Dziupin
parent 9cccc8d667
commit 321794a621
6 changed files with 148 additions and 3 deletions
@@ -0,0 +1,33 @@
import { describe, expect, test } from 'bun:test';
import { applyProviderEnvAliases } from './provider-env-aliases.js';
describe('applyProviderEnvAliases', () => {
test('mirrors GEMINI_API_KEY onto Google Generative AI env names', () => {
expect(applyProviderEnvAliases({
GEMINI_API_KEY: 'AIza-demo',
PATH: '/usr/bin',
})).toEqual({
GEMINI_API_KEY: 'AIza-demo',
GOOGLE_API_KEY: 'AIza-demo',
GOOGLE_GENERATIVE_AI_API_KEY: 'AIza-demo',
PATH: '/usr/bin',
});
});
test('does not overwrite an already-set preferred Google key', () => {
expect(applyProviderEnvAliases({
GEMINI_API_KEY: 'from-gemini',
GOOGLE_GENERATIVE_AI_API_KEY: 'from-google',
})).toEqual({
GEMINI_API_KEY: 'from-gemini',
GOOGLE_API_KEY: 'from-google',
GOOGLE_GENERATIVE_AI_API_KEY: 'from-google',
});
});
test('returns empty object for invalid input', () => {
expect(applyProviderEnvAliases(null)).toEqual({});
expect(applyProviderEnvAliases(undefined)).toEqual({});
});
});