Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop-app): r21-m1 route consumers through effective RPC
Josuéd9fd6f0358c6
diff --git a/desktop-app/src/__tests__/appService.runtimeConfigResolution.test.ts b/desktop-app/src/__tests__/appService.runtimeConfigResolution.test.tsindex bf30a7fb7..76c4420e5 100644--- a/desktop-app/src/__tests__/appService.runtimeConfigResolution.test.ts+++ b/desktop-app/src/__tests__/appService.runtimeConfigResolution.test.ts@@ -82,7 +82,12 @@ describe('AppService runtime config discovery ownership', () => {authorityScope: { environmentKey: string }sessionGeneration: number}+ openDesktop: (hostRef: string) => Promise<void>gfsScopeIdentity: { environmentKey: string } | null+ rpcTokenManager: {+ getOrIssue: ReturnType<typeof vi.fn>+ clear: ReturnType<typeof vi.fn>+ }}app.authClient = {getDesktopEnvironment,@@ -118,6 +123,20 @@ describe('AppService runtime config discovery ownership', () => {expect(service.getCachedUserId()).toBe('user-a')expect(app.gfsScopeIdentity?.environmentKey).toBe(restOnlyEnvKey)+ const openDesktopWindow = vi.fn().mockResolvedValue(undefined)+ vi.doMock('../desktopWindow.js', () => ({ openDesktopWindow }))+ app.rpcTokenManager = {+ getOrIssue: vi.fn().mockResolvedValue({ token: 'desktop-rpc-token' }),+ clear: vi.fn(),+ }+ await app.openDesktop('chatllm')+ expect(openDesktopWindow).toHaveBeenCalledWith(+ expect.objectContaining({+ hostRef: 'chatllm',+ rpcProxyUrl: 'https://rpc-discovered.example.test',+ })+ )+await service.logout()const rpcConfiguredEnvKey = runtimeConfig.getDesktopRuntimeConfigState().envKey@@ -141,7 +160,7 @@ describe('AppService runtime config discovery ownership', () => {)})- it('defers discovery completed during saved-session restore until logout', async () => {+ it('uses discovery completed during saved-session restore without changing durable identity', async () => {const { service, runtimeConfig, restA } = await createNativeCommitTestHarness()await runtimeConfig.saveDesktopRuntimeConfig({externalRestApiBaseUrl: restA,@@ -159,6 +178,7 @@ describe('AppService runtime config discovery ownership', () => {discoveryStarted.resolve()return discovery.promise})+ .mockRejectedValueOnce(new Error('later discovery must not be needed'))const getMeStarted = deferred<void>()const getMe = vi.fn(() => {getMeStarted.resolve()@@ -172,6 +192,9 @@ describe('AppService runtime config discovery ownership', () => {health: ReturnType<typeof vi.fn>}resolveRuntimeConfigIfNeeded: () => Promise<void>+ getEffectiveRpcProxyBaseUrl: () => string+ getDependenciesHealth: () => Promise<unknown>+ rpcClient: { health: ReturnType<typeof vi.fn> }gfsScopeIdentity: { environmentKey: string } | null}app.authClient = {@@ -179,6 +202,7 @@ describe('AppService runtime config discovery ownership', () => {getMe,health: vi.fn().mockResolvedValue({ status: 'ok' }),}+ app.rpcClient = { health: vi.fn().mockResolvedValue({ status: 'ok' }) }service.tokenStore.getSessionToken.mockResolvedValue('synthetic-saved-session-a')const { bindChatStoreForUser } = await import('../chatStoreBinding.js')@@ -209,6 +233,14 @@ describe('AppService runtime config discovery ownership', () => {)expect(app.gfsScopeIdentity?.environmentKey).toBe(restOnlyEnvKey)expect(service.getCachedUserId()).toBe('user-a')+ expect(app.getEffectiveRpcProxyBaseUrl()).toBe('https://rpc-discovered.example.test')++ await expect(app.getDependenciesHealth()).resolves.toMatchObject({+ externalRestApi: { ok: true },+ rpcProxy: { ok: true },+ })+ expect(app.rpcClient.health).toHaveBeenCalledOnce()+ expect(getDesktopEnvironment).toHaveBeenCalledTimes(2)await service.logout()expect(runtimeConfig.config.rpcProxyBaseUrl).toBe('https://rpc-discovered.example.test')diff --git a/desktop-app/src/__tests__/appService.sandboxUiLifecycle.test.ts b/desktop-app/src/__tests__/appService.sandboxUiLifecycle.test.tsindex add3935ca..c281e34bc 100644--- a/desktop-app/src/__tests__/appService.sandboxUiLifecycle.test.ts+++ b/desktop-app/src/__tests__/appService.sandboxUiLifecycle.test.ts@@ -99,6 +99,13 @@ const electronMocks = vi.hoisted(() => {}})+const authMocks = vi.hoisted(() => ({+ getDesktopEnvironment: vi.fn(),+ getMe: vi.fn(),+ googleLogin: vi.fn(),+ health: vi.fn(),+}))+vi.mock('electron', () => ({WebContentsView: electronMocks.FakeWebContentsView,BrowserWindow: { getAllWindows: () => [] },@@ -121,6 +128,9 @@ vi.mock('electron', () => ({vi.mock('../config.js', () => ({getActiveEnvKey: () => 'test-env',getActiveLegacyEnvKeys: () => [],+ hydrateDesktopRuntimeConfig: () => undefined,+ isDesktopRuntimeConfigured: () => true,+ saveDesktopRuntimeConfig: vi.fn(),getDesktopRuntimeConfigState: () => ({configured: true,isLocalhost: false,@@ -162,8 +172,10 @@ vi.mock('../rpcTokenManager.js', () => ({vi.mock('../authClient.js', () => ({AuthClient: class {- health = vi.fn().mockResolvedValue({ status: 'ok' })- getMe = vi.fn()+ health = authMocks.health+ getMe = authMocks.getMe+ googleLogin = authMocks.googleLogin+ getDesktopEnvironment = authMocks.getDesktopEnvironment},}))@@ -308,6 +320,12 @@ let userDataDir = ''beforeEach(async () => {vi.clearAllMocks()+ const { config } = await import('../config.js')+ config.rpcProxyBaseUrl = 'https://rpc.example'+ authMocks.health.mockResolvedValue({ status: 'ok' })+ authMocks.getMe.mockResolvedValue(null)+ authMocks.googleLogin.mockReset()+ authMocks.getDesktopEnvironment.mockReset()vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] })electronMocks.views.length = 0electronMocks.sessionObject.cookies.set.mockResolvedValue(undefined)@@ -342,6 +360,54 @@ async function setupWithLiveFirstApp(onClosed: () => void = vi.fn()) {return { service, parentWindow, firstWebContentsId: first!.webContentsId, firstView }}+describe('AppService sandbox-ui effective RPC endpoint', () => {+ it('uses a late discovery from the active session for mint, cookie, and navigation', async () => {+ const { config } = await import('../config.js')+ const discoveredRpcUrl = 'https://late-rpc.example.test'+ config.rpcProxyBaseUrl = ''+ authMocks.getDesktopEnvironment+ .mockRejectedValueOnce(new Error('initial discovery unavailable'))+ .mockResolvedValueOnce({+ externalRestApiBaseUrl: 'http://rest',+ rpcProxyBaseUrl: discoveredRpcUrl,+ appName: 'Discovered environment',+ })+ authMocks.googleLogin.mockResolvedValue({+ token: 'fake-session-token',+ me: {+ id: 'user-a',+ email: '[email protected]',+ name: 'User A',+ picture: null,+ teamId: 'team-a',+ teamName: 'Team A',+ role: 'member',+ },+ })+ const service = new AppService()+ await service.googleLogin('google-id-token')+ await service.getDependenciesHealth()+ expect(config.rpcProxyBaseUrl).toBe('')++ const parentWindow = new FakeParentWindow()++ await service.openSandboxUi(openArgs('effective-app', parentWindow))++ expect(fetchMock).toHaveBeenCalledWith(+ `${discoveredRpcUrl}/api/v1/sandbox-ui/sandbox-recipes/effective-app/session`,+ expect.objectContaining({ method: 'POST' })+ )+ expect(electronMocks.sessionObject.cookies.set).toHaveBeenCalledWith(+ expect.objectContaining({+ url: `${discoveredRpcUrl}/api/v1/sandbox-ui/sandbox-recipes/effective-app/`,+ })+ )+ expect(electronMocks.views.at(-1)?.webContents.currentUrl).toBe(+ `${discoveredRpcUrl}/api/v1/sandbox-ui/sandbox-recipes/effective-app/view/`+ )+ })+})+describe('AppService sandbox-ui open replaces the live view whatever its outcome', () => {it('a reopen whose mint rejects leaves no view, no refresh loop and no pin behind', async () => {const { service, parentWindow, firstWebContentsId, firstView } = await setupWithLiveFirstApp()diff --git a/desktop-app/src/__tests__/rpcProxyClient.test.ts b/desktop-app/src/__tests__/rpcProxyClient.test.tsindex a64c3a389..ac314501b 100644--- a/desktop-app/src/__tests__/rpcProxyClient.test.ts+++ b/desktop-app/src/__tests__/rpcProxyClient.test.ts@@ -31,6 +31,32 @@ describe('RpcProxyClient endpoint provider', () => {expect.any(Object))})++ it('uses its supplied endpoint for a Desktop session exchange', async () => {+ const client = new RpcProxyClient(() => 'https://effective-rpc.example.test/')+ const fetchMock = vi.fn().mockResolvedValue({+ ok: true,+ json: async () => ({ ok: true, hostRef: 'chatllm' }),+ headers: {+ get: (name: string) =>+ name === 'set-cookie'+ ? 'clerum_desktop_session=effective-cookie; Path=/api/v1/desktop/chatllm'+ : null,+ },+ })+ vi.stubGlobal('fetch', fetchMock)++ await expect(client.postDesktopSession('rpc-token', 'chatllm')).resolves.toEqual({+ ok: true,+ hostRef: 'chatllm',+ setCookie: ['clerum_desktop_session=effective-cookie; Path=/api/v1/desktop/chatllm'],+ })++ expect(fetchMock).toHaveBeenCalledWith(+ 'https://effective-rpc.example.test/api/v1/desktop/chatllm/session',+ expect.objectContaining({ method: 'POST' })+ )+ })})describe('RpcProxyClient.listSessions', () => {diff --git a/desktop-app/src/appService.ts b/desktop-app/src/appService.tsindex 3bc44d093..d51055097 100644--- a/desktop-app/src/appService.ts+++ b/desktop-app/src/appService.ts@@ -1716,7 +1716,7 @@ export class AppService {// single-flight slot can be cleared unconditionally after it settles.this.restoreSavedSessionInFlight = nullthis.restoreSavedSessionReservationStarted = false- if (!this.sessionToken && !this.me && this.interactiveLoginAttempts === 0) {+ if (this.interactiveLoginAttempts === 0) {await this.withNativeAuthEnvironmentCommit(async () => {await this.commitPendingRuntimeConfigDiscoveryIfSafe().catch(() => undefined)})@@ -5582,7 +5582,7 @@ export class AppService {await openDesktopWindow({hostRef: targetHostRef,jwt: rpc.token,- rpcProxyUrl: config.rpcProxyBaseUrl,+ rpcProxyUrl: this.getEffectiveRpcProxyBaseUrl(),onClose: onWindowClosed,})}@@ -5965,7 +5965,7 @@ export class AppService {recipeNs,recipeName,setCookie,- rpcProxyUrl: config.rpcProxyBaseUrl,+ rpcProxyUrl: this.getEffectiveRpcProxyBaseUrl(),defaultPath: args.defaultPath,routePath: args.routePath,parentWindow: args.parentWindow,diff --git a/desktop-app/src/desktopWindow.test.ts b/desktop-app/src/desktopWindow.test.tsindex c4e55dc79..17fa094b9 100644--- a/desktop-app/src/desktopWindow.test.ts+++ b/desktop-app/src/desktopWindow.test.ts@@ -41,9 +41,12 @@ vi.mock('electron', () => ({}))const mockPostDesktopSession = vi.fn()+const mockRpcProxyEndpointProvider = vi.fn()vi.mock('./rpcProxyClient.js', () => ({RpcProxyClient: class {- constructor() {}+ constructor(getRpcProxyBaseUrl: () => string) {+ mockRpcProxyEndpointProvider(getRpcProxyBaseUrl)+ }postDesktopSession = mockPostDesktopSession},}))@@ -83,6 +86,9 @@ describe('desktopWindow', () => {rpcProxyUrl: 'http://localhost:8094',})+ expect(mockRpcProxyEndpointProvider).toHaveBeenCalledOnce()+ const endpointProvider = mockRpcProxyEndpointProvider.mock.calls[0]?.[0]+ expect(endpointProvider?.()).toBe('http://localhost:8094')expect(mockPostDesktopSession).toHaveBeenCalledWith('test-jwt', 'chatllm')expect(mockFromPartition).toHaveBeenCalledWith('persist:desktop-chatllm')expect(mockSetCookie).toHaveBeenCalledWith(diff --git a/desktop-app/src/desktopWindow.ts b/desktop-app/src/desktopWindow.tsindex 50c59a0e0..76df0d541 100644--- a/desktop-app/src/desktopWindow.ts+++ b/desktop-app/src/desktopWindow.ts@@ -11,8 +11,6 @@ export type OpenDesktopWindowArgs = {type WindowEntry = { window: BrowserWindow; hostRef: string }const windows = new Map<string, WindowEntry>()-const client = new RpcProxyClient()-/*** Parses one or more Set-Cookie header values and extracts the session cookie value.* Accepts either a single string or an array (as returned by getSetCookie()).@@ -44,6 +42,7 @@ export async function openDesktopWindow(args: OpenDesktopWindowArgs): Promise<vo}// 1. Session exchange (Node-side fetch; no cookie-jar problem)+ const client = new RpcProxyClient(() => rpcProxyUrl)const { setCookie } = await client.postDesktopSession(jwt, hostRef)const cookieValue = extractSessionCookie(setCookie, SESSION_COOKIE_NAME)if (!cookieValue) {