Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(profile-ui): show the platform release, not the portal commit counter
Jose Ramirez85d17cedfb72
diff --git a/profile-ui/app/components/ReleaseLabel/index.tsx b/profile-ui/app/components/ReleaseLabel/index.tsxnew file mode 100644index 000000000..37a617a3a--- /dev/null+++ b/profile-ui/app/components/ReleaseLabel/index.tsx@@ -0,0 +1,39 @@+'use client'++import { useEffect, useState } from 'react'+import {+ formatReleaseLabel,+ loadReleaseIdentity,+ readCachedReleaseIdentity,+} from '@lib/releaseIdentity'+import type { ReleaseIdentityState, ReleaseLabelProps } from './types'++// The platform release the tenant is running, read from external-rest-api's+// release manifest. This is deliberately NOT profile-ui's package version: that+// 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.+export function useReleaseIdentity(): ReleaseIdentityState {+ const cached = readCachedReleaseIdentity()+ const [releaseId, setReleaseId] = useState<string | null>(cached?.releaseId ?? null)+ const [loading, setLoading] = useState(!cached)++ useEffect(() => {+ let active = true+ void loadReleaseIdentity().then(identity => {+ if (!active) return+ setReleaseId(identity?.releaseId ?? null)+ setLoading(false)+ })+ return () => {+ active = false+ }+ }, [])++ return { releaseId, loading }+}++export function ReleaseLabel({ className }: ReleaseLabelProps) {+ const { releaseId, loading } = useReleaseIdentity()+ return <div className={className}>{formatReleaseLabel(releaseId, loading)}</div>+}diff --git a/profile-ui/app/components/ReleaseLabel/types.ts b/profile-ui/app/components/ReleaseLabel/types.tsnew file mode 100644index 000000000..5ed102e6f--- /dev/null+++ b/profile-ui/app/components/ReleaseLabel/types.ts@@ -0,0 +1,8 @@+export type ReleaseLabelProps = {+ className?: string+}++export type ReleaseIdentityState = {+ releaseId: string | null+ loading: boolean+}diff --git a/profile-ui/app/components/Sidebar/index.tsx b/profile-ui/app/components/Sidebar/index.tsxindex 4f14a4922..5a8cb9857 100644--- a/profile-ui/app/components/Sidebar/index.tsx+++ b/profile-ui/app/components/Sidebar/index.tsx@@ -3,7 +3,7 @@import Image from 'next/image'import Link from 'next/link'import { useProfileAccess } from '@components/ProfileAccessContext'-import packageJson from '../../../package.json'+import { useReleaseIdentity } from '@components/ReleaseLabel'import { PROFILE_SIDEBAR_ITEMS } from './constants'import { IconLogout } from './icons'import type { ProfileRouteKey, ProfileSidebarItem, SidebarProps } from './types'@@ -11,6 +11,7 @@ import type { ProfileRouteKey, ProfileSidebarItem, SidebarProps } from './types'export function Sidebar({ currentRoute, isOpen = false, onNavigate, onLogout }: SidebarProps) {const { approvalTargets, approvalTargetsLoading, canManageMembers, manageableTeamsLoading } =useProfileAccess()+ const { releaseId } = useReleaseIdentity()const hasExternalChannelAccess = approvalTargets.length > 0const navigationItems = (@@ -25,7 +26,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={`Version ${packageJson.version}`}>+ <div className="cu-sidebar__brand" title={releaseId ? `Release ${releaseId}` : undefined}><ImageclassName="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.tsxnew file mode 100644index 000000000..8a7fbf01f--- /dev/null+++ b/profile-ui/app/components/__tests__/ReleaseLabel.test.tsx@@ -0,0 +1,70 @@+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 { ReleaseLabel } from '@components/ReleaseLabel'+import { resetReleaseIdentityCache } from '@lib/releaseIdentity'++const api = vi.hoisted(() => ({+ getDesktopRelease: vi.fn(),+}))++vi.mock('@lib/api', () => ({+ getDesktopRelease: api.getDesktopRelease,+}))++beforeEach(() => {+ resetReleaseIdentityCache()+ api.getDesktopRelease.mockReset()+})++afterEach(cleanup)++describe('ReleaseLabel', () => {+ it('names the platform release read from the release manifest', async () => {+ api.getDesktopRelease.mockResolvedValue({ releaseId: 'v0.6.0', desktopVersion: '0.6.0' })++ render(<ReleaseLabel />)++ expect(await screen.findByText('Release v0.6.0')).toBeInTheDocument()+ })++ it('holds a placeholder line while the release is being read', () => {+ api.getDesktopRelease.mockReturnValue(new Promise(() => {}))++ render(<ReleaseLabel />)++ expect(screen.getByText('Release ...')).toBeInTheDocument()+ })++ it('says the release is unavailable instead of throwing when the read fails', async () => {+ api.getDesktopRelease.mockRejectedValue(new Error('503 Service Unavailable'))++ render(<ReleaseLabel />)++ expect(await screen.findByText('Release unavailable')).toBeInTheDocument()+ })++ // The portal's package version is a per-commit counter, not a release+ // coordinate. Showing it here is the defect this component replaced.+ it('never falls back to the profile-ui package version', async () => {+ api.getDesktopRelease.mockRejectedValue(new Error('401 Unauthorized'))++ render(<ReleaseLabel />)++ expect(await screen.findByText('Release unavailable')).toBeInTheDocument()+ expect(screen.queryByText(/Version 0\.1\./)).not.toBeInTheDocument()+ })++ it('reads the release once and shares it with later mounts', async () => {+ api.getDesktopRelease.mockResolvedValue({ releaseId: 'v0.6.0' })++ const first = render(<ReleaseLabel />)+ expect(await screen.findByText('Release v0.6.0')).toBeInTheDocument()+ first.unmount()++ render(<ReleaseLabel />)+ expect(screen.getByText('Release v0.6.0')).toBeInTheDocument()+ expect(api.getDesktopRelease).toHaveBeenCalledTimes(1)+ })+})diff --git a/profile-ui/app/components/__tests__/Sidebar.test.tsx b/profile-ui/app/components/__tests__/Sidebar.test.tsxindex f6f70798a..2dd167c42 100644--- a/profile-ui/app/components/__tests__/Sidebar.test.tsx+++ b/profile-ui/app/components/__tests__/Sidebar.test.tsx@@ -1,8 +1,17 @@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 { cleanup, render, screen, waitFor } from '@testing-library/react'import { Sidebar } from '@components/Sidebar'+import { resetReleaseIdentityCache } from '@lib/releaseIdentity'++const api = vi.hoisted(() => ({+ getDesktopRelease: vi.fn(),+}))++vi.mock('@lib/api', () => ({+ getDesktopRelease: api.getDesktopRelease,+}))const profileAccessState = vi.hoisted(() => ({approvalTargets: [] as Array<{ id: string }>,@@ -49,6 +58,9 @@ beforeEach(() => {profileAccessState.manageableTeamsLoading = falseprofileAccessState.refreshApprovalTargets.mockClear()profileAccessState.refreshManageableTeams.mockClear()+ resetReleaseIdentityCache()+ api.getDesktopRelease.mockReset()+ api.getDesktopRelease.mockResolvedValue({ releaseId: 'v0.6.0' })})afterEach(cleanup)@@ -75,3 +87,22 @@ describe('Profile Sidebar access-controlled entries', () => {expect(view.container.querySelector('.cu-sidebar__item--loading')).toBeInTheDocument()})})++describe('Profile Sidebar release identity', () => {+ it('titles the brand with the platform release, not the portal package version', async () => {+ const view = render(<Sidebar currentRoute="settings" onLogout={vi.fn()} />)+ const brand = view.container.querySelector('.cu-sidebar__brand')++ await waitFor(() => expect(brand).toHaveAttribute('title', 'Release v0.6.0'))+ })++ it('leaves the brand untitled rather than naming a release it could not read', async () => {+ api.getDesktopRelease.mockRejectedValue(new Error('503 Service Unavailable'))++ const view = render(<Sidebar currentRoute="settings" onLogout={vi.fn()} />)+ const brand = view.container.querySelector('.cu-sidebar__brand')++ await waitFor(() => expect(api.getDesktopRelease).toHaveBeenCalled())+ expect(brand).not.toHaveAttribute('title')+ })+})diff --git a/profile-ui/app/settings/SettingsContent.tsx b/profile-ui/app/settings/SettingsContent.tsxindex 61e7a89f3..fc7469b8f 100644--- a/profile-ui/app/settings/SettingsContent.tsx+++ b/profile-ui/app/settings/SettingsContent.tsx@@ -11,6 +11,7 @@ import { FormField } from '@components/FormField'import { useProfileAccess } from '@components/ProfileAccessContext'import { ProfileBodySkeleton } from '@components/ProfileBodySkeleton'import { ProfileShell } from '@components/ProfileShell'+import { ReleaseLabel } from '@components/ReleaseLabel'import { TextInput } from '@components/TextInput'import { useToast } from '@components/Toast'import { IconCopy, IconRefresh } from '@components/icons'@@ -39,7 +40,6 @@ import {import type { DesktopEnvironmentResponse } from '@/app/types/api'import type { WorkflowApprovalMediumAccount } from '@/app/types/approvalChannels'import type { Me } from '@/app/types/profile'-import packageJson from '../../package.json'import { SettingsChannelSection } from './SettingsChannelSection'import { TelegramVerificationPanel } from './TelegramVerificationPanel'import { EMAIL_CHANNEL_SECTION, PROFILE_SOCIAL_CHANNEL_TABS } from './constants'@@ -341,7 +341,7 @@ export function SettingsContent({<div><p className="eyebrow">Profile settings</p><h1 className="page-title">Settings</h1>- <div className="small-plus muted">Version {packageJson.version}</div>+ <ReleaseLabel className="small-plus muted" /><div className="small-plus muted">{me ? `Signed in as ${me.email}` : 'Loading user session'}</div>diff --git a/profile-ui/app/types/api.ts b/profile-ui/app/types/api.tsindex 12d661b0e..da8d19bc4 100644--- a/profile-ui/app/types/api.ts+++ b/profile-ui/app/types/api.ts@@ -42,6 +42,16 @@ export type DesktopEnvironmentResponse = {rpcProxyBaseUrl: string}+export type DesktopReleaseResponse = {+ releaseId: string+ externalRestApiVersion: string+ rpcProxyVersion: string+ desktopVersion: string+ minimumDesktopVersion: string+ releaseTag: string+ releaseUrl: string+}+export type PasswordLoginResponse = {me: {id: stringdiff --git a/profile-ui/lib/api.ts b/profile-ui/lib/api.tsindex dc01e2773..192c002c5 100644--- a/profile-ui/lib/api.ts+++ b/profile-ui/lib/api.ts@@ -10,6 +10,7 @@ import type {AcceptInvitationResponse,DesktopAuthorizationResponse,DesktopEnvironmentResponse,+ DesktopReleaseResponse,InvitationPreview,PasswordLoginResponse,} from '../app/types/api'@@ -343,6 +344,17 @@ export async function getDesktopEnvironment(): Promise<DesktopEnvironmentResponsreturn apiGet('/api/v1/desktop/environment') as Promise<DesktopEnvironmentResponse>}+// silentUnauthorized on purpose: the release identity only feeds a label, so a+// 401 here must not run the global auth handler and bounce the user to login.+// The page's own getMe() call owns that decision.+export async function getDesktopRelease(): Promise<DesktopReleaseResponse> {+ return apiGet(+ '/api/v1/desktop/release',+ {},+ { silentUnauthorized: true }+ ) as Promise<DesktopReleaseResponse>+}+export function getConfiguredExternalRestApiBaseUrl(): string {if (typeof window === 'undefined') return EXTERNAL_REST_API_BASE_URL.replace(/\/+$/, '')try {diff --git a/profile-ui/lib/releaseIdentity.ts b/profile-ui/lib/releaseIdentity.tsnew file mode 100644index 000000000..4b0a6ef23--- /dev/null+++ b/profile-ui/lib/releaseIdentity.ts@@ -0,0 +1,61 @@+'use client'++import { getDesktopRelease } from './api'++export type ReleaseIdentity = {+ releaseId: string+}++export type ReleaseIdentityFetcher = () => Promise<unknown>++// 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+// page. A failed read is deliberately NOT cached: the label is decoration, and+// pinning it to "unavailable" until the next full page load would be the wrong+// trade for one transient error.+let cachedIdentity: ReleaseIdentity | null = null+let inFlight: Promise<ReleaseIdentity | null> | null = null++export function normalizeReleaseIdentity(payload: unknown): ReleaseIdentity | null {+ if (!payload || typeof payload !== 'object') return null+ const releaseId = String((payload as { releaseId?: unknown }).releaseId ?? '').trim()+ return releaseId ? { releaseId } : null+}++export function formatReleaseLabel(releaseId: string | null, loading = false): string {+ if (releaseId) return `Release ${releaseId}`+ return loading ? 'Release ...' : 'Release unavailable'+}++export function readCachedReleaseIdentity(): ReleaseIdentity | null {+ return cachedIdentity+}++export function resetReleaseIdentityCache(): void {+ cachedIdentity = null+ inFlight = null+}++export async function loadReleaseIdentity(+ fetcher: ReleaseIdentityFetcher = getDesktopRelease+): Promise<ReleaseIdentity | null> {+ if (cachedIdentity) return cachedIdentity+ if (inFlight) return inFlight++ inFlight = (async () => {+ try {+ const identity = normalizeReleaseIdentity(await fetcher())+ if (identity) cachedIdentity = 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.+ return null+ } finally {+ inFlight = null+ }+ })()++ return inFlight+}diff --git a/profile-ui/package-lock.json b/profile-ui/package-lock.jsonindex 728838ce2..ee80888fa 100644--- a/profile-ui/package-lock.json+++ b/profile-ui/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-profile-ui",- "version": "0.1.120",+ "version": "0.1.121","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-profile-ui",- "version": "0.1.120",+ "version": "0.1.121","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.jsonindex a42c74fed..d13d230b7 100644--- a/profile-ui/package.json+++ b/profile-ui/package.json@@ -1,6 +1,6 @@{"name": "clerum-profile-ui",- "version": "0.1.120",+ "version": "0.1.121","private": true,"scripts": {"dev": "next dev",diff --git a/profile-ui/test/releaseIdentity.test.ts b/profile-ui/test/releaseIdentity.test.tsnew file mode 100644index 000000000..8ae2663b1--- /dev/null+++ b/profile-ui/test/releaseIdentity.test.ts@@ -0,0 +1,86 @@+import assert from 'node:assert/strict'+import test from 'node:test'+import {+ formatReleaseLabel,+ loadReleaseIdentity,+ normalizeReleaseIdentity,+ resetReleaseIdentityCache,+} from '../lib/releaseIdentity'++test('normalizeReleaseIdentity keeps a trimmed release id', () => {+ assert.deepEqual(normalizeReleaseIdentity({ releaseId: ' v0.6.0 ' }), { releaseId: 'v0.6.0' })+})++test('normalizeReleaseIdentity rejects payloads that carry no release id', () => {+ assert.equal(normalizeReleaseIdentity({ releaseId: ' ' }), null)+ assert.equal(normalizeReleaseIdentity({}), null)+ assert.equal(normalizeReleaseIdentity(null), null)+ assert.equal(normalizeReleaseIdentity('v0.6.0'), null)+})++test('formatReleaseLabel names the release once it is known', () => {+ assert.equal(formatReleaseLabel('v0.6.0'), 'Release v0.6.0')+})++test('formatReleaseLabel holds the line while the release is being read', () => {+ assert.equal(formatReleaseLabel(null, true), 'Release ...')+})++test('formatReleaseLabel says so when the release could not be read', () => {+ assert.equal(formatReleaseLabel(null, false), 'Release unavailable')+})++test('loadReleaseIdentity caches a resolved read for the page session', async () => {+ resetReleaseIdentityCache()+ let calls = 0+ const fetcher = async () => {+ calls += 1+ return { releaseId: 'v0.6.0' }+ }++ assert.deepEqual(await loadReleaseIdentity(fetcher), { releaseId: 'v0.6.0' })+ assert.deepEqual(await loadReleaseIdentity(fetcher), { releaseId: 'v0.6.0' })+ assert.equal(calls, 1)+})++test('loadReleaseIdentity shares one in-flight read between concurrent callers', async () => {+ resetReleaseIdentityCache()+ let calls = 0+ const fetcher = async () => {+ calls += 1+ return { releaseId: 'v0.6.0' }+ }++ const [first, second] = await Promise.all([+ loadReleaseIdentity(fetcher),+ loadReleaseIdentity(fetcher),+ ])+ assert.deepEqual(first, { releaseId: 'v0.6.0' })+ assert.deepEqual(second, { releaseId: 'v0.6.0' })+ assert.equal(calls, 1)+})++// A cached failure would pin the label to "unavailable" until the next full+// page load, which is the wrong trade for a read that is only decoration.+test('loadReleaseIdentity does not cache a failed read', async () => {+ resetReleaseIdentityCache()+ let calls = 0+ const fetcher = async () => {+ calls += 1+ if (calls === 1) throw new Error('503 Service Unavailable')+ return { releaseId: 'v0.6.0' }+ }++ assert.equal(await loadReleaseIdentity(fetcher), null)+ assert.deepEqual(await loadReleaseIdentity(fetcher), { releaseId: 'v0.6.0' })+ assert.equal(calls, 2)+})++test('loadReleaseIdentity swallows a rejected read instead of surfacing it', async () => {+ resetReleaseIdentityCache()+ const fetcher = async () => {+ throw new Error('401 Unauthorized')+ }++ assert.equal(await loadReleaseIdentity(fetcher), null)+})