Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix: prioritize exact REST endpoint during handoff
Josué47cf29e08e74
diff --git a/desktop-app/ui/src/hooks/domain/__tests__/desktopEnvironmentHandoff.test.ts b/desktop-app/ui/src/hooks/domain/__tests__/desktopEnvironmentHandoff.test.tsindex 674808ba2..00a4a7acc 100644--- a/desktop-app/ui/src/hooks/domain/__tests__/desktopEnvironmentHandoff.test.ts+++ b/desktop-app/ui/src/hooks/domain/__tests__/desktopEnvironmentHandoff.test.ts@@ -226,6 +226,93 @@ describe('Desktop environment handoff concurrency', () => {}})+ it('selects an exact saved REST endpoint when a same-origin sibling is also saved', async () => {+ await runtimeConfigModule!.saveDesktopRuntimeConfig({+ appName: 'Sibling API profile',+ externalRestApiBaseUrl: `${targetEnvironment.externalRestApiBaseUrl}/api/v2`,+ rpcProxyBaseUrl: 'https://sibling-rpc.example.test',+ })+ const state = await runtimeConfigModule!.getDesktopRuntimeConfigState()+ const exactTarget = state.options.find(+ option =>+ option.externalRestApiBaseUrl === `${targetEnvironment.externalRestApiBaseUrl}/api/v1`+ )+ if (!exactTarget) throw new Error('The config producer did not return the exact REST profile')+ const { handler, selectRuntimeConfig, setPendingDesktopEnvironmentSetup, setStatus } =+ createHandler(() => ({+ booting: false,+ busy: false,+ authTransitioning: false,+ isAuthenticated: false,+ }))++ await handler({+ ...targetEnvironment,+ externalRestApiBaseUrl: `${targetEnvironment.externalRestApiBaseUrl}/api/v1`,+ })++ const finalState = await runtimeConfigModule!.getDesktopRuntimeConfigState()+ expect(selectRuntimeConfig).toHaveBeenCalledWith(exactTarget.id, 0)+ expect(finalState.activeOptionId).toBe(exactTarget.id)+ expect(setPendingDesktopEnvironmentSetup).toHaveBeenLastCalledWith(null)+ expect(setStatus).not.toHaveBeenCalledWith(+ 'Desktop setup link rejected because this REST host is already saved with a different API endpoint.',+ 'error'+ )+ })++ it('selects an exact REST profile added during logout despite a same-origin sibling', async () => {+ let authenticated = true+ let sessionGeneration = 0+ let targetId = ''+ const logout = vi.fn(async () => {+ await runtimeConfigModule!.saveDesktopRuntimeConfig({+ appName: 'New exact target',+ externalRestApiBaseUrl: 'https://new-api.example.test/api/v1',+ rpcProxyBaseUrl: 'https://rpc.new-api.example.test/v1',+ })+ await runtimeConfigModule!.saveDesktopRuntimeConfig({+ appName: 'New sibling target',+ externalRestApiBaseUrl: 'https://new-api.example.test/api/v2',+ rpcProxyBaseUrl: 'https://rpc.new-api.example.test/v2',+ })+ const state = await runtimeConfigModule!.getDesktopRuntimeConfigState()+ targetId =+ state.options.find(+ option => option.externalRestApiBaseUrl === 'https://new-api.example.test/api/v1'+ )?.id ?? ''+ authenticated = false+ sessionGeneration += 1+ return sessionGeneration+ })+ const { handler, selectRuntimeConfig, setPendingDesktopEnvironmentSetup, setStatus } =+ createHandler(+ () => ({+ booting: false,+ busy: false,+ authTransitioning: false,+ isAuthenticated: authenticated,+ }),+ undefined,+ logout,+ undefined,+ async () => sessionGeneration+ )++ await handler({+ appName: 'New target',+ externalRestApiBaseUrl: 'https://new-api.example.test/api/v1',+ })++ expect(logout).toHaveBeenCalledOnce()+ expect(selectRuntimeConfig).toHaveBeenCalledWith(targetId, 1)+ expect(setPendingDesktopEnvironmentSetup).toHaveBeenLastCalledWith(null)+ expect(setStatus).not.toHaveBeenCalledWith(+ 'Desktop setup link rejected because this REST host is already saved with a different API endpoint.',+ 'error'+ )+ })+it('asks before logging out to switch from an authenticated environment', async () => {const requestEnvironmentSwitchConfirmation = vi.fn(async () => false)const {@@ -487,6 +574,42 @@ describe('Desktop environment handoff concurrency', () => {})describe('Desktop environment REST endpoint matching', () => {+ it('keeps an exact active REST endpoint when a same-origin sibling is saved', async () => {+ await runtimeConfigModule!.saveDesktopRuntimeConfig({+ appName: 'Sibling API profile',+ externalRestApiBaseUrl: `${targetEnvironment.externalRestApiBaseUrl}/api/v2`,+ rpcProxyBaseUrl: 'https://sibling-rpc.example.test',+ })+ const state = await runtimeConfigModule!.getDesktopRuntimeConfigState()+ const exactTarget = state.options.find(+ option =>+ option.externalRestApiBaseUrl === `${targetEnvironment.externalRestApiBaseUrl}/api/v1`+ )+ if (!exactTarget) throw new Error('The config producer did not return the exact REST profile')+ await runtimeConfigModule!.selectDesktopRuntimeConfigOption(exactTarget.id)++ const { handler, logout, selectRuntimeConfig, setPendingDesktopEnvironmentSetup, setStatus } =+ createHandler(() => ({+ booting: false,+ busy: false,+ authTransitioning: false,+ isAuthenticated: false,+ }))++ await handler({+ ...targetEnvironment,+ externalRestApiBaseUrl: `${targetEnvironment.externalRestApiBaseUrl}/api/v1`,+ })++ expect(logout).not.toHaveBeenCalled()+ expect(selectRuntimeConfig).not.toHaveBeenCalled()+ expect(setPendingDesktopEnvironmentSetup).toHaveBeenLastCalledWith(null)+ expect(setStatus).toHaveBeenLastCalledWith(+ `Opening ${targetEnvironment.appName} in Evenfire Desktop.`,+ 'success'+ )+ })+it.each([['a REST host suffix',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.tsxindex f6efb8648..2138aa6ed 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@@ -431,11 +431,57 @@ describe('Desktop environment handoff', () => {})expect(mocks.saveRuntimeConfig).not.toHaveBeenCalled()- expect(mocks.selectRuntimeConfig).toHaveBeenCalledWith(savedOption.id)+ expect(mocks.selectRuntimeConfig).not.toHaveBeenCalled()expect(screen.getByTestId('pending-environment')).toHaveTextContent('none')expect((await runtimeConfigModule!.getDesktopRuntimeConfigState()).activeOptionId).toBe(savedOption.id)+ expect(mocks.setStatus).toHaveBeenLastCalledWith(+ `Opening ${linkedEnvironment.appName} in Evenfire Desktop.`,+ 'success'+ )+ })++ it('keeps the exact active REST profile when a same-origin sibling appears before confirmation', async () => {+ const linkedEnvironment = {+ appName: 'Linked target',+ externalRestApiBaseUrl: 'https://new-api.example.test/api/v1',+ }+ render(<Probe />)+ await waitFor(() => expect(screen.getByTestId('configuration-loaded')).toHaveTextContent('yes'))+ await dispatchDesktopEnvironmentLink(linkedEnvironment)+ expect(screen.getByTestId('pending-environment')).toHaveTextContent(+ linkedEnvironment.externalRestApiBaseUrl+ )++ await runtimeConfigModule!.saveDesktopRuntimeConfig({+ appName: 'Active target',+ externalRestApiBaseUrl: linkedEnvironment.externalRestApiBaseUrl,+ rpcProxyBaseUrl: 'https://rpc.new-api.example.test/v1',+ })+ await runtimeConfigModule!.saveDesktopRuntimeConfig({+ appName: 'Sibling target',+ externalRestApiBaseUrl: 'https://new-api.example.test/api/v2',+ rpcProxyBaseUrl: 'https://rpc.new-api.example.test/v2',+ })+ const state = await runtimeConfigModule!.getDesktopRuntimeConfigState()+ const exactTarget = state.options.find(+ option => option.externalRestApiBaseUrl === linkedEnvironment.externalRestApiBaseUrl+ )+ if (!exactTarget) throw new Error('The config producer did not return the exact REST profile')+ await runtimeConfigModule!.selectDesktopRuntimeConfigOption(exactTarget.id)++ await act(async () => {+ await confirmDesktopEnvironmentSetupForTest?.()+ })++ expect(mocks.saveRuntimeConfig).not.toHaveBeenCalled()+ expect(mocks.selectRuntimeConfig).not.toHaveBeenCalled()+ expect(screen.getByTestId('pending-environment')).toHaveTextContent('none')+ expect(mocks.setStatus).toHaveBeenLastCalledWith(+ `Opening ${linkedEnvironment.appName} in Evenfire Desktop.`,+ 'success'+ )})it('does not let runtime discovery overwrite another saved REST profile', async () => {diff --git a/desktop-app/ui/src/hooks/domain/desktopEnvironmentHandoff.ts b/desktop-app/ui/src/hooks/domain/desktopEnvironmentHandoff.tsindex 85284e151..c37c6d26f 100644--- a/desktop-app/ui/src/hooks/domain/desktopEnvironmentHandoff.ts+++ b/desktop-app/ui/src/hooks/domain/desktopEnvironmentHandoff.ts@@ -79,6 +79,7 @@ export function getDesktopEnvironmentRestMatches() {const restOrigin = desktopRestEndpointOrigin(externalRestApiBaseUrl)return {+ active: isActiveRestEndpointMatch(configState, externalRestApiBaseUrl),localhost: configState.options.find(option => {if (!isLocalhostOption(option)) return falsetry {@@ -218,17 +219,18 @@ export function createDesktopEnvironmentSetupHandler({)return}- if (restMatches.sameOriginDifferentEndpoint.length > 0) {+ let authState = getAuthState()+ let activeRestEndpointMatches = restMatches.active+ if (+ !activeRestEndpointMatches &&+ restMatches.saved.length === 0 &&+ restMatches.sameOriginDifferentEndpoint.length > 0+ ) {setPendingDesktopEnvironmentSetup(null)rejectSameOriginPathConflict(setStatus)return}- let authState = getAuthState()- let activeRestEndpointMatches = isActiveRestEndpointMatch(- configState,- linkedConfig.externalRestApiBaseUrl- )if (restMatches.saved.length > 1 && !activeRestEndpointMatches) {setPendingDesktopEnvironmentSetup(null)setStatus(@@ -338,15 +340,16 @@ export function createDesktopEnvironmentSetupHandler({)return}- if (restMatches.sameOriginDifferentEndpoint.length > 0) {+ activeRestEndpointMatches = restMatches.active+ if (+ !activeRestEndpointMatches &&+ restMatches.saved.length === 0 &&+ restMatches.sameOriginDifferentEndpoint.length > 0+ ) {setPendingDesktopEnvironmentSetup(null)rejectSameOriginPathConflict(setStatus)return}- activeRestEndpointMatches = isActiveRestEndpointMatch(- configState,- linkedConfig.externalRestApiBaseUrl- )if (restMatches.saved.length > 1 && !activeRestEndpointMatches) {setPendingDesktopEnvironmentSetup(null)setStatus(diff --git a/desktop-app/ui/src/hooks/domain/useAuthController.ts b/desktop-app/ui/src/hooks/domain/useAuthController.tsindex 46fd73d8b..fb92f1324 100644--- a/desktop-app/ui/src/hooks/domain/useAuthController.ts+++ b/desktop-app/ui/src/hooks/domain/useAuthController.ts@@ -555,7 +555,13 @@ export function useAuthController({return}- if (restMatches.sameOriginDifferentEndpoint.length > 0) {+ if (restMatches.active) {+ setPendingDesktopEnvironmentSetup(null)+ setStatus(`Opening ${nextConfig.appName} in Evenfire Desktop.`, 'success')+ return+ }++ if (restMatches.saved.length === 0 && restMatches.sameOriginDifferentEndpoint.length > 0) {setPendingDesktopEnvironmentSetup(null)setStatus('Desktop setup link rejected because this REST host is already saved with a different API endpoint.',