fix(gemini-cli-auth): use PLATFORM_UNSPECIFIED for Linux in loadCodeAssist

Google's loadCodeAssist API rejects "LINUX" as an invalid Platform enum
value, causing OAuth setup to fail with 400 Bad Request on Linux systems.

The pi-ai runtime already uses "PLATFORM_UNSPECIFIED" for this field.
This aligns the extension's discoverProject() with that approach by
returning "PLATFORM_UNSPECIFIED" for Linux (and other non-Windows/macOS
platforms) instead of "LINUX".

Also fixes the original resolvePlatform() which incorrectly fell through
to "MACOS" as default instead of explicitly checking for "darwin".
This commit is contained in:
riftzen-bit
2026-03-02 17:31:17 -08:00
committed by Peter Steinberger
parent 4c32411bee
commit 008e4804a6
2 changed files with 11 additions and 8 deletions

View File

@@ -239,14 +239,15 @@ describe("loginGeminiCliOAuth", () => {
"GOOGLE_CLOUD_PROJECT_ID",
] as const;
function getExpectedPlatform(): "WINDOWS" | "MACOS" | "LINUX" {
function getExpectedPlatform(): "WINDOWS" | "MACOS" | "LINUX" | "PLATFORM_UNSPECIFIED" {
if (process.platform === "win32") {
return "WINDOWS";
}
if (process.platform === "linux") {
return "LINUX";
if (process.platform === "darwin") {
return "MACOS";
}
return "MACOS";
// Matches updated resolvePlatform() which uses PLATFORM_UNSPECIFIED for Linux
return "PLATFORM_UNSPECIFIED";
}
function getRequestUrl(input: string | URL | Request): string {

View File

@@ -224,14 +224,16 @@ function generatePkce(): { verifier: string; challenge: string } {
return { verifier, challenge };
}
function resolvePlatform(): "WINDOWS" | "MACOS" | "LINUX" {
function resolvePlatform(): "WINDOWS" | "MACOS" | "LINUX" | "PLATFORM_UNSPECIFIED" {
if (process.platform === "win32") {
return "WINDOWS";
}
if (process.platform === "linux") {
return "LINUX";
if (process.platform === "darwin") {
return "MACOS";
}
return "MACOS";
// Google's loadCodeAssist API rejects "LINUX" as an invalid Platform enum value.
// Use "PLATFORM_UNSPECIFIED" for Linux and other platforms to match the pi-ai runtime.
return "PLATFORM_UNSPECIFIED";
}
async function fetchWithTimeout(