Skip to content

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

TypeScript

fix(profile-ui): address PR #344 review on the release label

Jose Ramirez617bc302c23a
diff --git a/profile-ui/app/components/ReleaseLabel/index.tsx b/profile-ui/app/components/ReleaseLabel/index.tsx
index 37a617a3a..8f8cce154 100644
--- a/profile-ui/app/components/ReleaseLabel/index.tsx
+++ b/profile-ui/app/components/ReleaseLabel/index.tsx
@@ -5,6 +5,7 @@ import {
formatReleaseLabel,
loadReleaseIdentity,
readCachedReleaseIdentity,
+ subscribeReleaseIdentity,
} from '@lib/releaseIdentity'
import type { ReleaseIdentityState, ReleaseLabelProps } from './types'
@@ -13,6 +14,10 @@ import type { ReleaseIdentityState, ReleaseLabelProps } from './types'
// number is a per-commit counter (scripts/precommit/bump-staged-package-versions.mjs)
// and is not a release coordinate, so it can never be matched to a tag, a
// release, or a docs page.
+//
+// The hook lives here rather than in lib/ because lib/ is React-free, and
+// because a hook exported from its component's index.tsx is the established
+// shape in this app (useAuth, useToast, useProfileAccess, useConfirmDialog).
export function useReleaseIdentity(): ReleaseIdentityState {
const cached = readCachedReleaseIdentity()
const [releaseId, setReleaseId] = useState<string | null>(cached?.releaseId ?? null)
@@ -20,13 +25,20 @@ export function useReleaseIdentity(): ReleaseIdentityState {
useEffect(() => {
let active = true
- void loadReleaseIdentity().then(identity => {
+ const apply = (identity: { releaseId: string } | null) => {
if (!active) return
setReleaseId(identity?.releaseId ?? null)
setLoading(false)
- })
+ }
+
+ // Subscribe before loading: a read resolved for any other mounted label,
+ // or a refresh driven by the settings page, lands on this instance too.
+ const unsubscribe = subscribeReleaseIdentity(apply)
+ void loadReleaseIdentity().then(apply)
+
return () => {
active = false
+ unsubscribe()
}
}, [])
diff --git a/profile-ui/app/components/Sidebar/index.tsx b/profile-ui/app/components/Sidebar/index.tsx
index 5a8cb9857..223f09e06 100644
--- a/profile-ui/app/components/Sidebar/index.tsx
+++ b/profile-ui/app/components/Sidebar/index.tsx
@@ -4,6 +4,7 @@ import Image from 'next/image'
import Link from 'next/link'
import { useProfileAccess } from '@components/ProfileAccessContext'
import { useReleaseIdentity } from '@components/ReleaseLabel'
+import { formatReleaseTitle } from '@lib/releaseIdentity'
import { PROFILE_SIDEBAR_ITEMS } from './constants'
import { IconLogout } from './icons'
import type { ProfileRouteKey, ProfileSidebarItem, SidebarProps } from './types'
@@ -26,7 +27,7 @@ export function Sidebar({ currentRoute, isOpen = false, onNavigate, onLogout }:
className={`cu-sidebar${isOpen ? ' cu-sidebar--open' : ''}`}
aria-label="Main navigation"
>
- <div className="cu-sidebar__brand" title={releaseId ? `Release ${releaseId}` : undefined}>
+ <div className="cu-sidebar__brand" title={formatReleaseTitle(releaseId)}>
<Image
className="cu-sidebar__brand-mark"
src="/brand/logo.svg"
diff --git a/profile-ui/app/components/__tests__/ReleaseLabel.test.tsx b/profile-ui/app/components/__tests__/ReleaseLabel.test.tsx
index 8a7fbf01f..3a41bf704 100644
--- a/profile-ui/app/components/__tests__/ReleaseLabel.test.tsx
+++ b/profile-ui/app/components/__tests__/ReleaseLabel.test.tsx
@@ -1,9 +1,9 @@
import React from 'react'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import '@testing-library/jest-dom/vitest'
-import { cleanup, render, screen } from '@testing-library/react'
+import { act, cleanup, render, screen } from '@testing-library/react'
import { ReleaseLabel } from '@components/ReleaseLabel'
-import { resetReleaseIdentityCache } from '@lib/releaseIdentity'
+import { refreshReleaseIdentity, resetReleaseIdentityCache } from '@lib/releaseIdentity'
const api = vi.hoisted(() => ({
getDesktopRelease: vi.fn(),
@@ -56,6 +56,36 @@ describe('ReleaseLabel', () => {
expect(screen.queryByText(/Version 0\.1\./)).not.toBeInTheDocument()
})
+ // The settings Refresh button drives refreshReleaseIdentity(). A label that
+ // caught a transient failure must heal in place, without remounting.
+ it('heals a mounted label in place when a later read succeeds', async () => {
+ api.getDesktopRelease.mockRejectedValueOnce(new Error('503 Service Unavailable'))
+
+ render(<ReleaseLabel />)
+ expect(await screen.findByText('Release unavailable')).toBeInTheDocument()
+
+ api.getDesktopRelease.mockResolvedValue({ releaseId: 'v0.6.0' })
+ await act(async () => {
+ await refreshReleaseIdentity()
+ })
+
+ expect(screen.getByText('Release v0.6.0')).toBeInTheDocument()
+ })
+
+ it('publishes one read to every mounted label', async () => {
+ api.getDesktopRelease.mockResolvedValue({ releaseId: 'v0.6.0' })
+
+ render(
+ <>
+ <ReleaseLabel className="first" />
+ <ReleaseLabel className="second" />
+ </>
+ )
+
+ expect(await screen.findAllByText('Release v0.6.0')).toHaveLength(2)
+ expect(api.getDesktopRelease).toHaveBeenCalledTimes(1)
+ })
+
it('reads the release once and shares it with later mounts', async () => {
api.getDesktopRelease.mockResolvedValue({ releaseId: 'v0.6.0' })
diff --git a/profile-ui/app/settings/SettingsContent.tsx b/profile-ui/app/settings/SettingsContent.tsx
index fc7469b8f..c5ca67275 100644
--- a/profile-ui/app/settings/SettingsContent.tsx
+++ b/profile-ui/app/settings/SettingsContent.tsx
@@ -37,6 +37,7 @@ import {
removeDraftRow,
updateDraftRow,
} from '@lib/profileSettings'
+import { refreshReleaseIdentity } from '@lib/releaseIdentity'
import type { DesktopEnvironmentResponse } from '@/app/types/api'
import type { WorkflowApprovalMediumAccount } from '@/app/types/approvalChannels'
import type { Me } from '@/app/types/profile'
@@ -143,6 +144,11 @@ export function SettingsContent({
async function loadAll(forceAccess = false) {
setState('loading')
setError('')
+ // An explicit Refresh re-reads the release too, so a label left on
+ // "Release unavailable" by a transient failure heals here instead of
+ // waiting for a remount. Deliberately not on the mount path: that would
+ // defeat the per-session cache the label shares with the sidebar.
+ if (forceAccess) void refreshReleaseIdentity()
try {
const [current, , nextAccounts] = await Promise.all([
getMe(),
diff --git a/profile-ui/lib/releaseIdentity.ts b/profile-ui/lib/releaseIdentity.ts
index 4b0a6ef23..ef85c0dc8 100644
--- a/profile-ui/lib/releaseIdentity.ts
+++ b/profile-ui/lib/releaseIdentity.ts
@@ -8,6 +8,12 @@ export type ReleaseIdentity = {
export type ReleaseIdentityFetcher = () => Promise<unknown>
+export type ReleaseIdentityListener = (identity: ReleaseIdentity | null) => void
+
+// One prefix, one place. Both call sites render it: the settings line through
+// formatReleaseLabel, the sidebar brand through formatReleaseTitle.
+const RELEASE_PREFIX = 'Release'
+
// The running external-rest-api image bakes its release identity in, so the
// value cannot change while the tab is open. One resolved read is cached for
// the page session and shared by the always-mounted sidebar and the settings
@@ -17,15 +23,42 @@ export type ReleaseIdentityFetcher = () => Promise<unknown>
let cachedIdentity: ReleaseIdentity | null = null
let inFlight: Promise<ReleaseIdentity | null> | null = null
+// Every mounted label subscribes, so a read resolved by one of them lands on
+// all of them. Without this, an instance that caught a transient failure would
+// keep showing "unavailable" until it happened to remount, even after a later
+// read succeeded.
+const listeners = new Set<ReleaseIdentityListener>()
+
+export function subscribeReleaseIdentity(listener: ReleaseIdentityListener): () => void {
+ listeners.add(listener)
+ return () => {
+ listeners.delete(listener)
+ }
+}
+
+function publishReleaseIdentity(identity: ReleaseIdentity | null): void {
+ // Iterate a copy: a listener may unsubscribe (unmount) while being notified.
+ for (const listener of [...listeners]) listener(identity)
+}
+
export function normalizeReleaseIdentity(payload: unknown): ReleaseIdentity | null {
if (!payload || typeof payload !== 'object') return null
- const releaseId = String((payload as { releaseId?: unknown }).releaseId ?? '').trim()
+ const raw = (payload as { releaseId?: unknown }).releaseId
+ // typeof rather than String(): coercion would turn an object into the truthy
+ // "[object Object]" and accept it as a release name.
+ if (typeof raw !== 'string') return null
+ const releaseId = raw.trim()
return releaseId ? { releaseId } : null
}
+export function formatReleaseTitle(releaseId: string | null): string | undefined {
+ return releaseId ? `${RELEASE_PREFIX} ${releaseId}` : undefined
+}
+
export function formatReleaseLabel(releaseId: string | null, loading = false): string {
- if (releaseId) return `Release ${releaseId}`
- return loading ? 'Release ...' : 'Release unavailable'
+ const title = formatReleaseTitle(releaseId)
+ if (title) return title
+ return loading ? `${RELEASE_PREFIX} ...` : `${RELEASE_PREFIX} unavailable`
}
export function readCachedReleaseIdentity(): ReleaseIdentity | null {
@@ -47,10 +80,12 @@ export async function loadReleaseIdentity(
try {
const identity = normalizeReleaseIdentity(await fetcher())
if (identity) cachedIdentity = identity
+ publishReleaseIdentity(identity)
return identity
} catch {
// Never surfaced to the page and never allowed to drive navigation: the
// settings page's own getMe() call is what detects a dead session.
+ publishReleaseIdentity(null)
return null
} finally {
inFlight = null
@@ -59,3 +94,13 @@ export async function loadReleaseIdentity(
return inFlight
}
+
+// Drops a resolved read so the next load re-asks. The settings Refresh button
+// routes through here, which is what lets a label that caught a transient
+// failure heal in place rather than waiting to be remounted.
+export async function refreshReleaseIdentity(
+ fetcher: ReleaseIdentityFetcher = getDesktopRelease
+): Promise<ReleaseIdentity | null> {
+ cachedIdentity = null
+ return loadReleaseIdentity(fetcher)
+}
diff --git a/profile-ui/package-lock.json b/profile-ui/package-lock.json
index ee80888fa..ee191a51d 100644
--- a/profile-ui/package-lock.json
+++ b/profile-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-profile-ui",
- "version": "0.1.121",
+ "version": "0.1.122",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-profile-ui",
- "version": "0.1.121",
+ "version": "0.1.122",
"dependencies": {
"@clerum/desktop-app-links": "file:../packages/desktop-app-links",
"next": "16.2.11",
diff --git a/profile-ui/package.json b/profile-ui/package.json
index d13d230b7..3a220df6b 100644
--- a/profile-ui/package.json
+++ b/profile-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-profile-ui",
- "version": "0.1.121",
+ "version": "0.1.122",
"private": true,
"scripts": {
"dev": "next dev",
diff --git a/profile-ui/test/releaseIdentity.test.ts b/profile-ui/test/releaseIdentity.test.ts
index 8ae2663b1..1ba713075 100644
--- a/profile-ui/test/releaseIdentity.test.ts
+++ b/profile-ui/test/releaseIdentity.test.ts
@@ -2,9 +2,12 @@ import assert from 'node:assert/strict'
import test from 'node:test'
import {
formatReleaseLabel,
+ formatReleaseTitle,
loadReleaseIdentity,
normalizeReleaseIdentity,
+ refreshReleaseIdentity,
resetReleaseIdentityCache,
+ subscribeReleaseIdentity,
} from '../lib/releaseIdentity'
test('normalizeReleaseIdentity keeps a trimmed release id', () => {
@@ -18,6 +21,25 @@ test('normalizeReleaseIdentity rejects payloads that carry no release id', () =>
assert.equal(normalizeReleaseIdentity('v0.6.0'), null)
})
+// String() coercion would turn any of these into a truthy label: an object
+// becomes "[object Object]", a number becomes its digits.
+test('normalizeReleaseIdentity rejects a release id that is not a string', () => {
+ assert.equal(normalizeReleaseIdentity({ releaseId: { tag: 'v0.6.0' } }), null)
+ assert.equal(normalizeReleaseIdentity({ releaseId: ['v0.6.0'] }), null)
+ assert.equal(normalizeReleaseIdentity({ releaseId: 6 }), null)
+ assert.equal(normalizeReleaseIdentity({ releaseId: true }), null)
+})
+
+test('formatReleaseTitle shares one prefix with the settings label', () => {
+ assert.equal(formatReleaseTitle('v0.6.0'), 'Release v0.6.0')
+ assert.equal(formatReleaseTitle('v0.6.0'), formatReleaseLabel('v0.6.0'))
+})
+
+// The sidebar brand needs an absent title, not the word "unavailable".
+test('formatReleaseTitle yields no title when the release is unknown', () => {
+ assert.equal(formatReleaseTitle(null), undefined)
+})
+
test('formatReleaseLabel names the release once it is known', () => {
assert.equal(formatReleaseLabel('v0.6.0'), 'Release v0.6.0')
})
@@ -84,3 +106,61 @@ test('loadReleaseIdentity swallows a rejected read instead of surfacing it', asy
assert.equal(await loadReleaseIdentity(fetcher), null)
})
+
+test('subscribeReleaseIdentity publishes a resolved read to every listener', async () => {
+ resetReleaseIdentityCache()
+ const seen: Array<{ releaseId: string } | null> = []
+ const unsubscribe = subscribeReleaseIdentity(identity => seen.push(identity))
+
+ await loadReleaseIdentity(async () => ({ releaseId: 'v0.6.0' }))
+ unsubscribe()
+
+ assert.deepEqual(seen, [{ releaseId: 'v0.6.0' }])
+})
+
+test('subscribeReleaseIdentity publishes a failed read so labels can fall back', async () => {
+ resetReleaseIdentityCache()
+ const seen: Array<{ releaseId: string } | null> = []
+ const unsubscribe = subscribeReleaseIdentity(identity => seen.push(identity))
+
+ await loadReleaseIdentity(async () => {
+ throw new Error('503 Service Unavailable')
+ })
+ unsubscribe()
+
+ assert.deepEqual(seen, [null])
+})
+
+test('subscribeReleaseIdentity stops publishing once unsubscribed', async () => {
+ resetReleaseIdentityCache()
+ const seen: Array<{ releaseId: string } | null> = []
+ const unsubscribe = subscribeReleaseIdentity(identity => seen.push(identity))
+ unsubscribe()
+
+ await loadReleaseIdentity(async () => ({ releaseId: 'v0.6.0' }))
+
+ assert.deepEqual(seen, [])
+})
+
+// The settings Refresh button routes through here. Without it, a label that
+// caught a transient failure stays on "unavailable" until it remounts.
+test('refreshReleaseIdentity re-reads past a cached value and republishes', async () => {
+ resetReleaseIdentityCache()
+ let calls = 0
+ const fetcher = async () => {
+ calls += 1
+ return { releaseId: calls === 1 ? 'v0.6.0' : 'v0.7.0' }
+ }
+ const seen: Array<{ releaseId: string } | null> = []
+ const unsubscribe = subscribeReleaseIdentity(identity => seen.push(identity))
+
+ await loadReleaseIdentity(fetcher)
+ await loadReleaseIdentity(fetcher)
+ assert.equal(calls, 1)
+
+ assert.deepEqual(await refreshReleaseIdentity(fetcher), { releaseId: 'v0.7.0' })
+ unsubscribe()
+
+ assert.equal(calls, 2)
+ assert.deepEqual(seen, [{ releaseId: 'v0.6.0' }, { releaseId: 'v0.7.0' }])
+})