Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop-app): r19-l2 use generation for setup races
Josuébb82abf2fd7a
diff --git a/desktop-app/src/__tests__/appService.nativeCommit.test.ts b/desktop-app/src/__tests__/appService.nativeCommit.test.tsindex 9af8ac307..92b04df53 100644--- a/desktop-app/src/__tests__/appService.nativeCommit.test.ts+++ b/desktop-app/src/__tests__/appService.nativeCommit.test.ts@@ -160,6 +160,45 @@ describe('AppService native auth and environment commit ordering', () => {expect(service.getSessionGeneration()).toBe(generationDuringLogin + 1)})+ it('uses the captured generation when login wins before setup dispatch', async () => {+ const { service } = await createNativeCommitTestHarness()+ const me = { id: 'user-a', email: '[email protected]', teamId: 'team-a' }+ service.authClient = {+ googleLogin: vi.fn().mockResolvedValue({ token: 'synthetic-session-a', me }),+ } as never+ const setupRequest = vi.fn().mockResolvedValue({+ valid: true,+ email: '[email protected]',+ externalRestApiBaseUrl: 'https://api-b.example.test',+ rpcProxyBaseUrl: 'https://rpc-b.example.test',+ appName: 'Environment B',+ })+ const app = service as unknown as {+ memberRegistrationServiceClient: { completeDesktopSetup: typeof setupRequest }+ completeDesktopSetup: (email: string, authorizationToken: string) => Promise<unknown>+ withNativeAuthEnvironmentCommit<T>(operation: () => Promise<T>): Promise<T>+ }+ app.memberRegistrationServiceClient = { completeDesktopSetup: setupRequest }+ const originalCommit = app.withNativeAuthEnvironmentCommit.bind(service)+ let commitCount = 0+ app.withNativeAuthEnvironmentCommit = async operation => {+ commitCount += 1+ if (commitCount === 2) {+ app.withNativeAuthEnvironmentCommit = originalCommit+ await service.googleLogin('synthetic-login-before-setup-dispatch')+ }+ return originalCommit(operation)+ }++ await expect(+ app.completeDesktopSetup('[email protected]', 'synthetic-setup-token')+ ).rejects.toThrow('stale_session_generation')++ expect(setupRequest).not.toHaveBeenCalled()+ expect(service.sessionToken).toBe('synthetic-session-a')+ expect(service.getCachedUserId()).toBe('user-a')+ })+it('rejects handoff environment saves after auth changes or while auth is active', async () => {const { service, runtimeConfig, optionB, restA, restB } = await createNativeCommitTestHarness()const loginStarted = deferred<void>()diff --git a/desktop-app/src/__tests__/appService.setupRestoreRace.test.ts b/desktop-app/src/__tests__/appService.setupRestoreRace.test.tsindex 78e0a3988..f999aecac 100644--- a/desktop-app/src/__tests__/appService.setupRestoreRace.test.ts+++ b/desktop-app/src/__tests__/appService.setupRestoreRace.test.ts@@ -138,7 +138,7 @@ describe('AppService setup and saved-session ownership', () => {appName: 'Environment B',})- await expect(setup).rejects.toThrow('desktop_setup_requires_signout')+ await expect(setup).rejects.toThrow('stale_session_generation')expect(setupRequest).toHaveBeenCalledOnce()expect(runtimeConfig.config.externalRestApiBaseUrl).toBe(restA)expect(app.getSessionGeneration()).toBe(restoredGeneration)diff --git a/desktop-app/src/appService.ts b/desktop-app/src/appService.tsindex 961eefab0..604875fc1 100644--- a/desktop-app/src/appService.ts+++ b/desktop-app/src/appService.ts@@ -2290,7 +2290,6 @@ export class AppService {| ReturnType<MemberRegistrationServiceClient['completeDesktopSetup']>| undefinedawait this.withNativeAuthEnvironmentCommit(async () => {- this.assertProfileHandoffSessionIsSignedOut()this.assertSessionGeneration(setupGeneration)setupRequest = this.memberRegistrationServiceClient.completeDesktopSetup(normalizedEmail,@@ -2306,7 +2305,6 @@ export class AppService {}const committedGeneration = await this.withNativeAuthEnvironmentCommit(async () => {- this.assertProfileHandoffSessionIsSignedOut()this.assertSessionGeneration(setupGeneration)await saveDesktopRuntimeConfig({externalRestApiBaseUrl: activation.externalRestApiBaseUrl,