Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test(desktop-app): remove unreachable auth race recovery paths (R12-M6)
Josuéc682af1de385
diff --git a/desktop-app/src/__tests__/appService.entityChanges.test.ts b/desktop-app/src/__tests__/appService.entityChanges.test.tsindex 7065c2d0b..5b4f2f57b 100644--- a/desktop-app/src/__tests__/appService.entityChanges.test.ts+++ b/desktop-app/src/__tests__/appService.entityChanges.test.ts@@ -45,46 +45,6 @@ function setSyntheticEntityChangeSession(service: object, value: string, generatstate.entityChangeSessionGeneration = generation}-describe('AppService runtime transition ownership', () => {- it('rejects a handoff selection from an older session generation before reading profiles', async () => {- const service = new AppService() as any- service.sessionGeneration = 9-- await expect(service.selectRuntimeConfigForHandoff('saved-profile', 8)).rejects.toThrow(- 'stale_session_generation'- )- expect(service.getSessionGeneration()).toBe(9)- })-- it('does not persist an environment selection after another transition supersedes it', async () => {- const service = new AppService() as any- service.sessionGeneration = 9- service.sessionToken = 'synthetic-session-token'- service.me = { id: 'user-1', teamId: 'team-1' }- service.beginPrewarmAuthTransition = () => () => undefined- service.ensureEntityChangeConnection = vi.fn()-- let finishUploadSuspension!: () => void- service.suspendDesktopGfsUploadsForAuthBoundary = () =>- new Promise<void>(resolve => {- finishUploadSuspension = resolve- })- const persistEnvironmentSelection = vi.fn(async () => undefined)- const changing = service.applyRuntimeEnvironmentChange(persistEnvironmentSelection, 9)-- await flushAsyncWork()- expect(service.getSessionGeneration()).toBe(10)-- // A login or environment selection advances the same native owner revision.- service.sessionGeneration += 1- finishUploadSuspension()-- await expect(changing).rejects.toThrow('stale_session_generation')- expect(persistEnvironmentSelection).not.toHaveBeenCalled()- expect(service.entityChangeEnvironmentSwitching).toBe(false)- })-})-describe('AppService entity-change fan-out', () => {it('rebinds a live subscriber after expiry through public Google login', async () => {const service = new AppService() as any@@ -228,61 +188,7 @@ describe('AppService entity-change fan-out', () => {})})-describe('AppService.startEntityChangeStream session expiry', () => {- it('does not retry an old committed token against a changing environment', async () => {- vi.useFakeTimers()- vi.spyOn(Math, 'random').mockReturnValue(0)- const originalBaseUrl = config.externalRestApiBaseUrl- const environmentA = 'https://environment-a.example'- const environmentB = 'https://environment-b.example'- config.externalRestApiBaseUrl = environmentA- const service = new AppService() as any- setSyntheticSessionToken(service, 'synthetic-environment-a-committed-token')- service.me = { id: 'user-1', teamId: 'team-1' }- service.beginPrewarmAuthTransition = () => () => undefined- service.suspendDesktopGfsUploadsForAuthBoundary = vi.fn().mockResolvedValue(undefined)- service.activateGfsAuthScope = vi.fn()- service.stopAllStreams = vi.fn()- service.tokenStore = { clearSessionToken: vi.fn().mockResolvedValue(undefined) }- const opened: Array<{ token: string; baseUrl: string }> = []- service.authClient = {- openEntityChangeStream: vi.fn(async (token: string) => {- opened.push({ token, baseUrl: config.externalRestApiBaseUrl })- throw new Error('temporary connection failure')- }),- }-- let finishPersistence!: () => void- try {- service.startEntityChangeStream('stream-1', 7, vi.fn())- await flushAsyncWork()- expect(opened).toEqual([- { token: 'synthetic-environment-a-committed-token', baseUrl: environmentA },- ])-- const switching = service.applyRuntimeEnvironmentChange(async () => {- config.externalRestApiBaseUrl = environmentB- await new Promise<void>(resolve => {- finishPersistence = resolve- })- })- await flushAsyncWork()- await vi.advanceTimersByTimeAsync(1_000)- await flushAsyncWork()-- expect(opened).toHaveLength(1)- finishPersistence()- await switching- expect(service.sessionToken).toBeNull()- expect(opened).toHaveLength(1)- } finally {- config.externalRestApiBaseUrl = originalBaseUrl- service.stopEntityChangeStream('stream-1', 7)- vi.useRealTimers()- vi.restoreAllMocks()- }- })-+describe('AppService entity-change reconnect behavior', () => {it('does not reset reconnect backoff on synthetic transport-open callbacks', async () => {vi.useFakeTimers()vi.spyOn(Math, 'random').mockReturnValue(0)@@ -569,7 +475,7 @@ describe('AppService entity-change stream team-context lifecycle', () => {expect(opened[0]?.token).toBe('committed-session-token')const teamOperation = service.runWithTeamContext('team-b', async () => operationGate)- await flushAsyncWork()+ await flushAsyncWork(20)expect(service.sessionToken).toBe('transient-team-context-token')finishFirstStream()diff --git a/desktop-app/src/__tests__/appService.nativeLogoutRecovery.test.ts b/desktop-app/src/__tests__/appService.nativeLogoutRecovery.test.tsindex d4cc1d74f..b81eae0f0 100644--- a/desktop-app/src/__tests__/appService.nativeLogoutRecovery.test.ts+++ b/desktop-app/src/__tests__/appService.nativeLogoutRecovery.test.ts@@ -2,48 +2,38 @@ import { afterEach, describe, expect, it, vi } from 'vitest'import {cleanupNativeCommitTestHarness,createNativeCommitTestHarness,- deferred,} from '../../testSupport/appService.nativeCommitTestHarness.js'afterEach(cleanupNativeCommitTestHarness)describe('AppService logout recovery ownership', () => {- it('fails closed when token removal completes after the runtime boundary changes', async () => {- const { service, runtimeConfig, optionB, restB } = await createNativeCommitTestHarness()+ it('keeps the current session when token removal fails on the same runtime boundary', async () => {+ const { service } = await createNativeCommitTestHarness()service.authClient = {googleLogin: vi.fn().mockResolvedValue({token: 'synthetic-session-a',- me: { id: 'user-a' },+ me: {+ id: 'user-a',+ email: '[email protected]',+ name: 'User A',+ picture: null,+ teamId: 'team-a',+ teamName: 'Team A',+ role: 'member',+ },}),} as neverawait service.googleLogin('initial-login')+ const app = service as unknown as { activateGfsAuthScope: () => void }+ const restoreAuthScope = vi.spyOn(app, 'activateGfsAuthScope')+ service.tokenStore.clearSessionToken = vi+ .fn()+ .mockRejectedValue(new Error('keychain unavailable'))- const tokenRemovalStarted = deferred<void>()- const releaseTokenRemoval = deferred<void>()- service.tokenStore.clearSessionToken = vi.fn(async () => {- tokenRemovalStarted.resolve()- await releaseTokenRemoval.promise- })+ await expect(service.logout()).rejects.toThrow('keychain unavailable')- const logout = service.logout().then(- value => ({ status: 'fulfilled' as const, value }),- reason => ({ status: 'rejected' as const, reason })- )- await tokenRemovalStarted.promise- await runtimeConfig.selectDesktopRuntimeConfigOption(optionB.id)- const testService = service as unknown as { sessionGeneration: number }- testService.sessionGeneration += 1- releaseTokenRemoval.resolve()- const logoutOutcome = await logout-- expect(logoutOutcome.status).toBe('rejected')- expect(service.getCachedUserId()).toBeNull()- await expect(service.listGfsUploadSessions()).rejects.toThrow(- 'GFS upload dispatch is unavailable without an active authenticated scope'- )- expect(service.gfsScopeIdentity).toBeNull()- expect(runtimeConfig.getDesktopRuntimeConfigState().currentConfig.externalRestApiBaseUrl).toBe(- restB- )+ expect(service.getCachedUserId()).toBe('user-a')+ expect(service.sessionToken).toBe('synthetic-session-a')+ expect(restoreAuthScope).toHaveBeenCalledOnce()})})diff --git a/desktop-app/src/__tests__/appService.teamTransitionOwnership.test.ts b/desktop-app/src/__tests__/appService.teamTransitionOwnership.test.tsindex fea3e65ab..484062a42 100644--- a/desktop-app/src/__tests__/appService.teamTransitionOwnership.test.ts+++ b/desktop-app/src/__tests__/appService.teamTransitionOwnership.test.ts@@ -8,6 +8,35 @@ import {afterEach(cleanupNativeCommitTestHarness)describe('AppService deliberate team transition ownership', () => {+ it('rejects a stale handoff generation after a public login advances the session', async () => {+ const { service, runtimeConfig, optionA } = await createNativeCommitTestHarness()+ const app = service as unknown as {+ authClient: unknown+ selectRuntimeConfigForHandoff(optionId: string, generation: number): Promise<unknown>+ }+ app.authClient = {+ googleLogin: vi.fn().mockResolvedValue({+ token: 'session-a',+ me: {+ id: 'user-a',+ email: '[email protected]',+ name: 'User A',+ picture: null,+ teamId: 'team-a',+ teamName: 'Team A',+ role: 'member',+ },+ }),+ }+ const previousGeneration = service.getSessionGeneration()+ await service.googleLogin('synthetic-google-token')++ await expect(app.selectRuntimeConfigForHandoff(optionA.id, previousGeneration)).rejects.toThrow(+ 'stale_session_generation'+ )+ expect(runtimeConfig.getDesktopRuntimeConfigState().activeOptionId).toBe(optionA.id)+ })+it('does not let REST discovery block logout or overwrite a later session revision', async () => {const { service, runtimeConfig, restA } = await createNativeCommitTestHarness()await runtimeConfig.saveDesktopRuntimeConfig({diff --git a/desktop-app/src/appService.ts b/desktop-app/src/appService.tsindex 958fd7bfc..a3ee4e218 100644--- a/desktop-app/src/appService.ts+++ b/desktop-app/src/appService.ts@@ -1878,20 +1878,6 @@ export class AppService {const environmentUnchanged =getActiveEnvKey() === oldEnvKey &&normalizeDesktopUploadBaseUrl(config.externalRestApiBaseUrl) === oldBaseUrl- if (this.sessionGeneration !== transitionGeneration) {- if (!environmentUnchanged) {- this.clearAuthenticatedSessionState()- await this.tokenStore- .clearSessionToken(oldEnvKey, { legacyEnvKeys: oldLegacyEnvKeys })- .catch(() => undefined)- } else if (this.sessionToken === oldSessionToken && this.me === oldMe) {- this.clearAuthenticatedSessionState()- await this.tokenStore- .clearSessionToken(oldEnvKey, { legacyEnvKeys: oldLegacyEnvKeys })- .catch(() => undefined)- }- throw new Error('stale_session_generation')- }if (!environmentUnchanged) {this.clearAuthenticatedSessionState()await this.tokenStore@@ -2429,11 +2415,6 @@ export class AppService {logoutEnvironment.restBaseUrlif (capturedSessionStillOwnsBoundary) {if (logoutToken && logoutMe) this.activateGfsAuthScope()- } else if (this.sessionToken === logoutToken && this.me === logoutMe) {- this.clearAuthenticatedSessionState()- await this.tokenStore- .clearSessionToken(envKey, { legacyEnvKeys })- .catch(() => undefined)}throw error}