Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop): prevent runtime profile id collisions
Alfredo Lopezfcb955d00d70
diff --git a/desktop-app/src/config.ts b/desktop-app/src/config.tsindex 7454f9b82..432badd32 100644--- a/desktop-app/src/config.ts+++ b/desktop-app/src/config.ts@@ -1,5 +1,5 @@import { app } from 'electron'-import { createHash } from 'node:crypto'+import { createHash, randomUUID } from 'node:crypto'import fs from 'node:fs'import fsp from 'node:fs/promises'import os from 'node:os'@@ -783,7 +783,9 @@ export async function saveDesktopRuntimeConfig(next: DesktopRuntimeConfig): Promconst filePath = nextProfileFilePath(directoryPath, validated.appName || DEFAULT_APP_NAME)const timestamp = new Date().toISOString()const profile: StoredRuntimeProfile = {- id: `${toAppSlug(validated.appName || DEFAULT_APP_NAME)}-${Date.now()}`,+ // Two profiles can legitimately share an app name. A UUID keeps their+ // identities independent even when saves occur in the same millisecond.+ id: `${toAppSlug(validated.appName || DEFAULT_APP_NAME)}-${randomUUID()}`,appName: validated.appName?.trim() || DEFAULT_APP_NAME,filePath,createdAt: timestamp,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 c5753181f..5f854e3f7 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@@ -46,6 +46,7 @@ let setAuthenticatedForTest: ((value: boolean) => void) | null = nulllet runtimeConfigModule: typeof import('../../../../../src/config') | null = nulllet runtimeConfigDirectory = ''const originalOnboardingPreview = process.env.EVENFIRE_ONBOARDING_PREVIEW+const frozenProfileIdMilliseconds = 1790000000000function Probe() {const auth = useAuthController({@@ -92,6 +93,7 @@ async function savedTargetOptionId(): Promise<string> {beforeEach(async () => {vi.clearAllMocks()+ vi.spyOn(Date, 'now').mockReturnValue(frozenProfileIdMilliseconds)desktopEnvironmentSetupListener = nullconfirmDesktopEnvironmentSetupForTest = nullsetBootingForTest = null@@ -110,29 +112,11 @@ beforeEach(async () => {},}))runtimeConfigModule = await import('../../../../../src/config')- // Profile ids combine the app-name slug with Date.now(). Allocate the- // path-based target's id through a distinct temporary root profile, then- // discard that placeholder after creating the user-facing path profile.- await runtimeConfigModule.saveDesktopRuntimeConfig({- ...targetEnvironment,- appName: 'Example tenant path',- })await runtimeConfigModule.saveDesktopRuntimeConfig({...targetEnvironment,externalRestApiBaseUrl: `${targetEnvironment.externalRestApiBaseUrl}/api/v1`,rpcProxyBaseUrl: `${targetEnvironment.rpcProxyBaseUrl}/rpc`,})- const pathNamePlaceholder = (- await runtimeConfigModule.getDesktopRuntimeConfigState()- ).options.find(- option =>- option.externalRestApiBaseUrl === targetEnvironment.externalRestApiBaseUrl &&- option.rpcProxyBaseUrl === targetEnvironment.rpcProxyBaseUrl- )- if (!pathNamePlaceholder) {- throw new Error('The config producer did not retain the distinct path-profile id')- }- await runtimeConfigModule.deleteDesktopRuntimeConfigOption(pathNamePlaceholder.id)await runtimeConfigModule.saveDesktopRuntimeConfig(otherEnvironment)mocks.getRuntimeConfigState.mockImplementation(async () =>@@ -167,6 +151,7 @@ beforeEach(async () => {afterEach(async () => {cleanup()+ vi.restoreAllMocks()vi.doUnmock('electron')vi.resetModules()await fsp.rm(runtimeConfigDirectory, { recursive: true, force: true })@@ -257,6 +242,8 @@ describe('Desktop environment handoff', () => {option.rpcProxyBaseUrl === targetEnvironment.rpcProxyBaseUrl)if (!savedTarget) throw new Error('The config producer did not return the saved REST profile')+ // The frozen Date.now value makes the historical slug+timestamp collision+ // deterministic. Deleting one profile must never remove its same-name peer.expect(savedTarget.id).not.toBe(pathBasedTarget.id)const other = (await runtimeConfigModule!.getDesktopRuntimeConfigState()).options.find(option => option.id !== savedTarget.id && option.id !== '__localhost__'