Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
e8b4837
Make Antigravity Chat account changes request a fresh sign-in
brennanb2025 Nov 4, 2026
ca82afa
Stop the sign-in test fixture after its process exits
brennanb2025 Nov 4, 2026
dbe0550
Preserve saved Antigravity sign-in while changing accounts
brennanb2025 Nov 4, 2026
063cfe9
Preserve the accepted account action across sign-in retries
brennanb2025 Nov 4, 2026
6533a13
Merge origin/main before final account sign-in verification
brennanb2025 Nov 4, 2026
d400ded
Assert the accepted sign-in policy directly in the rejoin regression
brennanb2025 Nov 4, 2026
2f6eaa8
test: keep Antigravity mock registration in its test
brennanb2025 Nov 4, 2026
61036d6
test: honor RPC envelopes and await terminal navigation
brennanb2025 Nov 4, 2026
d361234
Keep Antigravity account replacement isolated on current main
brennanb2025 Nov 16, 2026
bdb9d86
Require Antigravity sign-in processes to exit before replacing creden…
brennanb2025 Nov 16, 2026
1c60ee3
Keep Antigravity exit callbacks typed and document atomic credential …
brennanb2025 Nov 16, 2026
044eba0
Split Antigravity Chat and agy terminal accounts into separate settin…
brennanb2025 Nov 18, 2026
2da564d
Drop retired Antigravity copy keys, index the new card titles, and sh…
brennanb2025 Nov 18, 2026
9a594cc
Promote the replacement Antigravity credential with an async rename, …
brennanb2025 Nov 18, 2026
5663169
Merge origin/main into Antigravity Change account
brennanb2025 Nov 18, 2026
a2ebe73
Hold every phase change while the replacement credential moves, then …
brennanb2025 Nov 18, 2026
26eea91
Drop a sign-in Start answer from a runtime the host has since replace…
brennanb2025 Nov 18, 2026
3aac1f9
Merge origin/main into Antigravity Change account
brennanb2025 Nov 18, 2026
5457a02
Merge origin/main into Antigravity Change account
brennanb2025 Nov 18, 2026
0b74a26
Merge origin/main into Antigravity Change account
brennanb2025 Nov 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/main-sync-fs-baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
8 src/main/amp/hook-service.ts
2 src/main/amp/managed-plugin-install-status.ts
1 src/main/antigravity/antigravity-host-acp.ts
1 src/main/antigravity/antigravity-sign-in-home.ts # one same-filesystem token promotion per explicit account replacement; cancellation check and success publish cannot yield (reviewed constant work)
1 src/main/antigravity/native-account-launch.ts
5 src/main/antigravity/native-account-store.ts
2 src/main/antigravity/native-credential-backend.ts
Expand Down
21 changes: 16 additions & 5 deletions src/main/antigravity/antigravity-chat-account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ import { ANTIGRAVITY_ACP_HOME } from '../../shared/agent-session/lifecycle/provi
import { ANTIGRAVITY_CHAT_HOME_FOLDER } from './antigravity-chat-home'
import { antigravityUserHome, linkAntigravityUserSkills } from './antigravity-chat-user-skills'

type SignInOwner = Pick<AcpAgentConnection, 'close' | 'onExit' | 'exited'>
const retained = new ProviderAcquisitionStarts<SignInOwner>()
type SignInOwner = Pick<AcpAgentConnection, 'close' | 'exited'> & {
onExit(listener: () => void): void
}
const retained = new ProviderAcquisitionStarts<Pick<SignInOwner, 'close' | 'onExit'>>()
const folder = hostFolderAccountBinding('GEMINI_HOME', ANTIGRAVITY_CHAT_HOME_FOLDER, [
ANTIGRAVITY_ACP_HOME
])
Expand Down Expand Up @@ -57,9 +59,18 @@ export async function closeAntigravitySignInOwner(
home: string,
connection: SignInOwner
): Promise<void> {
if (!(await connection.close().catch(() => false)) && !connection.exited) {
retained.retainFailed(home, connection)
ANTIGRAVITY_LAUNCH_GATE.retain(connection)
await connection.close().catch(() => false)
if (!connection.exited) {
// A delivered kill is not an observed exit; retries must keep the same owner.
const owner = {
close: async () => {
await connection.close().catch(() => false)
return connection.exited
},
onExit: (listener: () => void) => connection.onExit(listener)
}
retained.retainFailed(home, owner)
ANTIGRAVITY_LAUNCH_GATE.retain(owner)
throw new AntigravitySignInCloseUnprovenError()
}
}
Expand Down
147 changes: 129 additions & 18 deletions src/main/antigravity/antigravity-chat-sign-in.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as profileStorage from '../orca-profiles/profile-storage-paths'

import { existsSync } from 'node:fs'
import { createServer } from 'node:http'
import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises'
import { mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { PassThrough } from 'node:stream'
Expand All @@ -27,12 +27,14 @@ import type { RpcCallerIdentity } from '../runtime/rpc/callers/rpc-caller-identi
import { ANTIGRAVITY_ACCOUNT_METHODS } from '../runtime/rpc/methods/accounts/antigravity-accounts'
import type { AntigravityChatSignInStatus } from '../../shared/agent-accounts/antigravity/antigravity-account-types'

import { closeAntigravitySignInOwner } from './antigravity-chat-account'
import * as browserHelper from './antigravity-browser-helper'
import { ANTIGRAVITY_SIGN_IN_PROMPT } from './antigravity-sign-in-url'
import {
cancelAntigravityChatSignIn,
completeAntigravityChatSignIn,
startAntigravityChatSignIn
startAntigravityChatSignIn,
readAntigravityChatSignInStatus
} from './antigravity-chat-sign-in'

vi.mock('../provider-process/provider-process-spawn', () => ({
Expand Down Expand Up @@ -102,6 +104,9 @@ async function signInAgainst(
realLaunchSources?: boolean
/** A new server asks to sign in again, as after Google grants fewer scopes than requested. */
savedSignInUnusable?: boolean
intent?: 'signIn' | 'changeAccount'
cachedToken?: string
missingCredential?: boolean
} = {}
) {
vi.spyOn(ANTIGRAVITY_LAUNCH_SPEC.managedRuntime, 'pin').mockReturnValue(PIN)
Expand All @@ -112,9 +117,15 @@ async function signInAgainst(
)
folders.push(stateDirectory)
const folder = join(stateDirectory, 'antigravity-chat')
const tokenName =
options.authConfig?.method === 'oauth-business' ? 'acp_business_token.json' : 'acp_token.json'
await mkdir(join(folder, 'antigravity-acp'), { recursive: true })
if (options.cachedToken) {
await writeFile(join(folder, 'antigravity-acp', tokenName), options.cachedToken)
}
const [browserDone, sessionOpen] = [deferred<void>(), deferred<void>()]
// Each launch is a new server process that holds only what the sign-in saved.
const spawnServer = () => {
const spawnServer = (serverHome: string) => {
const agent = new AcpScriptedAgent()
const stderr = new PassThrough()
const signInOutput = () =>
Expand All @@ -123,11 +134,19 @@ async function signInAgainst(
)
let authenticatedHere = false
agent.on('authenticate', (frame) => {
signInOutput()
void browserDone.promise.then(() => {
void (async () => {
if (await readFile(join(serverHome, 'antigravity-acp', tokenName)).catch(() => null)) {
agent.reply(frame, {})
return
}
signInOutput()
await browserDone.promise
if (!options.missingCredential) {
await writeFile(join(serverHome, 'antigravity-acp', tokenName), 'replacement-token')
}
authenticatedHere = true
agent.reply(frame, {})
})
})()
})
agent.on('session/new', (frame) => {
if (options.savedSignInUnusable && !authenticatedHere) {
Expand All @@ -136,11 +155,11 @@ async function signInAgainst(
}
void sessionOpen.promise.then(async () => {
const { cwd } = z.object({ cwd: z.string() }).parse(frame.params)
await mkdir(join(folder, 'antigravity-acp', 'brain', SESSION), { recursive: true })
await mkdir(join(folder, 'antigravity-acp', 'conversations'), { recursive: true })
await writeFile(sessionFile(folder, '.db'), '')
await mkdir(join(serverHome, 'antigravity-acp', 'brain', SESSION), { recursive: true })
await mkdir(join(serverHome, 'antigravity-acp', 'conversations'), { recursive: true })
await writeFile(sessionFile(serverHome, '.db'), '')
await writeFile(
sessionFile(folder, '.meta'),
sessionFile(serverHome, '.meta'),
JSON.stringify({ cwd: options.metaCwd ?? cwd })
)
agent.reply(frame, { ...options.sessionResult, sessionId: SESSION })
Expand Down Expand Up @@ -185,12 +204,14 @@ async function signInAgainst(
}),
stopLiveChats: async () => {},
connect: vi.fn<ConnectAcpAgent<AcpAgentConnection>>((launch, connectionOptions) => {
const connection = createAcpAgentConnection(launch, connectionOptions, spawnServer)
const connection = createAcpAgentConnection(launch, connectionOptions, () =>
spawnServer(launch.env?.GEMINI_HOME ?? folder)
)
options.configure?.(connection)
return connection
})
}
const { flowId } = startAntigravityChatSignIn(host, DESKTOP)
const { flowId } = startAntigravityChatSignIn(host, DESKTOP, options.intent)
return {
folder,
flowId,
Expand Down Expand Up @@ -243,7 +264,7 @@ it('shows another client the sign-in without its link, and refuses it every acti
await expect(cancelAntigravityChatSignIn('phone', flowId)).rejects.toThrow('no longer active')
const pasted = 'http://127.0.0.1:41234/?state=s1&code=c1'
await expect(completeAntigravityChatSignIn('phone', flowId, pasted)).rejects.toThrow('no longer')
expect(startAntigravityChatSignIn(host, DESKTOP)).toEqual({ flowId })
expect(startAntigravityChatSignIn(host, DESKTOP)).toMatchObject({ flowId })
expect((await cancelAntigravityChatSignIn(DESKTOP, flowId))?.phase).toBe('cancelled')
expect(phone.at(-1)?.flow).toEqual({ flowId: null, phase: 'cancelled' })
watcher.close()
Expand Down Expand Up @@ -309,7 +330,7 @@ it('signs in from the address a browser on another computer ended on', async ()
'already sent'
)
openSession()
expect(await stateAfter(flowId, 'verifying')).toEqual({ flowId, phase: 'signedIn' })
expect(await stateAfter(flowId, 'verifying')).toMatchObject({ flowId, phase: 'signedIn' })
} finally {
listener.close()
}
Expand All @@ -326,7 +347,7 @@ it.each([
'fails, and drops only its own token, when a new server cannot use the saved %j sign-in',
async (authConfig, dropped, kept) => {
vi.spyOn(console, 'warn').mockImplementation(() => {})
const { flowId, folder, host, finishBrowser, openSession } = await signInAgainst(
const { flowId, folder, finishBrowser, openSession } = await signInAgainst(
printed(GOOGLE_LINK),
{ savedSignInUnusable: true, authConfig }
)
Expand All @@ -347,8 +368,98 @@ it.each([
expect(await ended.promise.finally(close)).toMatchObject({ phase: 'failed' })
expect(existsSync(token)).toBe(false)
expect(existsSync(other)).toBe(true)
// Each server's exit removes its own temp folder, so the verifier must not share the first's.
const temps = host.connect.mock.calls.map(([launch]) => launch.env?.TMPDIR)
expect(new Set(temps).size).toBe(2)
}
)

it.each([
[{ method: 'oauth-personal' } as const, 'acp_token.json'],
[
{ method: 'oauth-business', gcpProject: 'p', gcpLocation: 'global' } as const,
'acp_business_token.json'
]
])(
'changes a cached %j account only after the replacement is verified',
async (authConfig, tokenName) => {
const { flowId, folder, finishBrowser, openSession } = await signInAgainst(
printed(GOOGLE_LINK),
{
intent: 'changeAccount',
cachedToken: 'working-token',
authConfig
}
)
expect(await stateAfter(flowId, 'starting')).toMatchObject({
phase: 'waiting',
intent: 'changeAccount'
})
const token = join(folder, 'antigravity-acp', tokenName)
expect(await readFile(token, 'utf8')).toBe('working-token')
const ended = stateAfter(flowId, 'waiting')
finishBrowser()
await ended
expect(await readFile(token, 'utf8')).toBe('working-token')
const verified = stateAfter(flowId, 'verifying')
openSession()
expect(await verified).toMatchObject({ phase: 'signedIn' })
expect(await readFile(token, 'utf8')).toBe('replacement-token')
}
)

it.each(['cancel', 'unusable', 'missing'] as const)(
'retains the working account when replacement is %s',
async (failure) => {
vi.spyOn(console, 'warn').mockImplementation(() => {})
const { flowId, folder, finishBrowser, openSession } = await signInAgainst(
printed(GOOGLE_LINK),
{
intent: 'changeAccount',
cachedToken: 'working-token',
savedSignInUnusable: failure === 'unusable',
missingCredential: failure === 'missing'
}
)
expect(await stateAfter(flowId, 'starting')).toMatchObject({ phase: 'waiting' })
if (failure === 'cancel') {
await cancelAntigravityChatSignIn(DESKTOP, flowId)
} else {
const ended = Promise.withResolvers<void>()
const { close } = await follow(({ flow }) => {
if (flow?.flowId === flowId && flow.phase === 'failed') {
ended.resolve()
}
})
finishBrowser()
openSession()
await ended.promise.finally(close)
}
expect(await readFile(join(folder, 'antigravity-acp', 'acp_token.json'), 'utf8')).toBe(
'working-token'
)
expect(readAntigravityChatSignInStatus(DESKTOP).flow?.phase).toBe(
failure === 'cancel' ? 'cancelled' : 'failed'
)
}
)

it('refuses an accepted close until the sign-in process has actually exited', async () => {
let exited = false
const listeners: (() => void)[] = []
const owner = {
close: async () => true,
get exited() {
return exited
},
onExit: (listener: () => void) => {
listeners.push(listener)
}
}
try {
await expect(closeAntigravitySignInOwner('closure-test', owner)).rejects.toThrow(
'could not be stopped'
)
} finally {
exited = true
listeners.forEach((listener) => listener())
}
await expect(closeAntigravitySignInOwner('closure-test', owner)).resolves.toBeUndefined()
})
Loading
Loading