Skip to content

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

TypeScript

fix(desktop): r3-l2 hide stale account link confirmations

Josué88a97d00ceaf
diff --git a/desktop-app/ui/src/App.tsx b/desktop-app/ui/src/App.tsx
index 1efd58154..149bd6f99 100644
--- a/desktop-app/ui/src/App.tsx
+++ b/desktop-app/ui/src/App.tsx
@@ -33,6 +33,7 @@ import {
deferPendingSandboxUiDeepLink,
enqueuePendingSandboxUiDeepLink,
failPendingSandboxUiDeepLink,
+ findPendingSandboxUiDeepLinkAwaitingConfirmation,
isPendingSandboxUiDeepLinkAwaitingConfirmation,
isPendingSandboxUiDeepLinkStale,
removePendingSandboxUiDeepLink,
@@ -840,19 +841,20 @@ export function App() {
appNotificationDrawerOpen ? 'notification-drawer-open' : 'notification-drawer-closed'
}`
- const pendingSandboxUiConfirmation = vm.authenticatedPrincipalIdentity
- ? pendingSandboxUiDeepLinks.find(item =>
- isPendingSandboxUiDeepLinkAwaitingConfirmation(item, vm.authenticatedPrincipalIdentity)
- )
- : null
+ const pendingSandboxUiConfirmation =
+ findPendingSandboxUiDeepLinkAwaitingConfirmation(
+ pendingSandboxUiDeepLinks,
+ vm.authenticatedPrincipalIdentity
+ ) ?? null
const failedSandboxUiDeepLink = vm.authenticatedPrincipalIdentity
? pendingSandboxUiDeepLinks.find(item => item.failedMessage)
: null
const handleConfirmSandboxUiDeepLink = React.useCallback(() => {
const identity = vm.authenticatedPrincipalIdentity
- const pending = pendingSandboxUiDeepLinksRef.current.find(item =>
- identity ? isPendingSandboxUiDeepLinkAwaitingConfirmation(item, identity) : false
+ const pending = findPendingSandboxUiDeepLinkAwaitingConfirmation(
+ pendingSandboxUiDeepLinksRef.current,
+ identity
)
if (!identity || !pending) return
const next = confirmPendingSandboxUiDeepLink(
@@ -865,8 +867,9 @@ export function App() {
const handleDismissSandboxUiDeepLink = React.useCallback(() => {
const identity = vm.authenticatedPrincipalIdentity
- const pending = pendingSandboxUiDeepLinksRef.current.find(item =>
- identity ? isPendingSandboxUiDeepLinkAwaitingConfirmation(item, identity) : false
+ const pending = findPendingSandboxUiDeepLinkAwaitingConfirmation(
+ pendingSandboxUiDeepLinksRef.current,
+ identity
)
if (!pending) return
void acknowledgeSandboxUiDeepLink(pending.link.id)
diff --git a/desktop-app/ui/src/__tests__/App.deepLinks.test.tsx b/desktop-app/ui/src/__tests__/App.deepLinks.test.tsx
index 5ad5a6c31..64e5e7a61 100644
--- a/desktop-app/ui/src/__tests__/App.deepLinks.test.tsx
+++ b/desktop-app/ui/src/__tests__/App.deepLinks.test.tsx
@@ -7,6 +7,7 @@ import { App } from '@/App'
import type { SandboxUiDeepLinkEnvelope } from '@/App.types'
const confirmDialogHarness = vi.hoisted(() => ({
+ rendered: vi.fn(),
props: null as null | {
title: string
onCancel: () => void
@@ -44,6 +45,7 @@ vi.mock('@components/BootSplash', () => ({ BootSplash: () => null }))
vi.mock('@components/Common', () => ({ Button: () => null, ToastStack: () => null }))
vi.mock('@components/ConfirmDialog', () => ({
ConfirmDialog: (props: { title: string; onCancel: () => void; onConfirm: () => void }) => {
+ confirmDialogHarness.rendered(props)
confirmDialogHarness.props = props
return null
},
@@ -351,13 +353,15 @@ describe('App deep-link orchestration', () => {
expect(currentController.handleNavSelect).toHaveBeenCalledTimes(1)
})
- it('purges user A links synchronously before user B can process them', async () => {
+ it('never presents a user A link after user B becomes authenticated', async () => {
const { rerender } = render(<App />)
await waitFor(() => expect(emitDeepLink).not.toBeNull())
act(() => {
- emitDeepLink?.({ id: 1, appRef: 'ns/app', teamId: 'team-a' })
+ emitDeepLink?.({ id: 1, appRef: 'ns/user-a-app', teamId: 'team-a' })
})
+ await waitFor(() => expect(confirmDialogHarness.props?.title).toBe('Open app link?'))
+ confirmDialogHarness.rendered.mockClear()
currentController = makeController({
initialExperienceLoading: false,
@@ -375,9 +379,18 @@ describe('App deep-link orchestration', () => {
})
rerender(<App />)
+ expect(confirmDialogHarness.rendered).not.toHaveBeenCalled()
await waitFor(() => expect(clearPendingDeepLinks).toHaveBeenCalledOnce())
expect(currentController.handleEnsureTeamContext).not.toHaveBeenCalled()
expect(acknowledgeDeepLink).not.toHaveBeenCalled()
+
+ act(() => {
+ emitDeepLink?.({ id: 2, appRef: 'ns/user-b-app', teamId: 'team-b' })
+ })
+ await waitFor(() => expect(confirmDialogHarness.rendered).toHaveBeenCalledOnce())
+ expect(confirmDialogHarness.props?.title).toBe('Open app link?')
+ expect(currentController.handleNavSelect).not.toHaveBeenCalledWith(DESKTOP_ROUTES.apps)
+ expect(acknowledgeDeepLink).not.toHaveBeenCalled()
})
it('drops a stale cold-list response after the authenticated identity changes', async () => {
diff --git a/desktop-app/ui/src/lib/__tests__/sandboxUiDeepLinkState.test.ts b/desktop-app/ui/src/lib/__tests__/sandboxUiDeepLinkState.test.ts
index 2e2a61a9f..c5cd5f44d 100644
--- a/desktop-app/ui/src/lib/__tests__/sandboxUiDeepLinkState.test.ts
+++ b/desktop-app/ui/src/lib/__tests__/sandboxUiDeepLinkState.test.ts
@@ -10,6 +10,7 @@ import {
deferPendingSandboxUiDeepLink,
enqueuePendingSandboxUiDeepLink,
failPendingSandboxUiDeepLink,
+ findPendingSandboxUiDeepLinkAwaitingConfirmation,
isPendingSandboxUiDeepLinkAwaitingConfirmation,
isPendingSandboxUiDeepLinkStale,
nextSandboxUiDeepLinkRetryDelayMs,
@@ -238,6 +239,26 @@ describe('pending sandbox UI deep-link state', () => {
expect(isPendingSandboxUiDeepLinkStale(pending[0]!, 'user-b')).toBe(true)
})
+ it('selects confirmation links only for the current authenticated identity', () => {
+ const userALink = enqueuePendingSandboxUiDeepLink(
+ [],
+ { id: 1, appRef: 'ns/user-a-app' },
+ null,
+ 'user-a'
+ )
+ const withUserBLink = enqueuePendingSandboxUiDeepLink(
+ userALink,
+ { id: 2, appRef: 'ns/user-b-app' },
+ null,
+ 'user-b'
+ )
+
+ expect(findPendingSandboxUiDeepLinkAwaitingConfirmation(userALink, 'user-b')).toBeUndefined()
+ expect(
+ findPendingSandboxUiDeepLinkAwaitingConfirmation(withUserBLink, 'user-b')?.link.appRef
+ ).toBe('ns/user-b-app')
+ })
+
it('tracks bounded retry delays and explicit failed state', () => {
let pending = enqueuePendingSandboxUiDeepLink([], { id: 1, appRef: 'ns/app' }, null, 'user-a')
pending = deferPendingSandboxUiDeepLink(pending, 1, 10_000)
diff --git a/desktop-app/ui/src/lib/sandboxUiDeepLinkState.ts b/desktop-app/ui/src/lib/sandboxUiDeepLinkState.ts
index 983373fad..ef554d14b 100644
--- a/desktop-app/ui/src/lib/sandboxUiDeepLinkState.ts
+++ b/desktop-app/ui/src/lib/sandboxUiDeepLinkState.ts
@@ -55,6 +55,18 @@ export function isPendingSandboxUiDeepLinkStale(
return Boolean(pending.confirmedIdentity && pending.confirmedIdentity !== currentIdentity)
}
+export function findPendingSandboxUiDeepLinkAwaitingConfirmation(
+ current: PendingSandboxUiDeepLink[],
+ currentIdentity: string | null
+): PendingSandboxUiDeepLink | undefined {
+ if (!currentIdentity) return undefined
+ return current.find(
+ item =>
+ !isPendingSandboxUiDeepLinkStale(item, currentIdentity) &&
+ isPendingSandboxUiDeepLinkAwaitingConfirmation(item, currentIdentity)
+ )
+}
+
export function confirmPendingSandboxUiDeepLink(
current: PendingSandboxUiDeepLink[],
linkId: number,