Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop): finish RPC discovery before Google login dispatch (R13-M4)
Josué415756560de1
diff --git a/desktop-app/src/__tests__/appService.teamTransitionOwnership.test.ts b/desktop-app/src/__tests__/appService.teamTransitionOwnership.test.tsindex 75e87f3a2..4400a35a4 100644--- a/desktop-app/src/__tests__/appService.teamTransitionOwnership.test.ts+++ b/desktop-app/src/__tests__/appService.teamTransitionOwnership.test.ts@@ -129,6 +129,78 @@ describe('AppService deliberate team transition ownership', () => {await expect(restore).resolves.toEqual({ authenticated: true, me })})+ it('accepts Google login when RPC discovery enriches its captured REST profile', async () => {+ const { service, runtimeConfig, restA } = await createNativeCommitTestHarness()+ await runtimeConfig.saveDesktopRuntimeConfig({+ externalRestApiBaseUrl: restA,+ rpcProxyBaseUrl: '',+ appName: 'Environment A',+ })+ const discovery = deferred<{+ externalRestApiBaseUrl: string+ rpcProxyBaseUrl: string+ appName: string+ }>()+ const discoveryStarted = deferred<void>()+ const getDesktopEnvironment = vi.fn(() => {+ discoveryStarted.resolve()+ return discovery.promise+ })+ const loginResponse = deferred<{+ token: string+ me: {+ id: string+ email: string+ name: string+ picture: null+ teamId: string+ teamName: string+ role: string+ }+ }>()+ const loginStarted = deferred<void>()+ const me = {+ id: 'user-a',+ email: '[email protected]',+ name: 'User A',+ picture: null,+ teamId: 'team-a',+ teamName: 'Team A',+ role: 'member',+ }+ const app = service as unknown as {+ authClient: unknown+ rpcClient: unknown+ getDependenciesHealth(): Promise<unknown>+ }+ const googleLogin = vi.fn(() => {+ loginStarted.resolve()+ return loginResponse.promise+ })+ app.authClient = {+ getDesktopEnvironment,+ googleLogin,+ health: vi.fn().mockResolvedValue({ status: 'ok' }),+ }+ app.rpcClient = { health: vi.fn().mockResolvedValue({ status: 'ok' }) }++ const login = service.googleLogin('synthetic-google-token')+ const healthRequest = app.getDependenciesHealth()+ await discoveryStarted.promise+ await new Promise(resolve => setTimeout(resolve, 0))+ expect(googleLogin).not.toHaveBeenCalled()+ discovery.resolve({+ externalRestApiBaseUrl: restA,+ rpcProxyBaseUrl: 'https://rpc-discovered.example.test',+ appName: 'Environment A',+ })+ await healthRequest+ await loginStarted.promise+ loginResponse.resolve({ token: 'session-a', me })++ await expect(login).resolves.toEqual({ authenticated: true, me })+ })+it('keeps the public session generation stable through transient team hops', async () => {const { service } = await createNativeCommitTestHarness()const meA = {diff --git a/desktop-app/src/appService.ts b/desktop-app/src/appService.tsindex b00b434c7..a36ee2589 100644--- a/desktop-app/src/appService.ts+++ b/desktop-app/src/appService.ts@@ -2040,20 +2040,30 @@ export class AppService {let loginRequest: ReturnType<AuthClient['googleLogin']> | undefinedlet registered = falsetry {- const attempt = await this.withNativeAuthEnvironmentCommit(async () => {+ const sessionGeneration = await this.withNativeAuthEnvironmentCommit(async () => {const sessionGeneration = ++this.sessionGeneration- const binding = this.captureAuthEnvironmentBinding()- loginRequest = this.authClient.googleLogin(idToken)this.interactiveLoginAttempts += 1registered = true- return { sessionGeneration, binding }+ return sessionGeneration})++ await this.resolveRuntimeConfigIfNeeded()+ const binding = await this.withNativeAuthEnvironmentCommit(async () => {+ this.assertSessionGeneration(sessionGeneration)+ return this.captureAuthEnvironmentBinding()+ })+ const dispatch = await this.withNativeAuthEnvironmentCommit(async () => {+ this.assertSessionGeneration(sessionGeneration)+ this.assertAuthEnvironmentBinding(binding)+ return { request: this.authClient.googleLogin(idToken) }+ })+ loginRequest = dispatch.requestif (!loginRequest) throw new Error('Google login request was not dispatched')const result = await loginRequestreturn await this.withNativeAuthEnvironmentCommit(async () => {- this.assertSessionGeneration(attempt.sessionGeneration)- this.assertAuthEnvironmentBinding(attempt.binding)- return this.installAuthenticatedLogin(result, attempt.sessionGeneration)+ this.assertSessionGeneration(sessionGeneration)+ this.assertAuthEnvironmentBinding(binding)+ return this.installAuthenticatedLogin(result, sessionGeneration)})} finally {if (registered) {