Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix: require canonical REST endpoint equality

Josuéa84fac908436
diff --git a/desktop-app/src/__tests__/appService.bootstrap.test.ts b/desktop-app/src/__tests__/appService.bootstrap.test.ts
index 322e266a9..12c579342 100644
--- a/desktop-app/src/__tests__/appService.bootstrap.test.ts
+++ b/desktop-app/src/__tests__/appService.bootstrap.test.ts
@@ -53,7 +53,7 @@ describe('AppService invitation configuration lookup', () => {
tempDirs.clear()
})
- it('persists runtime config when desktop setup is completed', async () => {
+ it('accepts terminal-dot discovery when the canonical REST endpoint matches', async () => {
const configPath = await createTempConfigPath('clerum-desktop-config')
process.env.CLERUM_DESKTOP_CONFIG_PATH = configPath
delete process.env.EXTERNAL_REST_API_BASE_URL
@@ -83,14 +83,14 @@ describe('AppService invitation configuration lookup', () => {
completeDesktopSetup: vi.fn().mockResolvedValue({
valid: true,
- externalRestApiBaseUrl: 'https://api.example.com.',
+ externalRestApiBaseUrl: 'https://api.example.com',
rpcProxyBaseUrl: 'https://rpc.example.com',
appName: 'Evenfire',
}),
} as never
service.authClient = {
getDesktopEnvironment: vi.fn().mockResolvedValue({
- externalRestApiBaseUrl: 'https://api.example.com',
+ externalRestApiBaseUrl: 'https://api.example.com.',
rpcProxyBaseUrl: 'https://rpc.example.com',
appName: 'Evenfire',
}),
@@ -153,6 +153,59 @@ describe('AppService invitation configuration lookup', () => {
})
})
+ it('does not save RPC when dotted discovery names a different REST endpoint', async () => {
+ const configPath = await createTempConfigPath('clerum-desktop-config-mismatched-discovery')
+ process.env.CLERUM_DESKTOP_CONFIG_PATH = configPath
+ delete process.env.EXTERNAL_REST_API_BASE_URL
+ delete process.env.RPC_PROXY_BASE_URL
+ delete process.env.PROFILE_UI_BASE_URL
+ vi.resetModules()
+
+ const [{ AppService }, { config }] = await Promise.all([
+ import('../appService.js'),
+ import('../config.js'),
+ ])
+ const service = new AppService() as unknown as {
+ authClient: { getDesktopEnvironment: ReturnType<typeof vi.fn> }
+ memberRegistrationServiceClient: { completeDesktopSetup: ReturnType<typeof vi.fn> }
+ completeDesktopSetup: (email: string, authorizationToken: string) => Promise<unknown>
+ }
+
+ service.memberRegistrationServiceClient = {
+ completeDesktopSetup: vi.fn().mockResolvedValue({
+ valid: true,
+ email: '[email protected]',
+ externalRestApiBaseUrl: 'https://api.example.com/confirmed',
+ rpcProxyBaseUrl: '',
+ appName: 'Evenfire',
+ }),
+ } as never
+ service.authClient = {
+ getDesktopEnvironment: vi.fn().mockResolvedValue({
+ externalRestApiBaseUrl: 'https://api.example.com./different',
+ rpcProxyBaseUrl: 'https://rpc.example.com',
+ appName: 'Discovered',
+ }),
+ } as never
+
+ await service.completeDesktopSetup('[email protected]', 'setup-token')
+
+ expect(service.authClient.getDesktopEnvironment).toHaveBeenCalledOnce()
+ expect(config.externalRestApiBaseUrl).toBe('https://api.example.com/confirmed')
+ expect(config.rpcProxyBaseUrl).toBe('')
+
+ const persisted = JSON.parse(await fs.readFile(configPath, 'utf8')) as {
+ externalRestApiBaseUrl: string
+ rpcProxyBaseUrl: string
+ appName: string
+ }
+ expect(persisted).toEqual({
+ externalRestApiBaseUrl: 'https://api.example.com/confirmed',
+ rpcProxyBaseUrl: '',
+ appName: 'Evenfire',
+ })
+ })
+
it('does not contact member-registration-service when runtime config is already set', async () => {
process.env.EXTERNAL_REST_API_BASE_URL = 'https://api.example.com'
process.env.RPC_PROXY_BASE_URL = 'https://rpc.example.com'
diff --git a/desktop-app/src/appService.ts b/desktop-app/src/appService.ts
index c1e0a1647..f1644a9f8 100644
--- a/desktop-app/src/appService.ts
+++ b/desktop-app/src/appService.ts
@@ -18,7 +18,7 @@ import {
} from './config.js'
import {
canonicalizeDesktopRestEndpoint,
- desktopRestEndpointOrigin,
+ sameDesktopRestEndpoint,
} from './desktopEnvironmentUrl.js'
import { fetchBoundedBytes } from './gfs/boundedDownload.js'
import { type DelegationAffordances, delegationAffordances } from './gfs/delegation.js'
@@ -1948,13 +1948,9 @@ export class AppService {
if (!isDesktopRuntimeConfigured()) return
if (config.rpcProxyBaseUrl?.trim()) return
const externalRestApiBaseUrl = canonicalizeDesktopRestEndpoint(config.externalRestApiBaseUrl)
- const externalRestApiOrigin = desktopRestEndpointOrigin(externalRestApiBaseUrl)
const discovered = await this.authClient.getDesktopEnvironment()
- if (
- discovered.externalRestApiBaseUrl?.trim() &&
- desktopRestEndpointOrigin(discovered.externalRestApiBaseUrl) !== externalRestApiOrigin
- ) {
- throw new Error('Desktop environment discovery returned a different REST host')
+ if (!sameDesktopRestEndpoint(discovered.externalRestApiBaseUrl, externalRestApiBaseUrl)) {
+ throw new Error('Desktop environment discovery returned a different REST endpoint')
}
await saveDesktopRuntimeConfig({
// Discovery is scoped to the configured REST endpoint; it may provide