Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop): r1-l3 clarify invalid Profile UI base configuration
Josuéa8b9fd0eb2b5
diff --git a/desktop-app/src/__tests__/appService.sandboxUiApps.test.ts b/desktop-app/src/__tests__/appService.sandboxUiApps.test.tsindex 749869ee6..5b2a98dc9 100644--- a/desktop-app/src/__tests__/appService.sandboxUiApps.test.ts+++ b/desktop-app/src/__tests__/appService.sandboxUiApps.test.ts@@ -333,6 +333,80 @@ describe('AppService.openForgotPassword', () => {})})+describe('AppService explicit Profile UI browser actions', () => {+ beforeEach(() => {+ vi.clearAllMocks()+ config.desktopProfileUiBaseUrl = 'https://profile.example.com'+ config.desktopProfileUiBaseUrlExplicit = false+ })++ it('opens forgot-password and profile settings from a valid explicit root origin', async () => {+ config.desktopProfileUiBaseUrl = 'https://profile.self-hosted.example/'+ config.desktopProfileUiBaseUrlExplicit = true+ const service = new AppService() as unknown as {+ memberRegistrationServiceClient: { getInvitationProfile: ReturnType<typeof vi.fn> }+ openForgotPassword: (email: string) => Promise<{ profileUiUrl: string }>+ openProfileSettings: (+ email: string,+ options?: { section?: 'profile'; action?: 'password' }+ ) => Promise<{ profileUiUrl: string }>+ }+ const getInvitationProfile = vi.fn()+ service.memberRegistrationServiceClient = { getInvitationProfile } as never++ await expect(service.openForgotPassword(' [email protected] ')).resolves.toEqual({+ profileUiUrl: 'https://profile.self-hosted.example/forgot-password?email=user%40example.com',+ })+ await expect(+ service.openProfileSettings(' [email protected] ', {+ section: 'profile',+ action: 'password',+ })+ ).resolves.toEqual({+ profileUiUrl: 'https://profile.self-hosted.example/settings/profile?action=password',+ })+ const { shell } = await import('electron')++ expect(shell.openExternal).toHaveBeenNthCalledWith(+ 1,+ 'https://profile.self-hosted.example/forgot-password?email=user%40example.com'+ )+ expect(shell.openExternal).toHaveBeenNthCalledWith(+ 2,+ 'https://profile.self-hosted.example/settings/profile?action=password'+ )+ expect(getInvitationProfile).not.toHaveBeenCalled()+ })++ for (const [label, baseUrl] of [+ ['non-root pathname', 'https://profile.self-hosted.example/profile'],+ ['search parameters', 'https://profile.self-hosted.example?tenant=one'],+ ] as const) {+ it(`rejects an explicit Profile UI base URL with ${label}`, async () => {+ config.desktopProfileUiBaseUrl = baseUrl+ config.desktopProfileUiBaseUrlExplicit = true+ const service = new AppService() as unknown as {+ memberRegistrationServiceClient: { getInvitationProfile: ReturnType<typeof vi.fn> }+ openForgotPassword: (email: string) => Promise<{ profileUiUrl: string }>+ openProfileSettings: (email: string) => Promise<{ profileUiUrl: string }>+ }+ const getInvitationProfile = vi.fn()+ service.memberRegistrationServiceClient = { getInvitationProfile } as never++ await expect(service.openForgotPassword('[email protected]')).rejects.toThrow(+ 'PROFILE_UI_BASE_URL must be an origin URL with a root pathname'+ )+ await expect(service.openProfileSettings('[email protected]')).rejects.toThrow(+ 'PROFILE_UI_BASE_URL must be an origin URL with a root pathname'+ )+ const { shell } = await import('electron')++ expect(shell.openExternal).not.toHaveBeenCalled()+ expect(getInvitationProfile).not.toHaveBeenCalled()+ })+ }+})+describe('AppService profile UI link authority', () => {beforeEach(() => {config.desktopProfileUiBaseUrl = 'https://profile.example.com'@@ -417,7 +491,7 @@ describe('AppService profile UI link authority', () => {})await expect(service.createSandboxUiDeepLink()).rejects.toThrow(- 'Cannot resolve the configured Profile UI URL'+ 'PROFILE_UI_BASE_URL must be an origin URL with a root pathname')expect(service.memberRegistrationServiceClient.getInvitationProfile).not.toHaveBeenCalled()})diff --git a/desktop-app/src/appService.ts b/desktop-app/src/appService.tsindex 19d3d64e3..a03e410c9 100644--- a/desktop-app/src/appService.ts+++ b/desktop-app/src/appService.ts@@ -73,6 +73,8 @@ import {// requested scopes against the caller's grants before issuance, so requesting// the wake scope never widens a caller who was not granted it.const HOST_WAKE_SCOPE: RpcScope = 'host:wake:write'+const PROFILE_UI_BASE_URL_ORIGIN_ERROR =+ 'PROFILE_UI_BASE_URL must be an origin URL with a root pathname and no search parameters'function normalizeExplicitProfileUiBaseUrl(rawValue: string): string | null {const value = rawValue.trim()@@ -91,6 +93,17 @@ function normalizeExplicitProfileUiBaseUrl(rawValue: string): string | null {return url.toString().replace(/\/$/, '')}+function requireProfileUiBaseUrlForBrowserAction(): string {+ if (!config.desktopProfileUiBaseUrlExplicit) {+ return config.desktopProfileUiBaseUrl+ }+ const explicitBaseUrl = normalizeExplicitProfileUiBaseUrl(config.desktopProfileUiBaseUrl)+ if (!explicitBaseUrl) {+ throw new Error(PROFILE_UI_BASE_URL_ORIGIN_ERROR)+ }+ return explicitBaseUrl+}+/*** Finite-operation scope matrix — the single source of truth for the exact* scope array each finite (single request/response) Host RPC operation requests,@@ -707,10 +720,8 @@ export class AppService {async openForgotPassword(email: string): Promise<{ profileUiUrl: string }> {const normalizedEmail = email.trim().toLowerCase()- const profileUiUrl = new URL(- '/forgot-password',- `${config.desktopProfileUiBaseUrl.replace(/\/+$/, '')}/`- )+ const profileUiBaseUrl = requireProfileUiBaseUrlForBrowserAction()+ const profileUiUrl = new URL('/forgot-password', `${profileUiBaseUrl.replace(/\/+$/, '')}/`)if (normalizedEmail) profileUiUrl.searchParams.set('email', normalizedEmail)const { shell } = await import('electron')await shell.openExternal(profileUiUrl.toString())@@ -746,7 +757,7 @@ export class AppService {if (config.desktopProfileUiBaseUrlExplicit) {const explicitBaseUrl = normalizeExplicitProfileUiBaseUrl(config.desktopProfileUiBaseUrl)if (!explicitBaseUrl) {- throw new Error('Cannot resolve the configured Profile UI URL for this desktop session')+ throw new Error(PROFILE_UI_BASE_URL_ORIGIN_ERROR)}return explicitBaseUrl}