fix(antigravity): guard active account removal (#21797)

This commit is contained in:
Neil
2026-09-20 18:04:21 -07:00
committed by GitHub
parent 7bfd2dbe4d
commit 2e59daeab9
2 changed files with 14 additions and 1 deletions
@@ -69,4 +69,15 @@ describe('AntigravityAccountService', () => {
await expect(service.removeAccount(account.id)).rejects.toThrow('active account')
await expect(service.selectAccount('missing')).rejects.toThrow('was not found')
})
it('protects the active account even before the first list refresh', async () => {
const active = backend(first)
const account = createSyntheticAntigravityAccount(first)
const service = new AntigravityAccountService(
createMemoryAntigravityAccountStore([account]),
active
)
await expect(service.removeAccount(account.id)).rejects.toThrow('active account')
})
})
@@ -107,7 +107,9 @@ export class AntigravityAccountService {
if (!accounts.some((account) => account.id === id)) {
throw new Error('Antigravity account was not found.')
}
if (this.activeAccountId === id) {
// Resolve the native credential here too; callers may remove before the first list refresh.
const active = await this.knownActiveAccount(accounts)
if (active?.id === id || this.activeAccountId === id) {
throw new Error('Select another Antigravity account before removing the active account.')
}
this.store.write(accounts.filter((account) => account.id !== id))