Skip to content

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

TypeScript

test: protect R6-M4 discovery commit and GFS migration boundaries

Josuéeb9fcdda2454
diff --git a/desktop-app/src/__tests__/appService.discoveryLifecycle.test.ts b/desktop-app/src/__tests__/appService.discoveryLifecycle.test.ts
index 5d34ed8e8..bae0a5567 100644
--- a/desktop-app/src/__tests__/appService.discoveryLifecycle.test.ts
+++ b/desktop-app/src/__tests__/appService.discoveryLifecycle.test.ts
@@ -146,6 +146,81 @@ describe('RPC discovery lifecycle through native producers', () => {
expect(config.config.externalRestApiBaseUrl).toBe(restB)
})
+ it('commits restore-held discovery before a newer interactive login captures identity', async () => {
+ const { service, config, store, discovery, AuthClient, rpc } = await fixture()
+ const key = config.getActiveEnvKey()
+ await store.setSessionToken('synthetic-saved-session', key)
+ const me = pending<ReturnType<typeof testSessionMe>>()
+ const started = pending<void>()
+ vi.spyOn(AuthClient.prototype, 'getMe').mockImplementation(() => {
+ started.resolve()
+ return me.promise
+ })
+ const restore = service.getSessionState()
+ await started.promise
+ await service.getDependenciesHealth()
+ expect(config.config.rpcProxyBaseUrl).toBe('')
+ discovery.mockRejectedValue(new Error('subsequent discovery unavailable'))
+ await service.googleLogin('synthetic-interactive-token')
+ const nextKey = config.getActiveEnvKey()
+ expect(nextKey).not.toBe(key)
+ expect(config.config.rpcProxyBaseUrl).toBe(rpc)
+ expect(await store.getSessionToken(nextKey)).toBe('synthetic-session-a')
+ me.resolve(testSessionMe({ id: 'restore-user' }))
+ await expect(restore).resolves.toMatchObject({ authenticated: true, me: { id: 'user-a' } })
+ expect(service.getCachedUserId()).toBe('user-a')
+ })
+
+ it.each(['Google', 'password'])(
+ 'persists pending discovery only in failed %s login cleanup',
+ async kind => {
+ const { service, config, store, discovery, AuthClient, configPath, rpc } = await fixture()
+ await store.setSessionToken('synthetic-saved-session', config.getActiveEnvKey())
+ const me = pending<ReturnType<typeof testSessionMe>>()
+ const started = pending<void>()
+ vi.spyOn(AuthClient.prototype, 'getMe').mockImplementation(() => {
+ started.resolve()
+ return me.promise
+ })
+ const restore = service.getSessionState()
+ await started.promise
+ await service.getDependenciesHealth()
+ const write = fs.writeFile.bind(fs)
+ let rejected = false
+ vi.spyOn(fs, 'writeFile').mockImplementation(async (file, ...args) => {
+ if (String(file) === configPath && !rejected) {
+ rejected = true
+ throw new Error('fixture prelogin persistence denied')
+ }
+ return write(file, ...args)
+ })
+ discovery.mockRejectedValue(new Error('subsequent discovery unavailable'))
+ const loginResponse = pending<ReturnType<typeof testLoginResult>>()
+ const loginStarted = pending<void>()
+ const dispatchLogin = () => {
+ loginStarted.resolve()
+ return loginResponse.promise
+ }
+ vi.spyOn(AuthClient.prototype, 'googleLogin').mockImplementation(dispatchLogin)
+ vi.spyOn(AuthClient.prototype, 'passwordLogin').mockImplementation(dispatchLogin)
+ const login =
+ kind === 'Google'
+ ? service.googleLogin('synthetic-google')
+ : service.passwordLogin('[email protected]', 'fixture-password')
+ const result = login.catch(error => error as Error)
+ await loginStarted.promise
+ me.resolve(testSessionMe())
+ await restore
+ expect(config.config.rpcProxyBaseUrl).toBe('')
+ loginResponse.reject(new Error('fixture login rejected'))
+ expect(await result).toMatchObject({ message: 'fixture login rejected' })
+ expect(rejected).toBe(true)
+ expect(config.config.rpcProxyBaseUrl).toBe(rpc)
+ expect(JSON.parse(await fs.readFile(configPath, 'utf8')).rpcProxyBaseUrl).toBe(rpc)
+ expect(service.getCachedUserId()).toBeNull()
+ }
+ )
+
it('retries discovery persistence after logout ends auth but its config write fails', async () => {
const { service, config, configPath, store, rest, rpc, discovery, chat } = await fixture()
await service.googleLogin('synthetic-google-token')
diff --git a/desktop-app/src/__tests__/appService.runtimeConfigBoundary.integration.test.ts b/desktop-app/src/__tests__/appService.runtimeConfigBoundary.integration.test.ts
index 9e9366c85..57db2aceb 100644
--- a/desktop-app/src/__tests__/appService.runtimeConfigBoundary.integration.test.ts
+++ b/desktop-app/src/__tests__/appService.runtimeConfigBoundary.integration.test.ts
@@ -237,7 +237,8 @@ describe('AppService RPC discovery restore boundary', () => {
teamId: string | null
environmentKey: string
baseUrl: string
- }
+ },
+ status: 'active' | 'paused' = 'active'
) => {
await seedService.persistDesktopGfsUpload({
version: 2,
@@ -262,7 +263,7 @@ describe('AppService RPC discovery restore boundary', () => {
expiresAt,
},
scope: { ...scope, drive: 'main', authEpoch: seedService.gfsAuthEpoch },
- status: 'active',
+ status,
updatedAt: new Date().toISOString(),
})
}
@@ -274,6 +275,12 @@ describe('AppService RPC discovery restore boundary', () => {
baseUrl: 'https://api-other.example.test',
})
await seedService.logout()
+ await persistRecord('paused-upload', seedScope, 'paused')
+ const unrelatedEnvKey = runtimeConfig.resolveEnvKey('https://unrelated.example.test')
+ await persistRecord('other-environment-upload', {
+ ...seedScope,
+ environmentKey: unrelatedEnvKey,
+ })
await runtimeConfig.saveDesktopRuntimeConfig({
externalRestApiBaseUrl: restBaseUrl,
@@ -305,6 +312,18 @@ describe('AppService RPC discovery restore boundary', () => {
}>
}
const byId = new Map(state.records.map(record => [record.uploadId, record]))
+ expect(byId.get('paused-upload')).toEqual(
+ expect.objectContaining({
+ status: 'paused',
+ scope: expect.objectContaining({ environmentKey: rpcEnvKey }),
+ })
+ )
+ expect(byId.get('other-environment-upload')).toEqual(
+ expect.objectContaining({
+ status: 'active',
+ scope: expect.objectContaining({ environmentKey: unrelatedEnvKey }),
+ })
+ )
expect(byId.get('matching-upload')).toEqual(
expect.objectContaining({
status: 'suspended_auth',