Skip to content

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

TypeScript

test: use native auth producers in handoff coverage

Josué015d9f0fd3ca
diff --git a/desktop-app/src/__tests__/appService.teamTransitionOwnership.test.ts b/desktop-app/src/__tests__/appService.teamTransitionOwnership.test.ts
index ad9b03fe4..03b47f932 100644
--- a/desktop-app/src/__tests__/appService.teamTransitionOwnership.test.ts
+++ b/desktop-app/src/__tests__/appService.teamTransitionOwnership.test.ts
@@ -4,6 +4,11 @@ import {
createNativeCommitTestHarness,
deferred,
} from '../../testSupport/appService.nativeCommitTestHarness.js'
+import {
+ testLoginResult,
+ testSessionMe,
+ testTeamSwitchResult,
+} from '../../testSupport/authTestFixtures.js'
afterEach(async () => {
vi.useRealTimers()
@@ -16,15 +21,7 @@ describe('AppService deliberate team transition ownership', () => {
const decisionResponse = deferred<{ approvalId: string; status: string }>()
const decisionStarted = deferred<void>()
const logoutCleanupStarted = vi.fn()
- const me = {
- id: 'user-a',
- email: '[email protected]',
- name: 'User A',
- picture: null,
- teamId: 'team-a',
- teamName: 'Team A',
- role: 'member',
- }
+ const me = testSessionMe()
const app = service as unknown as {
authClient: unknown
decideWorkflowApproval(
@@ -36,7 +33,7 @@ describe('AppService deliberate team transition ownership', () => {
suspendDesktopGfsUploadsForAuthBoundary: () => Promise<void>
}
app.authClient = {
- googleLogin: vi.fn().mockResolvedValue({ token: 'synthetic-session-a', me }),
+ googleLogin: vi.fn().mockResolvedValue(testLoginResult('synthetic-session-a', me)),
decideWorkflowApproval: vi.fn(() => {
decisionStarted.resolve()
return decisionResponse.promise
@@ -74,25 +71,9 @@ describe('AppService deliberate team transition ownership', () => {
appName: string
}>()
const discoveryStarted = deferred<void>()
- const getMeResponse = deferred<{
- id: string
- email: string
- name: string
- picture: null
- teamId: string
- teamName: string
- role: string
- }>()
+ const getMeResponse = deferred<ReturnType<typeof testSessionMe>>()
const getMeStarted = deferred<void>()
- const me = {
- id: 'user-a',
- email: '[email protected]',
- name: 'User A',
- picture: null,
- teamId: 'team-a',
- teamName: 'Team A',
- role: 'member',
- }
+ const me = testSessionMe()
const app = service as unknown as {
authClient: unknown
rpcClient: unknown
@@ -149,28 +130,9 @@ describe('AppService deliberate team transition ownership', () => {
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 loginResponse = deferred<ReturnType<typeof testLoginResult>>()
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 me = testSessionMe()
const app = service as unknown as {
authClient: unknown
rpcClient: unknown
@@ -199,7 +161,7 @@ describe('AppService deliberate team transition ownership', () => {
})
await healthRequest
await loginStarted.promise
- loginResponse.resolve({ token: 'synthetic-session-a', me })
+ loginResponse.resolve(testLoginResult('synthetic-session-a', me))
await expect(login).resolves.toEqual({ authenticated: true, me })
})
@@ -212,15 +174,7 @@ describe('AppService deliberate team transition ownership', () => {
appName: string
}>()
const discoveryStarted = deferred<void>()
- const me = {
- id: 'user-a',
- email: '[email protected]',
- name: 'User A',
- picture: null,
- teamId: 'team-a',
- teamName: 'Team A',
- role: 'member',
- }
+ const me = testSessionMe()
const app = service as unknown as {
authClient: unknown
rpcClient: unknown
@@ -272,16 +226,8 @@ describe('AppService deliberate team transition ownership', () => {
const { service } = await createNativeCommitTestHarness()
const workflowResponse = deferred<{ workflow: string }>()
const workflowStarted = deferred<void>()
- const meA = {
- id: 'user-a',
- email: '[email protected]',
- name: 'User A',
- picture: null,
- teamId: 'team-a',
- teamName: 'Team A',
- role: 'member',
- }
- const meB = { ...meA, teamId: 'team-b', teamName: 'Team B' }
+ const meA = testSessionMe()
+ const meB = testSessionMe({ teamId: 'team-b', teamName: 'Team B' })
const app = service as unknown as {
authClient: unknown
rpcClient: unknown
@@ -293,10 +239,10 @@ describe('AppService deliberate team transition ownership', () => {
}
let currentTeamId = 'team-a'
app.authClient = {
- googleLogin: vi.fn().mockResolvedValue({ token: 'synthetic-session-a', me: meA }),
+ googleLogin: vi.fn().mockResolvedValue(testLoginResult('synthetic-session-a', meA)),
switchTeam: vi.fn(async (_token: string, teamId: string) => {
currentTeamId = teamId
- return { token: `session-${teamId}`, team: { id: teamId, name: teamId, role: 'member' } }
+ return testTeamSwitchResult(teamId)
}),
getMe: vi.fn(async () => (currentTeamId === 'team-a' ? meA : meB)),
readWorkflow: vi.fn(() => {
@@ -340,16 +286,8 @@ describe('AppService deliberate team transition ownership', () => {
it('advances session generation when a failed restore leaves the borrowed team active', async () => {
const { service } = await createNativeCommitTestHarness()
- const meA = {
- id: 'user-a',
- email: '[email protected]',
- name: 'User A',
- picture: null,
- teamId: 'team-a',
- teamName: 'Team A',
- role: 'member',
- }
- const meB = { ...meA, teamId: 'team-b', teamName: 'Team B' }
+ const meA = testSessionMe()
+ const meB = testSessionMe({ teamId: 'team-b', teamName: 'Team B' })
const app = service as unknown as {
authClient: unknown
me: { teamId: string } | null
@@ -361,13 +299,13 @@ describe('AppService deliberate team transition ownership', () => {
}
let currentTeamId = 'team-a'
app.authClient = {
- googleLogin: vi.fn().mockResolvedValue({ token: 'synthetic-session-a', me: meA }),
+ googleLogin: vi.fn().mockResolvedValue(testLoginResult('synthetic-session-a', meA)),
switchTeam: vi.fn(async (_token: string, teamId: string) => {
if (teamId === 'team-a' && currentTeamId === 'team-b') {
throw new Error('restore rejected')
}
currentTeamId = teamId
- return { token: `session-${teamId}`, team: { id: teamId, name: teamId, role: 'member' } }
+ return testTeamSwitchResult(teamId)
}),
getMe: vi.fn(async () => (currentTeamId === 'team-a' ? meA : meB)),
readWorkflow: vi.fn().mockResolvedValue({ workflow: 'result' }),
@@ -392,20 +330,12 @@ describe('AppService deliberate team transition ownership', () => {
rpcProxyBaseUrl: '',
appName: 'Environment A',
})
- const me = {
- id: 'user-a',
- email: '[email protected]',
- name: 'User A',
- picture: null,
- teamId: 'team-a',
- teamName: 'Team A',
- role: 'member',
- }
+ const me = testSessionMe()
const getDesktopEnvironment = vi
.fn()
.mockRejectedValue(new Error('RPC discovery unavailable'))
- const googleLogin = vi.fn().mockResolvedValue({ token: 'google-session-a', me })
- const passwordLogin = vi.fn().mockResolvedValue({ token: 'password-session-a', me })
+ const googleLogin = vi.fn().mockResolvedValue(testLoginResult('google-session-a', me))
+ const passwordLogin = vi.fn().mockResolvedValue(testLoginResult('password-session-a', me))
const app = service as unknown as { authClient: unknown }
app.authClient = { getDesktopEnvironment, googleLogin, passwordLogin }
@@ -433,18 +363,7 @@ describe('AppService deliberate team transition ownership', () => {
selectRuntimeConfigForHandoff(optionId: string, generation: number): Promise<unknown>
}
app.authClient = {
- googleLogin: vi.fn().mockResolvedValue({
- token: 'fixture-session-a',
- me: {
- id: 'user-a',
- email: '[email protected]',
- name: 'User A',
- picture: null,
- teamId: 'team-a',
- teamName: 'Team A',
- role: 'member',
- },
- }),
+ googleLogin: vi.fn().mockResolvedValue(testLoginResult('fixture-session-a')),
}
const previousGeneration = service.getSessionGeneration()
await service.googleLogin('synthetic-google-token')
@@ -476,18 +395,7 @@ describe('AppService deliberate team transition ownership', () => {
getDependenciesHealth(): Promise<unknown>
}
app.authClient = {
- googleLogin: vi.fn().mockResolvedValue({
- token: 'synthetic-session-a',
- me: {
- id: 'user-a',
- email: '[email protected]',
- name: 'User A',
- picture: null,
- teamId: 'team-a',
- teamName: 'Team A',
- role: 'member',
- },
- }),
+ googleLogin: vi.fn().mockResolvedValue(testLoginResult()),
getDesktopEnvironment,
health: vi.fn().mockResolvedValue({ status: 'ok' }),
}
@@ -535,18 +443,7 @@ describe('AppService deliberate team transition ownership', () => {
suspendDesktopGfsUploadsForAuthBoundary: () => Promise<void>
}
app.authClient = {
- googleLogin: vi.fn().mockResolvedValue({
- token: 'synthetic-session-a',
- me: {
- id: 'user-a',
- email: '[email protected]',
- name: 'User A',
- picture: null,
- teamId: 'team-a',
- teamName: 'Team A',
- role: 'member',
- },
- }),
+ googleLogin: vi.fn().mockResolvedValue(testLoginResult()),
}
await service.googleLogin('synthetic-google-token')
app.suspendDesktopGfsUploadsForAuthBoundary = vi.fn().mockResolvedValue(undefined)
@@ -565,15 +462,7 @@ describe('AppService deliberate team transition ownership', () => {
it('lets logout commit during teamless session scope discovery', async () => {
const { service } = await createNativeCommitTestHarness()
- const meResponse = deferred<{
- id: string
- email: string
- name: string
- picture: null
- teamId: string
- teamName: string
- role: string
- }>()
+ const meResponse = deferred<ReturnType<typeof testSessionMe>>()
const discoveryStarted = deferred<void>()
const logoutStarted = deferred<void>()
const app = service as unknown as {
@@ -592,18 +481,15 @@ describe('AppService deliberate team transition ownership', () => {
suspendDesktopGfsUploadsForAuthBoundary: () => Promise<void>
}
app.authClient = {
- googleLogin: vi.fn().mockResolvedValue({
- token: 'synthetic-session-a',
- me: {
- id: 'user-a',
- email: '[email protected]',
- name: 'User A',
- picture: null,
- teamId: null,
- teamName: null,
- role: 'member',
- },
- }),
+ googleLogin: vi.fn().mockResolvedValue(
+ testLoginResult(
+ 'synthetic-session-a',
+ testSessionMe({
+ teamId: null,
+ teamName: null,
+ })
+ )
+ ),
getMe: vi.fn(() => {
discoveryStarted.resolve()
return meResponse.promise
@@ -620,15 +506,7 @@ describe('AppService deliberate team transition ownership', () => {
logoutStarted.promise.then(() => true),
new Promise<boolean>(resolve => setTimeout(() => resolve(false), 50)),
])
- meResponse.resolve({
- id: 'user-a',
- email: '[email protected]',
- name: 'User A',
- picture: null,
- teamId: 'team-a',
- teamName: 'Team A',
- role: 'member',
- })
+ meResponse.resolve(testSessionMe())
await expect(contextRequest).rejects.toThrow(/stale_(auth_epoch|session_generation)/)
await expect(logout).resolves.toBeTypeOf('number')
@@ -639,24 +517,13 @@ describe('AppService deliberate team transition ownership', () => {
it('finishes GFS activation before a queued workflow read borrows another team', async () => {
const { service, restA } = await createNativeCommitTestHarness()
- const teamBResponse = deferred<{
- token: string
- team: { id: string; name: string; role: string }
- }>()
+ const teamBResponse = deferred<ReturnType<typeof testTeamSwitchResult>>()
const switchStarted = deferred<void>()
const tokenTeams = new Map<string, string>([['synthetic-session-a', 'team-a']])
let issuedToken = 0
- const user = {
- id: 'user-a',
- email: '[email protected]',
- name: 'User A',
- picture: null,
- teamId: 'team-a',
- teamName: 'Team A',
- role: 'member',
- }
+ const user = testSessionMe()
const authClient = {
- googleLogin: vi.fn().mockResolvedValue({ token: 'synthetic-session-a', me: user }),
+ googleLogin: vi.fn().mockResolvedValue(testLoginResult('synthetic-session-a', user)),
switchTeam: vi.fn(async (_token: string, teamId: string) => {
if (teamId === 'team-b') {
switchStarted.resolve()
@@ -666,7 +533,7 @@ describe('AppService deliberate team transition ownership', () => {
}
const token = `synthetic-${teamId}-${++issuedToken}`
tokenTeams.set(token, teamId)
- return { token, team: { id: teamId, name: teamId, role: 'member' } }
+ return testTeamSwitchResult(teamId, token)
}),
getMe: vi.fn(async (token: string) => {
const teamId = tokenTeams.get(token) || 'team-a'
@@ -696,10 +563,7 @@ describe('AppService deliberate team transition ownership', () => {
const switching = app.switchTeam('team-b')
await switchStarted.promise
const workflowRead = app.readWorkflow('workflows', 'approval')
- teamBResponse.resolve({
- token: 'synthetic-session-b',
- team: { id: 'team-b', name: 'Team B', role: 'member' },
- })
+ teamBResponse.resolve(testTeamSwitchResult('team-b', 'synthetic-session-b'))
const [switchResult, workflowResult] = await Promise.all([switching, workflowRead])
diff --git a/desktop-app/ui/src/hooks/domain/__tests__/__fixtures__/appControllerHarness.tsx b/desktop-app/ui/src/hooks/domain/__tests__/__fixtures__/appControllerHarness.tsx
index 8d1a793a4..d02535f41 100644
--- a/desktop-app/ui/src/hooks/domain/__tests__/__fixtures__/appControllerHarness.tsx
+++ b/desktop-app/ui/src/hooks/domain/__tests__/__fixtures__/appControllerHarness.tsx
@@ -182,7 +182,6 @@ export function extendMockClerumForAppController(
const bridge = clerum as unknown as Record<string, unknown>
let authenticated = options.startAuthenticated ?? true
- let sessionGeneration = 0
let sessionStateError = options.sessionStateError
let runtimeConfigState: DesktopRuntimeConfigState = options.runtimeConfigState ?? {
configured: true,
@@ -220,62 +219,44 @@ export function extendMockClerumForAppController(
authenticated = true
return createSessionState(true, sessionMe)
})
- const getSessionGeneration = vi.fn(async () =>
- handoffProducer ? handoffProducer.getSessionGeneration() : sessionGeneration
- )
+ const getSessionGeneration = vi.fn(async () => {
+ if (!handoffProducer) {
+ throw new Error('Desktop environment handoff tests require the native auth producer')
+ }
+ return handoffProducer.getSessionGeneration()
+ })
const getRuntimeConfigState = vi.fn(async () =>
handoffProducer ? handoffProducer.getRuntimeConfigState() : runtimeConfigState
)
const selectRuntimeConfigForHandoff = vi.fn(
async (optionId: string, expectedGeneration: number) => {
- if (handoffProducer) {
- try {
- return await handoffProducer.selectRuntimeConfigForHandoff(optionId, expectedGeneration)
- } catch (error) {
- throw wrapLikeElectronIpc(
- 'auth:selectRuntimeConfigForHandoff',
- error instanceof Error ? error : new Error(String(error))
- )
- }
+ if (!handoffProducer) {
+ throw new Error('Desktop environment handoff tests require the native auth producer')
}
- if (expectedGeneration !== sessionGeneration) {
+ try {
+ return await handoffProducer.selectRuntimeConfigForHandoff(optionId, expectedGeneration)
+ } catch (error) {
throw wrapLikeElectronIpc(
'auth:selectRuntimeConfigForHandoff',
- new Error('stale_session_generation')
+ error instanceof Error ? error : new Error(String(error))
)
}
- const selected = runtimeConfigState.options.find(option => option.id === optionId)
- if (!selected) throw new Error('runtime configuration not found')
- runtimeConfigState = {
- ...runtimeConfigState,
- activeOptionId: selected.id,
- currentConfig: {
- externalRestApiBaseUrl: selected.externalRestApiBaseUrl,
- rpcProxyBaseUrl: selected.rpcProxyBaseUrl,
- appName: selected.appName,
- },
- envKey: `harness-${selected.id}`,
- }
- sessionGeneration += 1
- return { runtimeConfigState, sessionGeneration }
}
)
const logout = vi.fn(async () => {
- if (handoffProducer) {
- try {
- const generation = await handoffProducer.logout()
- authenticated = false
- return { ok: true as const, sessionGeneration: generation }
- } catch (error) {
- throw wrapLikeElectronIpc(
- 'auth:logout',
- error instanceof Error ? error : new Error(String(error))
- )
- }
+ if (!handoffProducer) {
+ throw new Error('Desktop environment handoff tests require the native auth producer')
+ }
+ try {
+ const generation = await handoffProducer.logout()
+ authenticated = false
+ return { ok: true as const, sessionGeneration: generation }
+ } catch (error) {
+ throw wrapLikeElectronIpc(
+ 'auth:logout',
+ error instanceof Error ? error : new Error(String(error))
+ )
}
- authenticated = false
- sessionGeneration += 1
- return { ok: true as const, sessionGeneration }
})
const getDesktopReleaseStatus = vi.fn(
async () => options.desktopReleaseStatus ?? DEFAULT_DESKTOP_RELEASE_STATUS
diff --git a/desktop-app/ui/src/hooks/domain/__tests__/desktopEnvironmentHandoff.test.ts b/desktop-app/ui/src/hooks/domain/__tests__/desktopEnvironmentHandoff.test.ts
index c8059ecfe..8d3712b40 100644
--- a/desktop-app/ui/src/hooks/domain/__tests__/desktopEnvironmentHandoff.test.ts
+++ b/desktop-app/ui/src/hooks/domain/__tests__/desktopEnvironmentHandoff.test.ts
@@ -2,6 +2,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import fsp from 'node:fs/promises'
import os from 'node:os'
import path from 'node:path'
+import type { DesktopRuntimeConfigHandoffSelection } from '../../../../../src/types'
import { createDesktopEnvironmentSetupHandler } from '../desktopEnvironmentHandoff'
const targetEnvironment = {
@@ -81,14 +82,19 @@ function createHandler(
sessionGeneration += 1
return sessionGeneration
})
- const selectRuntimeConfig = vi.fn(async (optionId: string, _expectedGeneration?: number) => {
- await runtimeConfigModule!.selectDesktopRuntimeConfigOption(optionId)
- sessionGeneration += 1
- return {
- runtimeConfigState: await runtimeConfigModule!.getDesktopRuntimeConfigState(),
- sessionGeneration,
+ const selectRuntimeConfig = vi.fn(
+ async (
+ optionId: string,
+ _expectedGeneration?: number
+ ): Promise<DesktopRuntimeConfigHandoffSelection | null> => {
+ await runtimeConfigModule!.selectDesktopRuntimeConfigOption(optionId)
+ sessionGeneration += 1
+ return {
+ runtimeConfigState: await runtimeConfigModule!.getDesktopRuntimeConfigState(),
+ sessionGeneration,
+ }
}
- })
+ )
const setPendingDesktopEnvironmentSetup = vi.fn()
const setStatus = vi.fn()
const handler = createDesktopEnvironmentSetupHandler({
diff --git a/desktop-app/ui/src/hooks/domain/__tests__/useAuthController.desktopEnvironment.test.tsx b/desktop-app/ui/src/hooks/domain/__tests__/useAuthController.desktopEnvironment.test.tsx
index 2138aa6ed..86b2b7ad2 100644
--- a/desktop-app/ui/src/hooks/domain/__tests__/useAuthController.desktopEnvironment.test.tsx
+++ b/desktop-app/ui/src/hooks/domain/__tests__/useAuthController.desktopEnvironment.test.tsx
@@ -5,6 +5,7 @@ import { act, cleanup, render, screen, waitFor } from '@testing-library/react'
import fsp from 'node:fs/promises'
import os from 'node:os'
import path from 'node:path'
+import type { AppService } from '../../../../../src/appService'
import { useAuthController } from '../useAuthController'
import { wrapLikeElectronIpc } from './__fixtures__/ipcErrors'
@@ -58,8 +59,9 @@ let cancelDesktopEnvironmentSwitchForTest: (() => void) | null = null
let setBootingForTest: ((value: boolean) => void) | null = null
let setAuthenticatedForTest: ((value: boolean) => void) | null = null
let runtimeConfigModule: typeof import('../../../../../src/config') | null = null
+let nativeAppService: AppService | null = null
+let mismatchLogoutGeneration: number | null = null
let runtimeConfigDirectory = ''
-let nativeSessionGeneration = 0
const originalOnboardingPreview = process.env.EVENFIRE_ONBOARDING_PREVIEW
const frozenProfileIdMilliseconds = 1790000000000
@@ -126,8 +128,9 @@ beforeEach(async () => {
setBootingForTest = null
setAuthenticatedForTest = null
runtimeConfigModule = null
+ nativeAppService = null
+ mismatchLogoutGeneration = null
delete process.env.EVENFIRE_ONBOARDING_PREVIEW
- nativeSessionGeneration = 0
runtimeConfigDirectory = await fsp.mkdtemp(path.join(os.tmpdir(), 'evenfire-desktop-env-test-'))
vi.doUnmock('electron')
vi.resetModules()
@@ -146,6 +149,13 @@ beforeEach(async () => {
rpcProxyBaseUrl: `${targetRpcProxyBaseUrl}/rpc`,
})
await runtimeConfigModule.saveDesktopRuntimeConfig(otherEnvironment)
+ const { AppService } = await import('../../../../../src/appService')
+ nativeAppService = new AppService()
+ ;(
+ nativeAppService as unknown as {
+ tokenStore: { clearSessionToken: ReturnType<typeof vi.fn> }
+ }
+ ).tokenStore.clearSessionToken = vi.fn().mockResolvedValue(undefined)
mocks.getRuntimeConfigState.mockImplementation(async () =>
runtimeConfigModule!.getDesktopRuntimeConfigState()
@@ -154,25 +164,29 @@ beforeEach(async () => {
await runtimeConfigModule!.selectDesktopRuntimeConfigOption(optionId)
return runtimeConfigModule!.getDesktopRuntimeConfigState()
})
- mocks.getSessionGeneration.mockImplementation(async () => nativeSessionGeneration)
+ mocks.getSessionGeneration.mockImplementation(async () =>
+ nativeAppService!.getSessionGeneration()
+ )
mocks.selectRuntimeConfigForHandoff.mockImplementation(
async (optionId: string, expectedSessionGeneration: number) => {
- if (expectedSessionGeneration !== nativeSessionGeneration) {
- throw new Error('stale_session_generation')
- }
- await runtimeConfigModule!.selectDesktopRuntimeConfigOption(optionId)
- nativeSessionGeneration += 1
- return {
- runtimeConfigState: await runtimeConfigModule!.getDesktopRuntimeConfigState(),
- sessionGeneration: nativeSessionGeneration,
+ try {
+ return await nativeAppService!.selectRuntimeConfigForHandoff(
+ optionId,
+ expectedSessionGeneration
+ )
+ } catch (error) {
+ throw wrapLikeElectronIpc(
+ 'auth:selectRuntimeConfigForHandoff',
+ error instanceof Error ? error : new Error(String(error))
+ )
}
}
)
mocks.loadSession.mockImplementation(async () => setBootingForTest?.(false))
mocks.logoutForEnvironmentMismatch.mockImplementation(async () => {
setAuthenticatedForTest?.(false)
- nativeSessionGeneration += 1
- return nativeSessionGeneration
+ mismatchLogoutGeneration = await nativeAppService!.logout()
+ return mismatchLogoutGeneration
})
mocks.onDesktopSetupToken.mockImplementation(listener => {
desktopSetupTokenListener = listener
@@ -268,6 +282,7 @@ describe('Desktop environment handoff', () => {
render(<Probe />)
await waitFor(() => expect(screen.getByTestId('configuration-loaded')).toHaveTextContent('yes'))
const targetOptionId = await savedTargetOptionId()
+ const generationBeforeHandoff = nativeAppService!.getSessionGeneration()
mocks.loadSession.mockClear()
await dispatchDesktopEnvironmentLink({
@@ -275,7 +290,10 @@ describe('Desktop environment handoff', () => {
externalRestApiBaseUrl: `${targetEnvironment.externalRestApiBaseUrl}/api/v1`,
})
- expect(mocks.selectRuntimeConfigForHandoff).toHaveBeenCalledWith(targetOptionId, 0)
+ expect(mocks.selectRuntimeConfigForHandoff).toHaveBeenCalledWith(
+ targetOptionId,
+ generationBeforeHandoff
+ )
expect(mocks.clearQueryCache).toHaveBeenCalledOnce()
expect(mocks.loadSession).toHaveBeenCalledWith({ preserveNav: true })
expect(screen.getByTestId('pending-environment')).toHaveTextContent('none')
@@ -321,12 +339,16 @@ describe('Desktop environment handoff', () => {
render(<Probe />)
await waitFor(() => expect(screen.getByTestId('configuration-loaded')).toHaveTextContent('yes'))
+ const generationBeforeHandoff = nativeAppService!.getSessionGeneration()
await dispatchDesktopEnvironmentLink({
...targetEnvironment,
externalRestApiBaseUrl: `${targetEnvironment.externalRestApiBaseUrl}/api/v1`,
})
- expect(mocks.selectRuntimeConfigForHandoff).toHaveBeenCalledWith(await savedTargetOptionId(), 0)
+ expect(mocks.selectRuntimeConfigForHandoff).toHaveBeenCalledWith(
+ await savedTargetOptionId(),
+ generationBeforeHandoff
+ )
expect(screen.getByTestId('pending-environment')).toHaveTextContent('none')
expect(screen.getByTestId('pending-rpc')).toHaveTextContent('none')
expect(
@@ -386,6 +408,7 @@ describe('Desktop environment handoff', () => {
render(<Probe />)
await waitFor(() => expect(screen.getByTestId('configuration-loaded')).toHaveTextContent('yes'))
+ const generationBeforeHandoff = nativeAppService!.getSessionGeneration()
await dispatchDesktopEnvironmentLink(targetEnvironment)
await act(async () => {
@@ -400,7 +423,10 @@ describe('Desktop environment handoff', () => {
})
expect(serviceInternals.authClient.getDesktopEnvironment).not.toHaveBeenCalled()
expect(mocks.saveRuntimeConfig).not.toHaveBeenCalled()
- expect(mocks.selectRuntimeConfigForHandoff).toHaveBeenCalledWith(savedTarget.id, 0)
+ expect(mocks.selectRuntimeConfigForHandoff).toHaveBeenCalledWith(
+ savedTarget.id,
+ generationBeforeHandoff
+ )
expect(finalState.activeOptionId).toBe(savedTarget.id)
expect(screen.getByTestId('pending-environment')).toHaveTextContent('none')
})
@@ -726,7 +752,7 @@ describe('Desktop environment handoff', () => {
)
)
- nativeSessionGeneration += 1
+ await nativeAppService!.logout()
await act(async () => confirmDesktopEnvironmentSwitchForTest?.())
await act(async () => handoff)
@@ -795,7 +821,10 @@ describe('Desktop environment handoff', () => {
await act(async () => handoff)
expect(mocks.logoutForEnvironmentMismatch).toHaveBeenCalledOnce()
- expect(mocks.selectRuntimeConfigForHandoff).toHaveBeenCalledWith(await savedTargetOptionId(), 1)
+ expect(mocks.selectRuntimeConfigForHandoff).toHaveBeenCalledWith(
+ await savedTargetOptionId(),
+ mismatchLogoutGeneration
+ )
expect(screen.getByTestId('pending-environment')).toHaveTextContent('none')
})