Skip to content

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

TypeScript

fix(profile-ui): [R5-M2] gate desktop environment handoffs

Josué2d9f0fe0be46
diff --git a/.github/workflows/build-publish.yml b/.github/workflows/build-publish.yml
index c0e860060..0e2ab4df0 100644
--- a/.github/workflows/build-publish.yml
+++ b/.github/workflows/build-publish.yml
@@ -387,6 +387,8 @@ jobs:
MATRIX_PATH: ${{ matrix.path }}
MATRIX_DOCKERFILE: ${{ matrix.dockerfile }}
MATRIX_ROOTED: ${{ matrix.rooted }}
+ MATRIX_IMAGE: ${{ matrix.image }}
+ PROFILE_DESKTOP_HANDOFF_ENABLED: ${{ vars.PROFILE_DESKTOP_HANDOFF_ENABLED }}
run: |
# Rooted services COPY from sibling directories (packages/*) so their
# Docker build context must be the repo root and the Dockerfile path
@@ -399,6 +401,15 @@ jobs:
echo "file=$MATRIX_PATH/${MATRIX_DOCKERFILE:-Dockerfile}" >> "$GITHUB_OUTPUT"
fi
+ if [ "$MATRIX_IMAGE" = "profile-ui" ]; then
+ handoff_enabled="${PROFILE_DESKTOP_HANDOFF_ENABLED:-false}"
+ case "$handoff_enabled" in
+ true|false) ;;
+ *) echo "PROFILE_DESKTOP_HANDOFF_ENABLED must be true or false" >&2; exit 1 ;;
+ esac
+ echo "build_args=PROFILE_DESKTOP_HANDOFF_ENABLED=$handoff_enabled" >> "$GITHUB_OUTPUT"
+ fi
+
- name: Build and push by digest
if: ${{ matrix.changed == 'true' || needs.detect.outputs.force_all == 'true' }}
id: build
@@ -406,6 +417,7 @@ jobs:
with:
context: ${{ steps.buildargs.outputs.context }}
file: ${{ steps.buildargs.outputs.file }}
+ build-args: ${{ steps.buildargs.outputs.build_args }}
platforms: linux/${{ matrix.arch }}
# Attestations are disabled per-leg. Provenance attestations don't
# push cleanly in push-by-digest mode (they need a repo:tag target,
diff --git a/profile-ui/.env.example b/profile-ui/.env.example
index f278f8542..9ea1af1c2 100644
--- a/profile-ui/.env.example
+++ b/profile-ui/.env.example
@@ -1,2 +1,3 @@
EXTERNAL_REST_API_INTERNAL_URL=http://localhost:8091
NEXT_PUBLIC_EXTERNAL_REST_API_BASE_URL=/external-rest-api
+NEXT_PUBLIC_PROFILE_DESKTOP_HANDOFF_ENABLED=false
diff --git a/profile-ui/Dockerfile b/profile-ui/Dockerfile
index 2eafd399c..d5257a411 100644
--- a/profile-ui/Dockerfile
+++ b/profile-ui/Dockerfile
@@ -1,4 +1,6 @@
FROM node:24-alpine AS builder
+ARG PROFILE_DESKTOP_HANDOFF_ENABLED=false
+ENV NEXT_PUBLIC_PROFILE_DESKTOP_HANDOFF_ENABLED=${PROFILE_DESKTOP_HANDOFF_ENABLED}
WORKDIR /app
COPY packages/desktop-app-links ./packages/desktop-app-links
diff --git a/profile-ui/README.md b/profile-ui/README.md
index 5dc29fc67..c3cc17bff 100644
--- a/profile-ui/README.md
+++ b/profile-ui/README.md
@@ -18,8 +18,15 @@ See `.env.example`.
Important variables:
- `NEXT_PUBLIC_EXTERNAL_REST_API_BASE_URL`
+- `NEXT_PUBLIC_PROFILE_DESKTOP_HANDOFF_ENABLED` (build-time; defaults to `false`)
- `EXTERNAL_REST_API_INTERNAL_URL` (server-side proxy target)
+The Profile-to-Desktop environment handoff is disabled by default to protect older
+Desktop clients from ambiguous REST-only links. Enable it only after the updated
+Desktop consumer is released and operators have verified that older supported
+clients are no longer in use. Image builds can set the repository variable
+`PROFILE_DESKTOP_HANDOFF_ENABLED=true`; unset or `false` keeps the handoff disabled.
+
## Local
```bash
diff --git a/profile-ui/app/components/__tests__/ProfilePortalHome.test.tsx b/profile-ui/app/components/__tests__/ProfilePortalHome.test.tsx
index af7282451..f87cd1918 100644
--- a/profile-ui/app/components/__tests__/ProfilePortalHome.test.tsx
+++ b/profile-ui/app/components/__tests__/ProfilePortalHome.test.tsx
@@ -46,9 +46,13 @@ vi.mock('next/link', () => ({
beforeEach(() => {
api.getDesktopEnvironment.mockReset()
api.getDesktopEnvironment.mockResolvedValue(desktopEnvironment)
+ vi.stubEnv('NEXT_PUBLIC_PROFILE_DESKTOP_HANDOFF_ENABLED', 'true')
})
-afterEach(cleanup)
+afterEach(() => {
+ cleanup()
+ vi.unstubAllEnvs()
+})
describe('Profile Portal home desktop app link', () => {
it('keeps the welcome, portal prompt, and account summary in three cards', () => {
@@ -63,6 +67,18 @@ describe('Profile Portal home desktop app link', () => {
expect(screen.getByText('Profile Portal', { selector: 'strong' })).toBeInTheDocument()
})
+ it('does not discover or link a Desktop environment while handoffs are disabled', () => {
+ vi.stubEnv('NEXT_PUBLIC_PROFILE_DESKTOP_HANDOFF_ENABLED', 'false')
+
+ render(<Page />)
+
+ expect(api.getDesktopEnvironment).not.toHaveBeenCalled()
+ expect(screen.getByRole('status')).toHaveTextContent(
+ 'Automatic Desktop setup is not enabled yet.'
+ )
+ expect(screen.queryByRole('link', { name: 'Open Desktop App' })).not.toBeInTheDocument()
+ })
+
it('shows a loading status while desktop setup availability is checked', () => {
api.getDesktopEnvironment.mockReturnValue(new Promise(() => {}))
diff --git a/profile-ui/app/components/__tests__/SettingsContent.test.tsx b/profile-ui/app/components/__tests__/SettingsContent.test.tsx
index d0a547d0f..f489029a1 100644
--- a/profile-ui/app/components/__tests__/SettingsContent.test.tsx
+++ b/profile-ui/app/components/__tests__/SettingsContent.test.tsx
@@ -15,6 +15,7 @@ const mocks = vi.hoisted(() => ({
getConfiguredExternalRestApiBaseUrl: vi.fn(),
getDesktopEnvironment: vi.fn(),
getMe: vi.fn(),
+ isDesktopEnvironmentHandoffEnabled: vi.fn(),
isSilentApiError: vi.fn(),
listWorkflowApprovalMediums: vi.fn(),
logout: vi.fn(),
@@ -109,6 +110,7 @@ vi.mock('@lib/approvalChannels', () => ({
vi.mock('@lib/desktopAppLinks', () => ({
buildDesktopEnvironmentLink: mocks.buildDesktopEnvironmentLink,
+ isDesktopEnvironmentHandoffEnabled: mocks.isDesktopEnvironmentHandoffEnabled,
navigateToDesktopApp: mocks.navigateToDesktopApp,
}))
@@ -122,6 +124,7 @@ beforeEach(() => {
mocks.getConfiguredExternalRestApiBaseUrl.mockReturnValue('https://api.example.com')
mocks.getDesktopEnvironment.mockResolvedValue(desktopEnvironment)
mocks.getMe.mockResolvedValue(currentUser)
+ mocks.isDesktopEnvironmentHandoffEnabled.mockReturnValue(true)
mocks.isSilentApiError.mockReturnValue(false)
mocks.listWorkflowApprovalMediums.mockResolvedValue([])
mocks.refreshApprovalTargets.mockResolvedValue([])
@@ -151,4 +154,21 @@ describe('Settings desktop setup handoff', () => {
expect(mocks.buildDesktopEnvironmentLink).toHaveBeenCalledWith(desktopEnvironment)
expect(mocks.navigateToDesktopApp).toHaveBeenCalledWith(desktopHref)
})
+
+ it('keeps manual REST setup available while automatic handoff is disabled', async () => {
+ mocks.isDesktopEnvironmentHandoffEnabled.mockReturnValue(false)
+
+ render(<SettingsContent activeSettingsTab="profile" activeSocialTab="telegram" />)
+
+ fireEvent.click(await screen.findByRole('button', { name: 'Setup desktop app' }))
+
+ const dialog = await screen.findByRole('dialog', { name: 'Setup desktop app' })
+ expect(
+ within(dialog).getByText(/Automatic Desktop handoff is temporarily unavailable/)
+ ).toBeInTheDocument()
+ expect(
+ within(dialog).queryByRole('button', { name: 'Open desktop app and setup' })
+ ).not.toBeInTheDocument()
+ expect(within(dialog).getByRole('button', { name: 'Copy External REST API URL' })).toBeEnabled()
+ })
})
diff --git a/profile-ui/app/page.tsx b/profile-ui/app/page.tsx
index beff7816a..ff27b6a6f 100644
--- a/profile-ui/app/page.tsx
+++ b/profile-ui/app/page.tsx
@@ -7,17 +7,25 @@ import { AuthGate } from '@components/AuthGate'
import { IconExternalLink } from '@components/icons'
import { PROFILE_ROUTES } from '@constants/routes'
import { getDesktopEnvironment } from '@lib/api'
-import { buildDesktopEnvironmentLink } from '@lib/desktopAppLinks'
+import {
+ buildDesktopEnvironmentLink,
+ isDesktopEnvironmentHandoffEnabled,
+} from '@lib/desktopAppLinks'
function HomeContent() {
const { authState } = useAuth()
const me = authState.me
const displayName = me?.profile?.displayName || me?.name || me?.email || 'there'
+ const desktopHandoffEnabled = isDesktopEnvironmentHandoffEnabled()
const [desktopAppLink, setDesktopAppLink] = useState<
- { state: 'loading' } | { state: 'ready'; href: string } | { state: 'unavailable' }
- >({ state: 'loading' })
+ | { state: 'loading' }
+ | { state: 'ready'; href: string }
+ | { state: 'unavailable' }
+ | { state: 'disabled' }
+ >(() => (desktopHandoffEnabled ? { state: 'loading' } : { state: 'disabled' }))
useEffect(() => {
+ if (!desktopHandoffEnabled) return
let isCurrent = true
void getDesktopEnvironment()
.then(environment => {
@@ -32,7 +40,7 @@ function HomeContent() {
return () => {
isCurrent = false
}
- }, [])
+ }, [desktopHandoffEnabled])
return (
<section className="profile-page">
@@ -51,6 +59,8 @@ function HomeContent() {
<p className="body-copy" role="status" aria-live="polite" aria-atomic="true">
{desktopAppLink.state === 'loading' ? (
'Checking desktop app setup…'
+ ) : desktopAppLink.state === 'disabled' ? (
+ 'Automatic Desktop setup is not enabled yet. You can copy the REST API URL in Settings.'
) : desktopAppLink.state === 'unavailable' ? (
<>
Desktop app setup is unavailable right now. Visit{' '}
diff --git a/profile-ui/app/settings/SettingsContent.tsx b/profile-ui/app/settings/SettingsContent.tsx
index 714f758af..698cf94a1 100644
--- a/profile-ui/app/settings/SettingsContent.tsx
+++ b/profile-ui/app/settings/SettingsContent.tsx
@@ -28,7 +28,11 @@ import {
disconnectWorkflowApprovalMedium,
listWorkflowApprovalMediums,
} from '@lib/approvalChannels'
-import { buildDesktopEnvironmentLink, navigateToDesktopApp } from '@lib/desktopAppLinks'
+import {
+ buildDesktopEnvironmentLink,
+ isDesktopEnvironmentHandoffEnabled,
+ navigateToDesktopApp,
+} from '@lib/desktopAppLinks'
import {
EMPTY_PROFILE_CHANNELS,
addDraftRow,
@@ -601,6 +605,7 @@ export function SettingsContent({
{showDesktopSetupModal ? (
<DesktopSetupModal
busy={desktopSetupBusy}
+ handoffEnabled={isDesktopEnvironmentHandoffEnabled()}
environment={desktopEnvironment}
externalRestApiBaseUrl={desktopSetupExternalRestApiBaseUrl}
onClose={() => setShowDesktopSetupModal(false)}
@@ -657,6 +662,7 @@ function ReadonlyChannelSection({
function DesktopSetupModal({
busy,
+ handoffEnabled,
environment,
externalRestApiBaseUrl,
onClose,
@@ -664,13 +670,14 @@ function DesktopSetupModal({
onOpenDesktop,
}: {
busy: boolean
+ handoffEnabled: boolean
environment: DesktopEnvironmentResponse | null
externalRestApiBaseUrl: string
onClose: () => void
onCopy: () => void
onOpenDesktop: () => void
}) {
- const canOpenDesktop = Boolean(environment?.externalRestApiBaseUrl)
+ const canOpenDesktop = handoffEnabled && Boolean(environment?.externalRestApiBaseUrl)
return (
<div
@@ -714,11 +721,19 @@ function DesktopSetupModal({
</Button>
</div>
</div>
- <div className="settings-desktop-setup-actions">
- <Button onClick={onOpenDesktop} disabled={busy || !canOpenDesktop}>
- Open desktop app and setup
- </Button>
- </div>
+ {!handoffEnabled ? (
+ <p className="settings-help">
+ Automatic Desktop handoff is temporarily unavailable. You can copy this API URL and
+ add it in Desktop.
+ </p>
+ ) : null}
+ {handoffEnabled ? (
+ <div className="settings-desktop-setup-actions">
+ <Button onClick={onOpenDesktop} disabled={busy || !canOpenDesktop}>
+ Open desktop app and setup
+ </Button>
+ </div>
+ ) : null}
</div>
</section>
</div>
diff --git a/profile-ui/lib/desktopAppLinks.ts b/profile-ui/lib/desktopAppLinks.ts
index 1247d8a06..9c2a9691d 100644
--- a/profile-ui/lib/desktopAppLinks.ts
+++ b/profile-ui/lib/desktopAppLinks.ts
@@ -7,10 +7,14 @@ import type { DesktopEnvironmentResponse } from '@/app/types/api'
const SCRIPT_NONCE_PATTERN = /^[A-Za-z0-9+/_-]+={0,2}$/
+export function isDesktopEnvironmentHandoffEnabled(): boolean {
+ return process.env.NEXT_PUBLIC_PROFILE_DESKTOP_HANDOFF_ENABLED === 'true'
+}
+
export function buildDesktopEnvironmentLink(
environment: DesktopEnvironmentResponse | null | undefined
): string | null {
- if (!environment?.externalRestApiBaseUrl) return null
+ if (!isDesktopEnvironmentHandoffEnabled() || !environment?.externalRestApiBaseUrl) return null
const params = new URLSearchParams({
externalRestApiBaseUrl: environment.externalRestApiBaseUrl,
tenantName: environment.appName || 'Evenfire',
diff --git a/profile-ui/package-lock.json b/profile-ui/package-lock.json
index 21e2516b4..99d30b777 100644
--- a/profile-ui/package-lock.json
+++ b/profile-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-profile-ui",
- "version": "0.1.167",
+ "version": "0.1.168",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-profile-ui",
- "version": "0.1.167",
+ "version": "0.1.168",
"dependencies": {
"@clerum/desktop-app-links": "file:../packages/desktop-app-links",
"@clerum/frontend-components": "file:../packages/frontend-components",
diff --git a/profile-ui/package.json b/profile-ui/package.json
index a7555ae59..0556dd854 100644
--- a/profile-ui/package.json
+++ b/profile-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-profile-ui",
- "version": "0.1.167",
+ "version": "0.1.168",
"private": true,
"scripts": {
"dev": "next dev",
diff --git a/profile-ui/test/desktopAppLinks.test.ts b/profile-ui/test/desktopAppLinks.test.ts
index 0dbbc5e54..be9750469 100644
--- a/profile-ui/test/desktopAppLinks.test.ts
+++ b/profile-ui/test/desktopAppLinks.test.ts
@@ -8,7 +8,31 @@ import {
navigateToDesktopApp,
} from '../lib/desktopAppLinks'
+test('buildDesktopEnvironmentLink is disabled unless the rollout flag is enabled', () => {
+ const original = process.env.NEXT_PUBLIC_PROFILE_DESKTOP_HANDOFF_ENABLED
+ const environment = {
+ externalRestApiBaseUrl: 'https://api.example.com',
+ rpcProxyBaseUrl: '',
+ appName: 'Example tenant',
+ }
+
+ try {
+ delete process.env.NEXT_PUBLIC_PROFILE_DESKTOP_HANDOFF_ENABLED
+ assert.equal(buildDesktopEnvironmentLink(environment), null)
+
+ process.env.NEXT_PUBLIC_PROFILE_DESKTOP_HANDOFF_ENABLED = 'false'
+ assert.equal(buildDesktopEnvironmentLink(environment), null)
+
+ process.env.NEXT_PUBLIC_PROFILE_DESKTOP_HANDOFF_ENABLED = 'true'
+ assert.ok(buildDesktopEnvironmentLink(environment))
+ } finally {
+ if (original === undefined) delete process.env.NEXT_PUBLIC_PROFILE_DESKTOP_HANDOFF_ENABLED
+ else process.env.NEXT_PUBLIC_PROFILE_DESKTOP_HANDOFF_ENABLED = original
+ }
+})
+
test('buildDesktopEnvironmentLink defaults the tenant name to Evenfire', () => {
+ process.env.NEXT_PUBLIC_PROFILE_DESKTOP_HANDOFF_ENABLED = 'true'
const link = buildDesktopEnvironmentLink({
externalRestApiBaseUrl: 'https://api.example.com',
rpcProxyBaseUrl: '',
@@ -21,6 +45,7 @@ test('buildDesktopEnvironmentLink defaults the tenant name to Evenfire', () => {
})
test('buildDesktopEnvironmentLink does not include the RPC proxy URL', () => {
+ process.env.NEXT_PUBLIC_PROFILE_DESKTOP_HANDOFF_ENABLED = 'true'
const link = buildDesktopEnvironmentLink({
externalRestApiBaseUrl: 'https://api.example.com',
rpcProxyBaseUrl: 'https://rpc.example.com',