From 771d3e363a9ba8a2e903bacd3c3344f6c6c6c0bd Mon Sep 17 00:00:00 2001 From: Diego Rodrigues de Sa e Souza Date: Fri, 7 Aug 2026 18:08:35 -0300 Subject: [PATCH] fix: make antigravity and agy equivalent in credential selection (#9204) Co-authored-by: diegosouzapw --- changelog.d/fixes/9204-fix.plan.md | 1 + src/lib/oauth/utils/agyAuthImport.ts | 1 + ...204-agy-provider-alias-credentials.test.ts | 48 +++++++++++++++++ .../bug-9204-agy-reimport-reactivates.test.ts | 53 +++++++++++++++++++ 4 files changed, 103 insertions(+) create mode 100644 changelog.d/fixes/9204-fix.plan.md create mode 100644 tests/unit/bug-9204-agy-provider-alias-credentials.test.ts create mode 100644 tests/unit/bug-9204-agy-reimport-reactivates.test.ts diff --git a/changelog.d/fixes/9204-fix.plan.md b/changelog.d/fixes/9204-fix.plan.md new file mode 100644 index 0000000000..21981ed128 --- /dev/null +++ b/changelog.d/fixes/9204-fix.plan.md @@ -0,0 +1 @@ +- fix(auth): make antigravity and agy equivalent in credential selection (#9204) diff --git a/src/lib/oauth/utils/agyAuthImport.ts b/src/lib/oauth/utils/agyAuthImport.ts index 77ea09c5c4..86edf19d78 100644 --- a/src/lib/oauth/utils/agyAuthImport.ts +++ b/src/lib/oauth/utils/agyAuthImport.ts @@ -214,6 +214,7 @@ export async function createConnectionFromAgyToken( resolvedEmail || "Antigravity CLI (imported)", testStatus: "active", + isActive: true, providerSpecificData: { ...toRecord(existing.providerSpecificData), clientProfile: "cli", diff --git a/tests/unit/bug-9204-agy-provider-alias-credentials.test.ts b/tests/unit/bug-9204-agy-provider-alias-credentials.test.ts new file mode 100644 index 0000000000..e45d020e66 --- /dev/null +++ b/tests/unit/bug-9204-agy-provider-alias-credentials.test.ts @@ -0,0 +1,48 @@ +import test from "node:test"; +import assert from "node:assert/strict"; +import fs from "node:fs"; +import os from "node:os"; +import path from "node:path"; + +const TEST_DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-9204-agy-alias-")); +process.env.DATA_DIR = TEST_DATA_DIR; + +const core = await import("../../src/lib/db/core.ts"); +const { createConnectionFromAgyToken } = await import( + "../../src/lib/oauth/utils/agyAuthImport.ts" +); +const { parseModel } = await import("../../open-sse/services/model.ts"); +const { getProviderCredentials } = await import("../../src/sse/services/auth.ts"); + +test.after(() => { + core.resetDbInstance(); + fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true }); +}); + +test("#9204: an Antigravity CLI login is eligible for an agy model request", async () => { + const { connection } = await createConnectionFromAgyToken( + { + accessToken: "fresh-access-token", + refreshToken: "fresh-refresh-token", + expiresAt: new Date(Date.now() + 3_600_000).toISOString(), + tokenType: "Bearer", + authMethod: "oauth", + email: "reporter@example.test", + projectId: "project-9204", + tier: "free-tier", + }, + { overwriteExisting: true } + ); + + assert.equal(connection.provider, "agy"); + assert.equal(connection.isActive, true); + assert.equal(connection.testStatus, "active"); + + const parsed = parseModel("agy/gemini-2.5-flash"); + assert.equal(parsed.provider, "antigravity"); + + const credentials = await getProviderCredentials(parsed.provider!, null, null, parsed.model); + assert.ok(credentials, "the active Antigravity CLI connection must remain selectable"); + assert.equal(credentials.connectionId, connection.id); + assert.equal(credentials.accessToken, "fresh-access-token"); +}); \ No newline at end of file diff --git a/tests/unit/bug-9204-agy-reimport-reactivates.test.ts b/tests/unit/bug-9204-agy-reimport-reactivates.test.ts new file mode 100644 index 0000000000..b57538663a --- /dev/null +++ b/tests/unit/bug-9204-agy-reimport-reactivates.test.ts @@ -0,0 +1,53 @@ +import test from "node:test"; +import assert from "node:assert/strict"; +import fs from "node:fs"; +import os from "node:os"; +import path from "node:path"; + +const TEST_DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-9204-agy-reimport-")); +process.env.DATA_DIR = TEST_DATA_DIR; + +const core = await import("../../src/lib/db/core.ts"); +const providersDb = await import("../../src/lib/db/providers.ts"); +const { createConnectionFromAgyToken } = await import( + "../../src/lib/oauth/utils/agyAuthImport.ts" +); + +test.after(() => { + core.resetDbInstance(); + fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true }); +}); + +test("#9204: reimporting an inactive Antigravity CLI account reactivates it", async () => { + const existing = await providersDb.createProviderConnection({ + provider: "agy", + authType: "oauth", + email: "reporter@example.test", + accessToken: "stale-access-token", + refreshToken: "stale-refresh-token", + expiresAt: new Date(Date.now() - 60_000).toISOString(), + isActive: false, + testStatus: "expired", + }); + + await createConnectionFromAgyToken( + { + accessToken: "fresh-access-token", + refreshToken: "fresh-refresh-token", + expiresAt: new Date(Date.now() + 3_600_000).toISOString(), + tokenType: "Bearer", + authMethod: "oauth", + email: "reporter@example.test", + projectId: "project-9204", + tier: "free-tier", + }, + { overwriteExisting: true } + ); + + const stored = await providersDb.getProviderConnectionById(existing.id); + assert.equal(stored?.testStatus, "active"); + assert.equal(stored?.isActive, true, "a successful reimport must reactivate the account"); + + const active = await providersDb.getProviderConnections({ provider: "agy", isActive: true }); + assert.deepEqual(active.map((connection) => connection.id), [existing.id]); +}); \ No newline at end of file