Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop-app): offer Localhost only when one is actually running
Andy Pavia9644d8345489
diff --git a/desktop-app/ui/src/components/RuntimeConfigDock/index.tsx b/desktop-app/ui/src/components/RuntimeConfigDock/index.tsxindex 8b9da4996..17d0aaab7 100644--- a/desktop-app/ui/src/components/RuntimeConfigDock/index.tsx+++ b/desktop-app/ui/src/components/RuntimeConfigDock/index.tsx@@ -6,6 +6,7 @@ import {LOCALHOST_RUNTIME_CONFIG_OPTION_ID,createLocalhostRuntimeConfigOption,} from '@constants/runtimeConfig'+import { useLocalhostReachable } from '@hooks/useLocalhostReachable'import type { DesktopRuntimeConfigOption } from '../../../../src/types'interface RuntimeConfigDockProps {@@ -44,8 +45,19 @@ export function RuntimeConfigDock({ onAddEnvironment }: RuntimeConfigDockProps)const localhostRuntimeConfigOption = runtimeConfigOptions.find(option => option.source === 'localhost')+ // Offer Localhost only when a local Evenfire actually answers, so the menu+ // never advertises a server that isn't there. The exception is a Localhost+ // that is already the active environment: hiding the row the user is+ // currently on would strand them with no way to see or leave it — a cluster+ // that went down mid-session is exactly when that row matters most.+ const localhostIsActive =+ activeRuntimeConfigId === LOCALHOST_RUNTIME_CONFIG_OPTION_ID ||+ selectedRuntimeConfig?.source === 'localhost'+ const localhostReachable = useLocalhostReachable()const displayedLocalhostRuntimeConfigOption =- localhostRuntimeConfigOption || createLocalhostRuntimeConfigOption()+ localhostReachable || localhostIsActive+ ? localhostRuntimeConfigOption || createLocalhostRuntimeConfigOption()+ : nullconst handleRuntimeOptionSelect = (optionId: string) => {setRuntimeMenuOpen(false)diff --git a/desktop-app/ui/src/hooks/useLocalhostReachable.ts b/desktop-app/ui/src/hooks/useLocalhostReachable.tsnew file mode 100644index 000000000..0bd19f266--- /dev/null+++ b/desktop-app/ui/src/hooks/useLocalhostReachable.ts@@ -0,0 +1,36 @@+import { useEffect, useState } from 'react'++/**+ * Whether a local Evenfire is answering on this machine (spec §5.6).+ *+ * One bounded probe per mount. The main process takes no URL — it only ever+ * checks the built-in Localhost option — so the renderer cannot use this to+ * reach an arbitrary host. A failed or slow probe resolves to `false`, which+ * every caller renders as "show nothing": a machine with no local cluster+ * never sees a Localhost affordance advertising a server that isn't there.+ *+ * Optional-chained throughout because tests and stale dev preloads can leave+ * `window.clerum` partially defined, and a missing bridge must degrade to+ * "not reachable" rather than throwing during render.+ */+export function useLocalhostReachable(): boolean {+ const [reachable, setReachable] = useState(false)++ useEffect(() => {+ let cancelled = false+ const probe = window.clerum?.auth?.probeLocalhostReachable+ if (typeof probe !== 'function') return++ probe()+ .then(result => {+ if (!cancelled) setReachable(Boolean(result))+ })+ .catch(() => undefined)++ return () => {+ cancelled = true+ }+ }, [])++ return reachable+}diff --git a/desktop-app/ui/src/pages/OnboardingPage/steps/ManualEnvironment.tsx b/desktop-app/ui/src/pages/OnboardingPage/steps/ManualEnvironment.tsxindex 427d72d27..282fe2947 100644--- a/desktop-app/ui/src/pages/OnboardingPage/steps/ManualEnvironment.tsx+++ b/desktop-app/ui/src/pages/OnboardingPage/steps/ManualEnvironment.tsx@@ -1,8 +1,11 @@import type { FormEvent } from 'react'-import { useEffect, useState } from 'react'import { useAuthContext } from '@contexts/AuthContext'-import { Button, Field, StatusBanner, TextInput } from '@components/Common'-import { LOCALHOST_RUNTIME_CONFIG_OPTION_ID } from '@constants/runtimeConfig'+import { Button, Field, SelectableOption, TextInput } from '@components/Common'+import {+ LOCALHOST_RUNTIME_CONFIG_OPTION_ID,+ createLocalhostRuntimeConfigOption,+} from '@constants/runtimeConfig'+import { useLocalhostReachable } from '@hooks/useLocalhostReachable'/*** Path D — manual environment (spec §5.6).@@ -22,32 +25,16 @@ export function ManualEnvironment() {handleSelectRuntimeConfig,} = useAuthContext()- const [localhostReachable, setLocalhostReachable] = useState(false)+ // One bounded probe on entry (spec §9.4). A negative or failed result+ // renders nothing, so a user with no local cluster sees no trace of it. The+ // probe never fills the form or saves on its own.+ const localhostReachable = useLocalhostReachable()+ const localhostOption = createLocalhostRuntimeConfigOption()const hasRuntimeSetupValues =Boolean(runtimeConfigSetupName.trim()) &&Boolean(runtimeConfigSetupExternalRestApiBaseUrl.trim())- // One bounded probe on entry (spec §9.4). It takes no URL — the main process- // only ever checks the built-in Localhost option — and a negative or failed- // result renders nothing, so a user with no local cluster sees no trace of- // it. The probe never fills the form or saves on its own.- useEffect(() => {- let cancelled = false- const probe = window.clerum.auth.probeLocalhostReachable- if (typeof probe !== 'function') return-- probe()- .then(reachable => {- if (!cancelled) setLocalhostReachable(reachable)- })- .catch(() => undefined)-- return () => {- cancelled = true- }- }, [])-const handleSubmit = (event: FormEvent<HTMLFormElement>) => {event.preventDefault()if (!busy && hasRuntimeSetupValues) {@@ -62,21 +49,19 @@ export function ManualEnvironment() {Enter the address of your Evenfire server. You can add more environments later.</p>{localhostReachable ? (- <StatusBanner tone="info">- <span className="auth-backend-hint">- <span>A local Evenfire looks like it’s running on this machine.</span>- <Button- type="button"- size="sm"- variant="soft"- block- disabled={busy}- onClick={() => void handleSelectRuntimeConfig(LOCALHOST_RUNTIME_CONFIG_OPTION_ID)}- >- Use Localhost- </Button>- </span>- </StatusBanner>+ <div className="onboarding-options">+ <SelectableOption+ className="onboarding-option"+ size="lg"+ disabled={busy}+ onClick={() => void handleSelectRuntimeConfig(LOCALHOST_RUNTIME_CONFIG_OPTION_ID)}+ >+ <span className="onboarding-option__title">Localhost</span>+ <span className="onboarding-option__hint">+ {localhostOption.externalRestApiBaseUrl}+ </span>+ </SelectableOption>+ </div>) : null}<form className="auth-form-stack" onSubmit={handleSubmit}><Fielddiff --git a/desktop-app/ui/src/pages/__tests__/AuthPage.test.tsx b/desktop-app/ui/src/pages/__tests__/AuthPage.test.tsxindex 6552befce..0481394ce 100644--- a/desktop-app/ui/src/pages/__tests__/AuthPage.test.tsx+++ b/desktop-app/ui/src/pages/__tests__/AuthPage.test.tsx@@ -1,5 +1,5 @@// @vitest-environment jsdom-import { afterEach, describe, expect, it, vi } from 'vitest'+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'import { cleanup, render, screen } from '@testing-library/react'import userEvent from '@testing-library/user-event'import { LOCALHOST_RUNTIME_CONFIG_OPTION_ID } from '../../constants/runtimeConfig'@@ -11,6 +11,15 @@ afterEach(() => {cleanup()})+// The environment dock probes for a local Evenfire and only lists Localhost+// when one answers, so these tests must say whether one is running.+let probeLocalhostReachable = vi.fn()++beforeEach(() => {+ probeLocalhostReachable = vi.fn().mockResolvedValue(false)+ ;(window as unknown as { clerum: unknown }).clerum = { auth: { probeLocalhostReachable } }+})+const makeAuthValue = (overrides: Partial<AuthContextValue> = {}): AuthContextValue => ({booting: false,busy: false,@@ -129,9 +138,10 @@ describe('AuthPage', () => {expect(screen.queryByLabelText('Environment name')).toBeNull()})- it('shows localhost in the environment menu even when no options are configured', async () => {+ it('shows localhost in the environment menu when one is detected', async () => {const user = userEvent.setup()const handleSelectRuntimeConfig = vi.fn()+ probeLocalhostReachable.mockResolvedValue(true)renderAuthPage({runtimeConfigMissing: true,@@ -149,16 +159,46 @@ describe('AuthPage', () => {await user.click(screen.getByLabelText('Open environment selector'))- expect(screen.getByRole('button', { name: 'Localhost' })).toBeTruthy()- expect(- screen.getByRole('button', { name: 'Localhost' }).getAttribute('aria-current')- ).toBeNull()+ const localhost = await screen.findByRole('button', { name: 'Localhost' })+ expect(localhost.getAttribute('aria-current')).toBeNull()- await user.click(screen.getByRole('button', { name: 'Localhost' }))+ await user.click(localhost)expect(handleSelectRuntimeConfig).toHaveBeenCalledWith(LOCALHOST_RUNTIME_CONFIG_OPTION_ID)})+ it('omits localhost from the environment menu when nothing is running', async () => {+ const user = userEvent.setup()++ renderAuthPage()++ await user.click(screen.getByLabelText('Open environment selector'))++ expect(screen.queryByRole('button', { name: 'Localhost' })).toBeNull()+ })++ it('keeps localhost listed while it is the active environment', async () => {+ const user = userEvent.setup()++ // A local cluster that went down mid-session must not silently vanish from+ // the menu the user is currently pointed at.+ renderAuthPage({+ runtimeConfigState: {+ configured: true,+ isLocalhost: true,+ selectorVisible: true,+ activeOptionId: LOCALHOST_RUNTIME_CONFIG_OPTION_ID,+ envKey: 'env-test-key',+ storagePath: '/tmp/evenfire-runtime-config',+ options: [],+ },+ })++ await user.click(screen.getByLabelText('Open environment selector'))++ expect(screen.getByRole('button', { name: 'Localhost' })).toBeTruthy()+ })+it('offers a switch-and-retry action when a backend-mismatch hint is present', async () => {const user = userEvent.setup()const handleSwitchLoginBackend = vi.fn()diff --git a/desktop-app/ui/src/pages/__tests__/OnboardingPage.test.tsx b/desktop-app/ui/src/pages/__tests__/OnboardingPage.test.tsxindex 717e3cde6..b37075e35 100644--- a/desktop-app/ui/src/pages/__tests__/OnboardingPage.test.tsx+++ b/desktop-app/ui/src/pages/__tests__/OnboardingPage.test.tsx@@ -246,36 +246,44 @@ describe('OnboardingPage', () => {renderOnboarding({ handleSelectRuntimeConfig })await user.click(screen.getByRole('button', { name: /I have a server address/ }))- const hint = await screen.findByRole('button', { name: 'Use Localhost' })+ // Presented as a plain option carrying its address, not a callout banner.+ const option = await screen.findByRole('button', { name: /Localhost/ })+ expect(option.textContent).toContain('http://127.0.0.1:8091')// The probe takes no URL argument (spec §5.6).expect(probeLocalhostReachable).toHaveBeenCalledWith()- await user.click(hint)+ await user.click(option)// Reuses the built-in Localhost option rather than saving a duplicate// environment that points at the same address.expect(handleSelectRuntimeConfig).toHaveBeenCalledWith(LOCALHOST_RUNTIME_CONFIG_OPTION_ID)})- it('shows no local-cluster hint when nothing answers', async () => {+ it('shows nothing about Localhost anywhere when nothing answers', async () => {const user = userEvent.setup()renderOnboarding()await user.click(screen.getByRole('button', { name: /I have a server address/ }))-await screen.findByLabelText('Environment name')- expect(probeLocalhostReachable).toHaveBeenCalledTimes(1)- expect(screen.queryByRole('button', { name: 'Use Localhost' })).toBeNull()++ expect(probeLocalhostReachable).toHaveBeenCalledWith()+ expect(screen.queryByRole('button', { name: /Localhost/ })).toBeNull()++ // Not in the environment dock either — the menu must not advertise a+ // server that isn't running.+ await user.click(screen.getByLabelText('Open environment selector'))+ expect(screen.queryByRole('button', { name: /Localhost/ })).toBeNull()})- it('keeps the Localhost escape hatch reachable from onboarding', async () => {+ it('keeps the Localhost escape hatch in the dock once one is detected', async () => {const user = userEvent.setup()const handleSelectRuntimeConfig = vi.fn()+ probeLocalhostReachable.mockResolvedValue(true)renderOnboarding({ handleSelectRuntimeConfig })await user.click(screen.getByLabelText('Open environment selector'))- await user.click(screen.getByRole('button', { name: 'Localhost' }))+ await user.click(await screen.findByRole('button', { name: 'Localhost' }))expect(handleSelectRuntimeConfig).toHaveBeenCalledWith(LOCALHOST_RUNTIME_CONFIG_OPTION_ID)})