Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop): honor explicit profile ui base
Josuéf37cb0821c30
diff --git a/desktop-app/src/__tests__/appService.sandboxUiApps.test.ts b/desktop-app/src/__tests__/appService.sandboxUiApps.test.tsindex b432b950a..749869ee6 100644--- a/desktop-app/src/__tests__/appService.sandboxUiApps.test.ts+++ b/desktop-app/src/__tests__/appService.sandboxUiApps.test.ts@@ -1,5 +1,6 @@import { beforeEach, describe, expect, it, vi } from 'vitest'import { AppService } from '../appService.js'+import { config } from '../config.js'import { ApiError } from '../httpClient.js'const {@@ -53,6 +54,7 @@ vi.mock('../config.js', () => ({rpcProxyBaseUrl: 'http://proxy',externalRestApiBaseUrl: 'http://rest',desktopProfileUiBaseUrl: 'https://profile.example.com',+ desktopProfileUiBaseUrlExplicit: false,enableDevLoginUi: false,requestTimeoutMs: 60000,appName: 'test',@@ -332,6 +334,11 @@ describe('AppService.openForgotPassword', () => {})describe('AppService profile UI link authority', () => {+ beforeEach(() => {+ config.desktopProfileUiBaseUrl = 'https://profile.example.com'+ config.desktopProfileUiBaseUrlExplicit = false+ })+it('uses and memoizes the authenticated invitation profile for shareable links', async () => {const service = makeService() as unknown as {me: { id: string; email: string }@@ -363,6 +370,58 @@ describe('AppService profile UI link authority', () => {)})+ it('uses an explicit Profile UI base for shareable links without registration lookup', async () => {+ config.desktopProfileUiBaseUrl = 'https://profile.self-hosted.example'+ config.desktopProfileUiBaseUrlExplicit = true+ const service = makeService() as unknown as {+ me: { id: string; email: string }+ memberRegistrationServiceClient: { getInvitationProfile: ReturnType<typeof vi.fn> }+ createSandboxUiDeepLink: (teamId?: string) => Promise<{ url: string }>+ }+ service.me = { id: 'user-1', email: '' }+ service.memberRegistrationServiceClient = {+ getInvitationProfile: vi.fn().mockRejectedValue(new Error('lookup unavailable')),+ }+ mockGetActiveSandboxUiLocation.mockReturnValue({+ recipeNs: 'sandbox-recipes',+ recipeName: 'task-board',+ path: '/tasks/42',+ })++ await expect(service.createSandboxUiDeepLink('team-1')).resolves.toEqual({+ url:+ 'https://profile.self-hosted.example/open/apps/sandbox-recipes/task-board' ++ '?path=%2Ftasks%2F42&team=team-1',+ })+ expect(service.memberRegistrationServiceClient.getInvitationProfile).not.toHaveBeenCalled()+ })++ it('fails closed when the explicit Profile UI base is invalid', async () => {+ config.desktopProfileUiBaseUrl = 'javascript:alert(1)'+ config.desktopProfileUiBaseUrlExplicit = true+ const service = makeService() as unknown as {+ me: { id: string; email: string }+ memberRegistrationServiceClient: { getInvitationProfile: ReturnType<typeof vi.fn> }+ createSandboxUiDeepLink: () => Promise<{ url: string }>+ }+ service.me = { id: 'user-1', email: '' }+ service.memberRegistrationServiceClient = {+ getInvitationProfile: vi.fn().mockResolvedValue({+ profileUiBaseUrl: 'https://profile.tenant.example',+ }),+ }+ mockGetActiveSandboxUiLocation.mockReturnValue({+ recipeNs: 'sandbox-recipes',+ recipeName: 'task-board',+ path: '/',+ })++ await expect(service.createSandboxUiDeepLink()).rejects.toThrow(+ 'Cannot resolve the configured Profile UI URL'+ )+ expect(service.memberRegistrationServiceClient.getInvitationProfile).not.toHaveBeenCalled()+ })+it('fails visibly instead of copying a localhost fallback after a lookup error', async () => {const service = makeService() as unknown as {me: { id: string; email: string }diff --git a/desktop-app/src/appService.ts b/desktop-app/src/appService.tsindex 6033b3a5d..19d3d64e3 100644--- a/desktop-app/src/appService.ts+++ b/desktop-app/src/appService.ts@@ -74,6 +74,23 @@ import {// the wake scope never widens a caller who was not granted it.const HOST_WAKE_SCOPE: RpcScope = 'host:wake:write'+function normalizeExplicitProfileUiBaseUrl(rawValue: string): string | null {+ const value = rawValue.trim()+ if (!value) return null+ let url: URL+ try {+ url = new URL(value)+ } catch {+ return null+ }+ if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password) {+ return null+ }+ if (url.pathname !== '/' || url.search) return null+ url.hash = ''+ return url.toString().replace(/\/$/, '')+}+/*** Finite-operation scope matrix — the single source of truth for the exact* scope array each finite (single request/response) Host RPC operation requests,@@ -726,6 +743,13 @@ export class AppService {options: { fallbackOnLookupError?: boolean } = {}): Promise<string> {const { fallbackOnLookupError = true } = options+ if (config.desktopProfileUiBaseUrlExplicit) {+ const explicitBaseUrl = normalizeExplicitProfileUiBaseUrl(config.desktopProfileUiBaseUrl)+ if (!explicitBaseUrl) {+ throw new Error('Cannot resolve the configured Profile UI URL for this desktop session')+ }+ return explicitBaseUrl+ }const normalizedEmail = String(email || this.me?.email || '').trim().toLowerCase()diff --git a/desktop-app/src/config.ts b/desktop-app/src/config.tsindex e749daf3e..1dcce5420 100644--- a/desktop-app/src/config.ts+++ b/desktop-app/src/config.ts@@ -14,6 +14,7 @@ type DesktopConfig = Omit<DesktopRuntimeConfig, 'appName' | 'rpcProxyBaseUrl'> &rpcProxyBaseUrl: stringmemberRegistrationServiceBaseUrl: stringdesktopProfileUiBaseUrl: string+ desktopProfileUiBaseUrlExplicit: booleanrequestTimeoutMs: numberappName: string}@@ -163,6 +164,10 @@ function deriveProfileUiBaseUrl(externalRestApiBaseUrl: string): string {return 'http://127.0.0.1:3001'}+function hasExplicitProfileUiBaseUrl(): boolean {+ return Boolean(process.env.PROFILE_UI_BASE_URL?.trim())+}+function runtimeConfigDirectoryPath(): string {const explicit = process.env.CLERUM_DESKTOP_CONFIG_PATH?.trim()if (explicit) return path.dirname(explicit)@@ -518,6 +523,7 @@ export const config: DesktopConfig = {'https://registration.evenfire.ai'),desktopProfileUiBaseUrl: deriveProfileUiBaseUrl(initialRuntimeConfig.externalRestApiBaseUrl),+ desktopProfileUiBaseUrlExplicit: hasExplicitProfileUiBaseUrl(),requestTimeoutMs: Number(requiredOrDefault('REQUEST_TIMEOUT_MS', '60000')),appName: initialRuntimeConfig.appName?.trim() || DEFAULT_APP_NAME,}@@ -527,6 +533,7 @@ function applyRuntimeConfig(next: DesktopRuntimeConfig, markConfigured: boolean)config.rpcProxyBaseUrl = next.rpcProxyBaseUrl || ''config.appName = next.appName?.trim() || DEFAULT_APP_NAMEconfig.desktopProfileUiBaseUrl = deriveProfileUiBaseUrl(next.externalRestApiBaseUrl)+ config.desktopProfileUiBaseUrlExplicit = hasExplicitProfileUiBaseUrl()if (markConfigured) desktopRuntimeConfigured = true}