Skip to content

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

TypeScript

test(desktop-app): m4 cover Retry branch of the deep-link failure dialog

Diego Zacarias7ea7abcc8acb
diff --git a/desktop-app/ui/src/__tests__/App.deepLinks.test.tsx b/desktop-app/ui/src/__tests__/App.deepLinks.test.tsx
index 4b36fa04e..4f2659f79 100644
--- a/desktop-app/ui/src/__tests__/App.deepLinks.test.tsx
+++ b/desktop-app/ui/src/__tests__/App.deepLinks.test.tsx
@@ -1,4 +1,5 @@
// @vitest-environment jsdom
+import { useEffect } from 'react'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { act, render, waitFor } from '@testing-library/react'
import { DESKTOP_ROUTES } from '@constants/navigation'
@@ -9,6 +10,10 @@ import type { DesktopCommandId } from '../../../src/desktopCommands'
const confirmDialogHarness = vi.hoisted(() => ({
rendered: vi.fn(),
+ // Tracks whether a deep-link ConfirmDialog is actually on screen right now,
+ // independently of the overlay signal, so the signal<->dialog invariant can
+ // be asserted without reading a stale `props` snapshot after unmount.
+ mounted: false,
props: null as null | {
title: string
onCancel: () => void
@@ -91,6 +96,12 @@ vi.mock('@components/ConfirmDialog', () => ({
ConfirmDialog: (props: { title: string; onCancel: () => void; onConfirm: () => void }) => {
confirmDialogHarness.rendered(props)
confirmDialogHarness.props = props
+ useEffect(() => {
+ confirmDialogHarness.mounted = true
+ return () => {
+ confirmDialogHarness.mounted = false
+ }
+ }, [])
return null
},
}))
@@ -225,6 +236,7 @@ describe('App deep-link orchestration', () => {
beforeEach(() => {
vi.clearAllMocks()
confirmDialogHarness.props = null
+ confirmDialogHarness.mounted = false
appHeaderHarness.props = null
chatLocalSearchHarness.rendered.mockReset()
commandPaletteHarness.props = null
@@ -688,6 +700,67 @@ describe('App deep-link orchestration', () => {
await waitFor(() => expect(sandboxUiPageHarness.props?.deepLinkShellOverlayOpen).toBe(false))
})
+ it('drops the overlay signal in lockstep with the dialog when Retry is chosen', async () => {
+ // T5: the deep-link overlay signal and the dialog derive from one App-level
+ // expression, so this pins that Retry (the failure dialog's onConfirm ->
+ // handleRetryFailedSandboxUiDeepLink) never leaves the embed hidden with a
+ // dialog still owning the screen, nor a dialog on screen with the embed
+ // shown. The invariant asserted: a mounted deep-link dialog implies the
+ // signal is raised, and once the signal drops no deep-link dialog is
+ // mounted. Retry is distinct from Dismiss here — it must not acknowledge
+ // the link, it re-drives the open.
+ vi.useFakeTimers({ shouldAdvanceTime: true })
+ const ensureTeamContext = vi.fn(async () => {
+ throw Object.assign(new Error('fetch failed'), { code: 'ECONNRESET' })
+ })
+ currentController = makeController({
+ initialExperienceLoading: false,
+ navItem: DESKTOP_ROUTES.apps,
+ handleEnsureTeamContext: ensureTeamContext,
+ })
+ render(<App />)
+ await waitFor(() => expect(emitDeepLink).not.toBeNull())
+
+ act(() => {
+ emitDeepLink?.({ id: 1, appRef: 'ns/app', teamId: 'team-b' })
+ })
+ await confirmPendingAppLink()
+
+ for (const delay of [1_000, 2_000, 4_000, 8_000, 15_000]) {
+ await act(async () => {
+ vi.advanceTimersByTime(delay)
+ await Promise.resolve()
+ })
+ }
+
+ // Failure dialog is up: a mounted deep-link dialog must keep the signal
+ // raised so the native WebContentsView does not paint over it.
+ await waitFor(() =>
+ expect(confirmDialogHarness.props?.title).toBe('App link could not be opened')
+ )
+ expect(confirmDialogHarness.mounted).toBe(true)
+ expect(sandboxUiPageHarness.props?.deepLinkShellOverlayOpen).toBe(true)
+
+ const ensureCallsBeforeRetry = ensureTeamContext.mock.calls.length
+
+ // Retry — the failure dialog's onConfirm, not onCancel.
+ await act(async () => {
+ confirmDialogHarness.props?.onConfirm()
+ await Promise.resolve()
+ })
+
+ // Retry clears the failure and re-drives the open in the same commit the
+ // predicates go null, so the dialog unmounts as the signal drops: there is
+ // no frame with a dialog mounted and the embed shown, and none with the
+ // embed hidden and no dialog. Retry never acknowledges (that is Dismiss).
+ await waitFor(() => expect(sandboxUiPageHarness.props?.deepLinkShellOverlayOpen).toBe(false))
+ expect(confirmDialogHarness.mounted).toBe(false)
+ expect(acknowledgeDeepLink).not.toHaveBeenCalled()
+ // The retry actually re-attempted the open (handleRetryFailedSandboxUiDeepLink
+ // ran), rather than just tearing the dialog down.
+ expect(ensureTeamContext.mock.calls.length).toBeGreaterThan(ensureCallsBeforeRetry)
+ })
+
it('does not duplicate an authenticated confirmation for the same link id', async () => {
currentController = makeController({ initialExperienceLoading: false })
listApps.mockResolvedValue({