diff --git a/src/main/antigravity/native-account-service.test.ts b/src/main/antigravity/native-account-service.test.ts index e52d9c37b51..6ea2ce9cc99 100644 --- a/src/main/antigravity/native-account-service.test.ts +++ b/src/main/antigravity/native-account-service.test.ts @@ -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') + }) }) diff --git a/src/main/antigravity/native-account-service.ts b/src/main/antigravity/native-account-service.ts index 29c81524f9a..2f1e8133db4 100644 --- a/src/main/antigravity/native-account-service.ts +++ b/src/main/antigravity/native-account-service.ts @@ -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))