Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(desktop-app): fence setup during login (R17-L3)

Josuéd7145f7d1779
diff --git a/desktop-app/src/__tests__/appService.nativeCommit.test.ts b/desktop-app/src/__tests__/appService.nativeCommit.test.ts
index a2e92fe4a..9af8ac307 100644
--- a/desktop-app/src/__tests__/appService.nativeCommit.test.ts
+++ b/desktop-app/src/__tests__/appService.nativeCommit.test.ts
@@ -114,6 +114,52 @@ describe('AppService native auth and environment commit ordering', () => {
expect(service.gfsScopeIdentity).toEqual(gfsScopeBeforeSetup)
})
+ it('rejects desktop setup while an explicit login is in flight', async () => {
+ const { service } = await createNativeCommitTestHarness()
+ const loginStarted = deferred<void>()
+ const loginResponse = deferred<{
+ token: string
+ me: { id: string; email: string; teamId: string }
+ }>()
+ const me = { id: 'user-a', email: '[email protected]', teamId: 'team-a' }
+ service.authClient = {
+ googleLogin: vi.fn(() => {
+ loginStarted.resolve()
+ return loginResponse.promise
+ }),
+ } as never
+ const setupRequest = vi.fn().mockRejectedValue(new Error('unexpected setup dispatch'))
+ const serviceInternals = service as unknown as {
+ memberRegistrationServiceClient: { completeDesktopSetup: typeof setupRequest }
+ completeDesktopSetup: (email: string, authorizationToken: string) => Promise<unknown>
+ }
+ serviceInternals.memberRegistrationServiceClient = { completeDesktopSetup: setupRequest }
+
+ const login = service.googleLogin('synthetic-google-token')
+ await loginStarted.promise
+ const generationDuringLogin = service.getSessionGeneration()
+ const setupOutcome = await serviceInternals
+ .completeDesktopSetup('[email protected]', 'synthetic-setup-token')
+ .then(
+ () => ({ error: null as unknown }),
+ error => ({ error })
+ )
+ const generationAfterSetup = service.getSessionGeneration()
+ loginResponse.resolve({ token: 'synthetic-session-a', me })
+ const loginOutcome = await login.then(
+ result => ({ result, error: null as unknown }),
+ error => ({ result: null, error })
+ )
+
+ expect(setupOutcome.error).toBeInstanceOf(Error)
+ expect((setupOutcome.error as Error).message).toBe('auth_transition_in_progress')
+ expect(setupRequest).not.toHaveBeenCalled()
+ expect(generationAfterSetup).toBe(generationDuringLogin)
+ expect(loginOutcome.error).toBeNull()
+ expect(loginOutcome.result).toMatchObject({ authenticated: true, me })
+ expect(service.getSessionGeneration()).toBe(generationDuringLogin + 1)
+ })
+
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/appService.ts b/desktop-app/src/appService.ts
index 5b5a46211..42de93d2c 100644
--- a/desktop-app/src/appService.ts
+++ b/desktop-app/src/appService.ts
@@ -2220,15 +2220,14 @@ export class AppService {
throw new Error('email and authorization token are required')
}
const setupGeneration = await this.withNativeAuthEnvironmentCommit(async () => {
- if (this.sessionToken && this.me) {
- throw new Error('desktop_setup_requires_signout')
- }
+ this.assertProfileHandoffSessionIsSignedOut()
return ++this.sessionGeneration
})
let setupRequest:
| ReturnType<MemberRegistrationServiceClient['completeDesktopSetup']>
| undefined
await this.withNativeAuthEnvironmentCommit(async () => {
+ this.assertProfileHandoffSessionIsSignedOut()
this.assertSessionGeneration(setupGeneration)
setupRequest = this.memberRegistrationServiceClient.completeDesktopSetup(
normalizedEmail,
@@ -2244,9 +2243,7 @@ export class AppService {
}
const committedGeneration = await this.withNativeAuthEnvironmentCommit(async () => {
- if (this.sessionToken && this.me) {
- throw new Error('desktop_setup_requires_signout')
- }
+ this.assertProfileHandoffSessionIsSignedOut()
this.assertSessionGeneration(setupGeneration)
await saveDesktopRuntimeConfig({
externalRestApiBaseUrl: activation.externalRestApiBaseUrl,