Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop-app): guard r8-h2 logout scope recovery
Josuéc87305dfebab
diff --git a/desktop-app/src/__tests__/appService.nativeLogoutRecovery.test.ts b/desktop-app/src/__tests__/appService.nativeLogoutRecovery.test.tsnew file mode 100644index 000000000..b6e0c11cd--- /dev/null+++ b/desktop-app/src/__tests__/appService.nativeLogoutRecovery.test.ts@@ -0,0 +1,46 @@+import { afterEach, describe, expect, it, vi } from 'vitest'+import {+ cleanupNativeCommitTestHarness,+ createNativeCommitTestHarness,+ deferred,+} from './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()+ service.authClient = {+ googleLogin: vi.fn().mockResolvedValue({ token: 'session-a', me: { id: 'user-a' } }),+ } as never+ await service.googleLogin('initial-login')++ const tokenRemovalStarted = deferred<void>()+ const releaseTokenRemoval = deferred<void>()+ service.tokenStore.clearSessionToken = vi.fn(async () => {+ tokenRemovalStarted.resolve()+ await releaseTokenRemoval.promise+ })++ 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+ )+ })+})diff --git a/desktop-app/src/appService.ts b/desktop-app/src/appService.tsindex c896efc0e..a2b34a7a9 100644--- a/desktop-app/src/appService.ts+++ b/desktop-app/src/appService.ts@@ -2314,6 +2314,9 @@ export class AppService {this.logoutInProgress = truethis.sessionGeneration += 1const logoutGeneration = this.sessionGeneration+ const logoutToken = this.sessionToken+ const logoutMe = this.me+ const logoutEnvironment = this.captureAuthEnvironmentBinding()const releasePrewarm = this.beginPrewarmAuthTransition()try {const envKey = getActiveEnvKey()@@ -2324,7 +2327,21 @@ export class AppService {await this.tokenStore.clearSessionToken(envKey, { legacyEnvKeys })this.assertSessionGeneration(logoutGeneration)} catch (error) {- if (this.sessionToken && this.me) this.activateGfsAuthScope()+ const capturedSessionStillOwnsBoundary =+ this.sessionGeneration === logoutGeneration &&+ this.sessionToken === logoutToken &&+ this.me === logoutMe &&+ getActiveEnvKey() === logoutEnvironment.environmentKey &&+ normalizeDesktopUploadBaseUrl(config.externalRestApiBaseUrl) ===+ logoutEnvironment.restBaseUrl+ if (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}this.clearAuthenticatedSessionState()