Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test(desktop-app): cover discovery boundary migrations
Josué4098197ba2eb
diff --git a/desktop-app/src/__tests__/appService.runtimeConfigBoundary.integration.test.ts b/desktop-app/src/__tests__/appService.runtimeConfigBoundary.integration.test.tsindex 21beea71f..9e9366c85 100644--- a/desktop-app/src/__tests__/appService.runtimeConfigBoundary.integration.test.ts+++ b/desktop-app/src/__tests__/appService.runtimeConfigBoundary.integration.test.ts@@ -67,57 +67,62 @@ describe('AppService RPC discovery restore boundary', () => {const restOnlyEnvKey = runtimeConfig.getActiveEnvKey()const me = testSessionMe()const tokenStore = new TokenStore({ isolatedUserDataPath: userDataDir })- await tokenStore.setSessionToken('synthetic-saved-session-a', restOnlyEnvKey)- await chatStoreBinding.bindChatStoreForUser(me.id, restOnlyEnvKey, {- teamId: me.teamId,- })+ const seedService = new AppService() as unknown as {+ authClient: {+ getDesktopEnvironment: ReturnType<typeof vi.fn>+ googleLogin: ReturnType<typeof vi.fn>+ }+ tokenStore: TokenStore+ googleLogin: (idToken: string) => Promise<unknown>+ gfsScopeIdentity: {+ ownerId: string+ teamId: string | null+ environmentKey: string+ baseUrl: string+ } | null+ gfsAuthEpoch: number+ persistDesktopGfsUpload: (record: unknown) => Promise<void>+ }+ seedService.tokenStore = tokenStore+ seedService.authClient = {+ getDesktopEnvironment: vi.fn().mockRejectedValue(new Error('seed discovery unavailable')),+ googleLogin: vi.fn().mockResolvedValue({ token: 'synthetic-saved-session-a', me }),+ }+ await seedService.googleLogin('synthetic-seed-google-token')await chatStoreBinding.requireChatStore().createChat('agent-a', 'chat-a')-- const gfsStatePath = path.join(userDataDir, 'gfs-upload-sessions.json')+ if (!seedService.gfsScopeIdentity)+ throw new Error('The seed login did not activate a GFS scope')const now = new Date().toISOString()- await fs.writeFile(- gfsStatePath,- JSON.stringify({- version: 2,- records: [- {- version: 2,- uploadId: 'upload-a',- filePath: '/payload.bin',- fileName: 'payload.bin',- fileSize: 4,- target: { operation: 'create', parentRid: 'parent-a' },- name: 'payload.bin',- session: {- uploadId: 'upload-a',- drive: 'main',- operation: 'create',- expectedBytes: 4,- partBytes: 4,- partCount: 1,- state: 'uploading',- contiguousBytes: 0,- committedBytes: 0,- committedPartCount: 0,- activePartCount: 0,- expiresAt: now,- },- scope: {- ownerId: me.id,- teamId: me.teamId,- environmentKey: restOnlyEnvKey,- baseUrl: restBaseUrl,- drive: 'main',- authEpoch: 1,- },- status: 'active',- updatedAt: now,- },- ],- quarantined: [],- }),- { mode: 0o600 }- )+ await seedService.persistDesktopGfsUpload({+ version: 2,+ uploadId: 'upload-a',+ filePath: '/payload.bin',+ fileName: 'payload.bin',+ fileSize: 4,+ target: { operation: 'create', parentRid: 'parent-a' },+ name: 'payload.bin',+ session: {+ uploadId: 'upload-a',+ drive: 'main',+ operation: 'create',+ expectedBytes: 4,+ partBytes: 4,+ partCount: 1,+ state: 'uploading',+ contiguousBytes: 0,+ committedBytes: 0,+ committedPartCount: 0,+ activePartCount: 0,+ expiresAt: now,+ },+ scope: {+ ...seedService.gfsScopeIdentity,+ drive: 'main',+ authEpoch: seedService.gfsAuthEpoch,+ },+ status: 'active',+ updatedAt: now,+ })const service = new AppService() as unknown as {authClient: {@@ -160,4 +165,158 @@ describe('AppService RPC discovery restore boundary', () => {expect.objectContaining({ uploadId: 'upload-a', status: 'suspended_auth' }),])})++ it('migrates only matching producer-written GFS records during login', async () => {+ tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'evenfire-runtime-login-boundary-'))+ const userDataDir = path.join(tempDir, 'user-data')+ const configPath = path.join(tempDir, 'runtime-config.json')+ await fs.mkdir(userDataDir, { recursive: true })+ process.env.CLERUM_DESKTOP_CONFIG_PATH = configPath+ delete process.env.APPDATA++ vi.resetModules()+ vi.doMock('electron', () => ({+ app: {+ getPath: vi.fn((name: string) =>+ name === 'appData' ? path.dirname(userDataDir) : userDataDir+ ),+ isPackaged: false,+ isReady: vi.fn(() => true),+ setName: vi.fn(),+ setPath: vi.fn(),+ },+ safeStorage: { isEncryptionAvailable: vi.fn(() => false) },+ }))++ const [{ AppService }, runtimeConfig, { TokenStore }] = await Promise.all([+ import('../appService.js'),+ import('../config.js'),+ import('../tokenStore.js'),+ ])+ const restBaseUrl = 'https://api-a.example.test'+ const rpcBaseUrl = 'https://rpc-discovered.example.test'+ await runtimeConfig.saveDesktopRuntimeConfig({+ externalRestApiBaseUrl: restBaseUrl,+ rpcProxyBaseUrl: '',+ appName: 'Environment A',+ })+ const restOnlyEnvKey = runtimeConfig.getActiveEnvKey()+ const me = testSessionMe()+ const tokenStore = new TokenStore({ isolatedUserDataPath: userDataDir })+ const seedService = new AppService() as unknown as {+ authClient: {+ getDesktopEnvironment: ReturnType<typeof vi.fn>+ googleLogin: ReturnType<typeof vi.fn>+ }+ tokenStore: TokenStore+ googleLogin: (idToken: string) => Promise<unknown>+ logout: () => Promise<number>+ gfsScopeIdentity: {+ ownerId: string+ teamId: string | null+ environmentKey: string+ baseUrl: string+ } | null+ gfsAuthEpoch: number+ persistDesktopGfsUpload: (record: unknown) => Promise<void>+ }+ seedService.tokenStore = tokenStore+ seedService.authClient = {+ getDesktopEnvironment: vi.fn().mockRejectedValue(new Error('seed discovery unavailable')),+ googleLogin: vi.fn().mockResolvedValue({ token: 'synthetic-seed-session', me }),+ }+ await seedService.googleLogin('synthetic-seed-google-token')+ if (!seedService.gfsScopeIdentity)+ throw new Error('The seed login did not activate a GFS scope')+ const seedScope = seedService.gfsScopeIdentity+ const expiresAt = new Date(Date.now() + 60_000).toISOString()+ const persistRecord = async (+ uploadId: string,+ scope: {+ ownerId: string+ teamId: string | null+ environmentKey: string+ baseUrl: string+ }+ ) => {+ await seedService.persistDesktopGfsUpload({+ version: 2,+ uploadId,+ filePath: `/${uploadId}.bin`,+ fileName: `${uploadId}.bin`,+ fileSize: 4,+ target: { operation: 'create', parentRid: 'parent-a' },+ name: `${uploadId}.bin`,+ session: {+ uploadId,+ drive: 'main',+ operation: 'create',+ expectedBytes: 4,+ partBytes: 4,+ partCount: 1,+ state: 'uploading',+ contiguousBytes: 0,+ committedBytes: 0,+ committedPartCount: 0,+ activePartCount: 0,+ expiresAt,+ },+ scope: { ...scope, drive: 'main', authEpoch: seedService.gfsAuthEpoch },+ status: 'active',+ updatedAt: new Date().toISOString(),+ })+ }+ await persistRecord('matching-upload', seedScope)+ await persistRecord('other-user-upload', { ...seedScope, ownerId: 'other-user' })+ await persistRecord('other-team-upload', { ...seedScope, teamId: 'other-team' })+ await persistRecord('other-rest-upload', {+ ...seedScope,+ baseUrl: 'https://api-other.example.test',+ })+ await seedService.logout()++ await runtimeConfig.saveDesktopRuntimeConfig({+ externalRestApiBaseUrl: restBaseUrl,+ rpcProxyBaseUrl: rpcBaseUrl,+ appName: 'Environment A',+ })+ const rpcEnvKey = runtimeConfig.getActiveEnvKey()+ const loginService = new AppService() as unknown as {+ authClient: { googleLogin: ReturnType<typeof vi.fn> }+ tokenStore: TokenStore+ googleLogin: (idToken: string) => Promise<unknown>+ }+ loginService.tokenStore = tokenStore+ loginService.authClient = {+ googleLogin: vi.fn().mockResolvedValue({ token: 'synthetic-login-session', me }),+ }++ await loginService.googleLogin('synthetic-login-google-token')++ expect(await tokenStore.getSessionToken(rpcEnvKey)).toBe('synthetic-login-session')+ expect(await tokenStore.getSessionToken(restOnlyEnvKey)).toBeNull()+ const state = JSON.parse(+ await fs.readFile(path.join(userDataDir, 'gfs-upload-sessions.json'), 'utf8')+ ) as {+ records: Array<{+ uploadId: string+ status: string+ scope: { environmentKey: string; ownerId: string; teamId: string | null; baseUrl: string }+ }>+ }+ const byId = new Map(state.records.map(record => [record.uploadId, record]))+ expect(byId.get('matching-upload')).toEqual(+ expect.objectContaining({+ status: 'suspended_auth',+ scope: expect.objectContaining({ environmentKey: rpcEnvKey }),+ })+ )+ for (const uploadId of ['other-user-upload', 'other-team-upload', 'other-rest-upload']) {+ expect(byId.get(uploadId)).toEqual(+ expect.objectContaining({+ scope: expect.objectContaining({ environmentKey: restOnlyEnvKey }),+ })+ )+ }+ })})diff --git a/desktop-app/src/__tests__/appService.runtimeConfigResolution.test.ts b/desktop-app/src/__tests__/appService.runtimeConfigResolution.test.tsindex 91b600459..bf30a7fb7 100644--- a/desktop-app/src/__tests__/appService.runtimeConfigResolution.test.ts+++ b/desktop-app/src/__tests__/appService.runtimeConfigResolution.test.ts@@ -308,6 +308,48 @@ describe('AppService runtime config discovery ownership', () => {expect(app.pendingRuntimeConfigDiscovery).toBeNull()})+ it.each([+ [+ 'Google',+ (service: { googleLogin: (idToken: string) => Promise<unknown> }) =>+ service.googleLogin('token'),+ ],+ [+ 'password',+ (service: { passwordLogin: (email: string, password: string) => Promise<unknown> }) =>+ service.passwordLogin('[email protected]', 'password'),+ ],+ ])('commits matching discovery after a failed %s login', async (_kind, login) => {+ const { service, runtimeConfig, restA } = await createNativeCommitTestHarness()+ await runtimeConfig.saveDesktopRuntimeConfig({+ externalRestApiBaseUrl: restA,+ rpcProxyBaseUrl: '',+ appName: 'Environment A',+ })+ const app = service as unknown as {+ authClient: {+ getDesktopEnvironment: ReturnType<typeof vi.fn>+ googleLogin: ReturnType<typeof vi.fn>+ passwordLogin: ReturnType<typeof vi.fn>+ }+ passwordLogin: (email: string, password: string) => Promise<unknown>+ }+ app.authClient = {+ getDesktopEnvironment: vi.fn().mockResolvedValue({+ externalRestApiBaseUrl: restA,+ rpcProxyBaseUrl: 'https://rpc-discovered.example.test',+ appName: 'Environment A',+ }),+ googleLogin: vi.fn().mockRejectedValue(new Error('Google login rejected')),+ passwordLogin: vi.fn().mockRejectedValue(new Error('password login rejected')),+ }++ await expect(login(app)).rejects.toThrow('login rejected')++ expect(runtimeConfig.config.rpcProxyBaseUrl).toBe('https://rpc-discovered.example.test')+ expect(service.tokenStore.setSessionToken).not.toHaveBeenCalled()+ })+it('shares a pending discovery for the same profile and REST endpoint', async () => {const { service, runtimeConfig, restA } = await createNativeCommitTestHarness()await runtimeConfig.saveDesktopRuntimeConfig({