Skip to content

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

TypeScript

fix(desktop): show a retryable error card when GFS discovery is rate limited

Alfredo Lopezbb62e229b418
diff --git a/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx b/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx
index fa30abe30..ef5b1a7e2 100644
--- a/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx
+++ b/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx
@@ -227,6 +227,7 @@ describe('useGfsBrowserController', () => {
cleanup()
lastHarnessQueryClient = null
vi.restoreAllMocks()
+ vi.useRealTimers()
})
it('resets visible GFS state when the authenticated session scope changes', async () => {
@@ -1000,6 +1001,65 @@ describe('useGfsBrowserController', () => {
expect(listAccessible).toHaveBeenCalledTimes(1)
})
+ it('suppresses the window-focus discovery refetch until the rate-limit window expires', async () => {
+ const listAccessible = vi.fn(async () => {
+ throw new Error(
+ "Error invoking remote method 'gfs:listAccessible': Error: 429 Too Many Requests: " +
+ 'Too Many Requests retryAfterSeconds=7'
+ )
+ })
+ Object.defineProperty(window, 'clerum', {
+ configurable: true,
+ value: {
+ gfs: {
+ listAccessible,
+ resolve: vi.fn(),
+ listChildren: vi.fn(async () => ({ items: [], nextCursor: null })),
+ affordances: vi.fn(async () => ({
+ held: [],
+ canDelegate: false,
+ grantableBits: [],
+ canCreateShare: false,
+ })),
+ },
+ },
+ })
+
+ render(<Probe />, { wrapper: Harness })
+ await waitFor(() =>
+ expect(screen.getByTestId('discovery-failure-kind').textContent).toBe('rate-limited')
+ )
+ expect(listAccessible).toHaveBeenCalledTimes(1)
+
+ // Fake only Date, and only after the waits above: the pause predicate reads
+ // Date.now(), while RTL's waitFor needs a real clock to time out rather
+ // than hang. vi.useFakeTimers seeds the fake clock from the real one, so
+ // the 7 s window opened a moment ago is still open here.
+ vi.useFakeTimers({ toFake: ['Date'] })
+ const pausedAt = Date.now()
+
+ await act(async () => {
+ focusManager.setFocused(false)
+ focusManager.setFocused(true)
+ })
+ expect(listAccessible).toHaveBeenCalledTimes(1)
+ // Witness: the controller is still mounted and still holding the verdict,
+ // so the unchanged count above is a suppressed refetch, not a dead tree.
+ expect(screen.getByTestId('discovery-failure-kind').textContent).toBe('rate-limited')
+
+ // Past the window, focus revalidates again. This is what makes the
+ // negative assertion above non-vacuous.
+ vi.setSystemTime(pausedAt + 8_000)
+ await act(async () => {
+ focusManager.setFocused(false)
+ focusManager.setFocused(true)
+ })
+ await act(async () => {
+ await new Promise(resolve => globalThis.setTimeout(resolve, 0))
+ })
+ expect(listAccessible).toHaveBeenCalledTimes(2)
+ })
+
it('reconciles the open folder after a move and feeds the returned version into follow-up actions', async () => {
const docsId = '11111111-1111-1111-1111-111111111111'
const rootId = '00000000-0000-0000-0000-00000000000a'
diff --git a/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts b/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts
index 006191a64..a7324e24f 100644
--- a/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts
+++ b/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts
@@ -248,6 +248,20 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {
}
}, [queryClient, sessionScope])
+ // Epoch (ms) before which a focus-driven revalidation would only burn
+ // another slice of the rate-limit budget the server just refused. A ref,
+ // not state: the refetch predicates read it when focus fires, and mutating
+ // it must not re-render. 0 means "not paused".
+ const pausedUntilRef = useRef(0)
+ // TanStack 5 accepts `(query) => boolean | 'always'` here. It must return
+ // 'always' | false, never a boolean: under desktopQueryDefaults' staleTime
+ // of Infinity, `true` means "refetch if stale", which never happens — a
+ // boolean predicate would silently disable focus refetch altogether.
+ const refetchOnFocusUnlessPaused = useCallback(
+ (): 'always' | false => (Date.now() >= pausedUntilRef.current ? 'always' : false),
+ []
+ )
+
const accessibleQuery = useInfiniteQuery({
queryKey: desktopQueryKeys.gfsAccessible(sessionScope ?? 'anonymous', DRIVE),
queryFn: async ({ pageParam }): Promise<GfsAccessibleWirePage> => {
@@ -265,8 +279,9 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {
refetchOnMount: 'always',
// Grants are often made from another surface (control-ui, an operator,
// another user) while this window stays open; focusing the app must
- // surface the new shares without a hard reload.
- refetchOnWindowFocus: 'always',
+ // surface the new shares without a hard reload — unless the server just
+ // rate limited us, in which case focusing again only costs another 429.
+ refetchOnWindowFocus: refetchOnFocusUnlessPaused,
initialPageParam: undefined as string | undefined,
getNextPageParam: lastPage => lastPage.nextCursor ?? undefined,
})
@@ -300,7 +315,7 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {
// and window focus must revalidate — an Infinity-fresh cached listing
// otherwise hides new files until a hard app reload.
refetchOnMount: 'always',
- refetchOnWindowFocus: 'always',
+ refetchOnWindowFocus: refetchOnFocusUnlessPaused,
initialPageParam: undefined as string | undefined,
getNextPageParam: lastPage => lastPage.nextCursor ?? undefined,
})
@@ -633,6 +648,19 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {
: null,
[accessibleErrorMessage]
)
+ useEffect(() => {
+ pausedUntilRef.current =
+ discoveryFailure?.kind === 'rate-limited' && discoveryFailure.retryAfterSeconds !== null
+ ? Date.now() + discoveryFailure.retryAfterSeconds * 1000
+ : 0
+ }, [discoveryFailure])
+ // The page must not reach into the query object to retry. Clearing the pause
+ // here is deliberate: an explicit retry is the user's decision, and the
+ // countdown in the UI is what keeps them from spending the request early.
+ const retryDiscovery = useCallback(async () => {
+ pausedUntilRef.current = 0
+ await accessibleQuery.refetch()
+ }, [accessibleQuery])
const accessibleNotice =
sessionScope && !canListAccessibleResources
? 'Automatic GFS discovery is not available in this desktop runtime. You can still open any GFS link you have.'
@@ -875,6 +903,7 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {
accessibleError: accessibleNotice ? null : accessibleErrorMessage,
accessibleNotice,
discoveryFailure,
+ retryDiscovery,
openError,
resolving,
hasMore: Boolean(childrenQuery.hasNextPage),
diff --git a/desktop-app/ui/src/lib/__tests__/gfsGrantErrors.test.ts b/desktop-app/ui/src/lib/__tests__/gfsGrantErrors.test.ts
index 1a3407e3f..2b2adc298 100644
--- a/desktop-app/ui/src/lib/__tests__/gfsGrantErrors.test.ts
+++ b/desktop-app/ui/src/lib/__tests__/gfsGrantErrors.test.ts
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest'
-import { describeGfsGrantError } from '../gfsGrantErrors'
+import { describeGfsGrantError, describeGfsReadError } from '../gfsGrantErrors'
/**
* Pure presentation map for GFS grant-plane server verdicts. Codes arrive
@@ -113,3 +113,47 @@ describe('describeGfsGrantError', () => {
})
})
})
+
+/**
+ * Reads are a different plane from grants. The copy diverges because the user's
+ * next action diverges: a rate-limited grant means "stop changing permissions",
+ * a rate-limited read means "the file is fine, ask again in a moment".
+ */
+describe('describeGfsReadError', () => {
+ it('reports a rate-limited read as a read, with the server retry hint', () => {
+ const raw =
+ "Error invoking remote method 'gfs:download': Error: gfs download failed: 429: " +
+ 'Too Many Requests retryAfterSeconds=7'
+
+ expect(describeGfsReadError(new Error(raw))).toEqual({
+ code: 'rate_limited',
+ message: 'Too many file requests — try again in 7s.',
+ severity: 'error',
+ })
+ })
+
+ it('drops the countdown when the server sent no retry hint', () => {
+ expect(describeGfsReadError(new Error('gfs download failed: 429'))).toEqual({
+ code: 'rate_limited',
+ message: 'Too many file requests — try again shortly.',
+ severity: 'error',
+ })
+ })
+
+ it('never borrows the permission-plane copy for a read', () => {
+ const readMessage = describeGfsReadError(new Error('429 retryAfterSeconds=7')).message
+
+ expect(readMessage).not.toContain('permission changes')
+ // Witness: the rate-limit branch really ran, so the assertion above is
+ // about chosen copy and not about a message that never got classified.
+ expect(readMessage).toContain('7s')
+ })
+
+ it('passes a non-rate-limited read failure through verbatim', () => {
+ expect(describeGfsReadError(new Error('gfs download failed: 502'))).toEqual({
+ code: null,
+ message: 'gfs download failed: 502',
+ severity: 'error',
+ })
+ })
+})
diff --git a/desktop-app/ui/src/lib/gfsGrantErrors.ts b/desktop-app/ui/src/lib/gfsGrantErrors.ts
index 89ce09383..94277788f 100644
--- a/desktop-app/ui/src/lib/gfsGrantErrors.ts
+++ b/desktop-app/ui/src/lib/gfsGrantErrors.ts
@@ -48,10 +48,41 @@ export function parseRetryAfterSeconds(message: string): number | null {
return Number.isInteger(seconds) && seconds >= 0 ? seconds : null
}
+export function isRateLimited(message: string): boolean {
+ return /\b429\b/.test(message) || message.includes('rate_limited')
+}
+
+/**
+ * Read-plane counterpart of `describeGfsGrantError`.
+ *
+ * A read and a permission change fail under the same server budget but call for
+ * different words: "too many permission changes" tells a user who was only
+ * opening a file to stop doing something they never did. Only the rate limit is
+ * translated here — every other read failure keeps its raw message, because the
+ * grant-plane codes below describe an operation a read never performs.
+ */
+export function describeGfsReadError(error: unknown): GfsGrantErrorPresentation {
+ const raw = rawMessage(error)
+
+ if (isRateLimited(raw)) {
+ const retryAfterSeconds = parseRetryAfterSeconds(raw)
+ return {
+ code: 'rate_limited',
+ message:
+ retryAfterSeconds !== null
+ ? `Too many file requests — try again in ${retryAfterSeconds}s.`
+ : 'Too many file requests — try again shortly.',
+ severity: 'error',
+ }
+ }
+
+ return { code: null, message: raw || 'The file request failed.', severity: 'error' }
+}
+
export function describeGfsGrantError(error: unknown): GfsGrantErrorPresentation {
const raw = rawMessage(error)
- if (/\b429\b/.test(raw) || raw.includes('rate_limited')) {
+ if (isRateLimited(raw)) {
const retryAfterSeconds = parseRetryAfterSeconds(raw)
return {
code: 'rate_limited',
diff --git a/desktop-app/ui/src/pages/FilesPage.tsx b/desktop-app/ui/src/pages/FilesPage.tsx
index dbdc1d679..5aa0f94be 100644
--- a/desktop-app/ui/src/pages/FilesPage.tsx
+++ b/desktop-app/ui/src/pages/FilesPage.tsx
@@ -35,10 +35,14 @@ import {
IconUpload,
} from '@components/SidebarNav/icons'
import { desktopQueryKeys } from '@hooks/domain/queryKeys'
-import { type GfsCrumb, useGfsBrowserController } from '@hooks/domain/useGfsBrowserController'
+import {
+ type GfsCrumb,
+ type GfsDiscoveryFailure,
+ useGfsBrowserController,
+} from '@hooks/domain/useGfsBrowserController'
import { isEventFromNestedInteractive } from '@lib/clickableRowProps'
import { assertGfsFileUploadSize } from '@lib/gfsFileUpload'
-import { describeGfsGrantError } from '@lib/gfsGrantErrors'
+import { describeGfsGrantError, describeGfsReadError } from '@lib/gfsGrantErrors'
import { gfsImagePreviewMimeType } from '@lib/gfsImagePreview'
import { isGfsMarkdownPreviewFile } from '@lib/gfsMarkdownPreview'
import { gfsVideoPreviewMimeType } from '@lib/gfsVideoPreview'
@@ -208,6 +212,63 @@ function GfsInlineRename({
)
}
+/**
+ * Terminal state for a discovery attempt that the server refused.
+ *
+ * Before this existed the page had no way to say "the request was answered,
+ * and the answer was no": a rejected discovery left the loader spinning and
+ * the raw IPC string in a red banner. The countdown is the point — it is the
+ * server's own Retry-After, so the user waits the exact window instead of
+ * hammering a budget that is already exhausted.
+ */
+function GfsDiscoveryFailureCard({
+ failure,
+ onRetry,
+}: {
+ failure: GfsDiscoveryFailure
+ onRetry: () => void
+}) {
+ const [remainingSeconds, setRemainingSeconds] = useState(failure.retryAfterSeconds ?? 0)
+
+ useEffect(() => {
+ setRemainingSeconds(failure.retryAfterSeconds ?? 0)
+ }, [failure])
+
+ useEffect(() => {
+ if (remainingSeconds <= 0) return
+ const timer = setInterval(() => {
+ setRemainingSeconds(previous => (previous <= 1 ? 0 : previous - 1))
+ }, 1_000)
+ return () => clearInterval(timer)
+ }, [remainingSeconds])
+
+ return (
+ <>
+ <EmptyState
+ title={
+ failure.kind === 'rate-limited' ? 'Too many file requests' : 'Could not load your files'
+ }
+ body={
+ failure.kind === 'rate-limited'
+ ? 'File listing is temporarily rate limited. Evenfire will let you retry once the server’s own window closes.'
+ : failure.message
+ }
+ />
+ <div className="da-gfs-footer-actions">
+ {remainingSeconds > 0 ? (
+ <span className="muted">
+ Retry available in{' '}
+ <span data-testid="gfs-discovery-retry-seconds">{remainingSeconds}</span>s
+ </span>
+ ) : null}
+ <Button disabled={remainingSeconds > 0} onClick={onRetry} size="sm" variant="outline">
+ Retry file listing
+ </Button>
+ </div>
+ </>
+ )
+}
+
export function FilesPage({
pushToast,
pendingGfsUri,
@@ -568,10 +629,7 @@ export function FilesPage({
pushToast?.(`Downloaded ${name}`, 'success')
} catch (downloadError) {
if (failClosedOnAuthorizationError(downloadError)) return
- pushToast?.(
- downloadError instanceof Error ? downloadError.message : String(downloadError),
- 'error'
- )
+ pushToast?.(describeGfsReadError(downloadError).message, 'error')
}
}
@@ -1053,6 +1111,13 @@ export function FilesPage({
const visibleLoading =
ctrl.authorityPending || (currentIsFolder ? loading : !current ? loadingAccessible : false)
const visibleError = currentIsFolder ? error : !current ? accessibleError : null
+ // Scoped to the root view on purpose: `accessibleError` only reaches
+ // `visibleError` when there is no `current`, so the card replaces exactly the
+ // banner it suppresses and never hides a folder-listing error behind it.
+ const blockingDiscoveryFailure =
+ !current && ctrl.discoveryFailure && ctrl.discoveryFailure.kind !== 'unsupported'
+ ? ctrl.discoveryFailure
+ : null
const hasMoreVisible = currentIsFolder ? ctrl.hasMore : !current && ctrl.hasMoreAccessible
const loadingMoreVisible = currentIsFolder ? ctrl.isFetchingMore : ctrl.isFetchingMoreAccessible
@@ -1230,7 +1295,7 @@ export function FilesPage({
) : null}
{accessibleNotice ? <StatusBanner tone="info" text={accessibleNotice} /> : null}
- {visibleError && !accessRevoked ? (
+ {visibleError && !accessRevoked && !blockingDiscoveryFailure ? (
<StatusBanner tone="error" text={visibleError} />
) : null}
@@ -1246,6 +1311,13 @@ export function FilesPage({
</Button>
</div>
</>
+ ) : blockingDiscoveryFailure ? (
+ <GfsDiscoveryFailureCard
+ failure={blockingDiscoveryFailure}
+ onRetry={() => {
+ void ctrl.retryDiscovery()
+ }}
+ />
) : visibleLoading ? (
<div
className="da-gfs-loading"
diff --git a/desktop-app/ui/src/pages/__tests__/FilesPage.discoverySeam.test.tsx b/desktop-app/ui/src/pages/__tests__/FilesPage.discoverySeam.test.tsx
new file mode 100644
index 000000000..de2569ab3
--- /dev/null
+++ b/desktop-app/ui/src/pages/__tests__/FilesPage.discoverySeam.test.tsx
@@ -0,0 +1,103 @@
+// @vitest-environment jsdom
+import { afterEach, describe, expect, it, vi } from 'vitest'
+import { AuthContext, type AuthContextValue } from '@contexts/AuthContext'
+import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
+import { cleanup, render, screen, waitFor } from '@testing-library/react'
+import { FilesPage } from '../FilesPage'
+
+/**
+ * The controller/page seam, which nothing else covers.
+ *
+ * `FilesPage.test.tsx` mocks `useGfsBrowserController` at module level, so
+ * every test in it renders the page against a hand-written controller object.
+ * That proves the page renders a `discoveryFailure` it was handed, and the
+ * controller suite proves the controller emits one — but nothing proves the
+ * two are the same field with the same shape. Rename it on one side and both
+ * suites stay green while the user still waits on "Loading files…" forever,
+ * which is the exact bug this PR exists to fix.
+ *
+ * This file therefore renders `FilesPage` against the REAL controller and
+ * fakes only `window.clerum.gfs`, the process boundary.
+ */
+
+const RATE_LIMITED_IPC_MESSAGE =
+ "Error invoking remote method 'gfs:listAccessible': Error: 429 Too Many Requests: " +
+ 'Too Many Requests retryAfterSeconds=7'
+
+// The controller reads exactly three fields off this context — isAuthenticated,
+// me and runtimeConfigState — and FilesPage reads none. The cast keeps the
+// double to those three rather than restating forty unrelated auth-screen
+// fields that no code under test touches.
+const authValue = {
+ isAuthenticated: true,
+ me: {
+ id: 'user-a',
+ email: '[email protected]',
+ name: 'User A',
+ picture: null,
+ teamId: 'team-a',
+ teamName: 'Team A',
+ role: 'member' as const,
+ },
+ runtimeConfigState: null,
+} as unknown as AuthContextValue
+
+function renderFilesPage() {
+ const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } })
+ return render(
+ <AuthContext.Provider value={authValue}>
+ <QueryClientProvider client={queryClient}>
+ <FilesPage />
+ </QueryClientProvider>
+ </AuthContext.Provider>
+ )
+}
+
+describe('FilesPage against the real GFS browser controller', () => {
+ afterEach(() => {
+ cleanup()
+ vi.restoreAllMocks()
+ })
+
+ it('turns a rate-limited discovery rejection into a retryable card, not an endless loader', async () => {
+ const listAccessible = vi.fn(async () => {
+ throw new Error(RATE_LIMITED_IPC_MESSAGE)
+ })
+ Object.defineProperty(window, 'clerum', {
+ configurable: true,
+ value: {
+ gfs: {
+ listAccessible,
+ resolve: vi.fn(),
+ listChildren: vi.fn(async () => ({ items: [], nextCursor: null })),
+ affordances: vi.fn(async () => ({
+ held: [],
+ canDelegate: false,
+ grantableBits: [],
+ canCreateShare: false,
+ })),
+ },
+ },
+ })
+
+ renderFilesPage()
+
+ await waitFor(() => {
+ // The reported symptom, asserted first so it is the failure reported
+ // when the seam is broken.
+ expect(screen.queryByText('Loading files…')).toBeNull()
+ // The raw IPC string must never reach the user.
+ expect(screen.queryByText(/Error invoking remote method/)).toBeNull()
+ // The route assertion: the controller's verdict reached the card with
+ // its retry hint intact, across every hop this PR touches.
+ expect(screen.getByTestId('gfs-discovery-retry-seconds').textContent).toBe('7')
+ })
+
+ expect(screen.getByRole('button', { name: /retry/i })).toBeTruthy()
+
+ // Liveness witness: discovery really ran through the real controller, so
+ // the absence assertions above describe a rendered failure rather than a
+ // page that never got started.
+ expect(listAccessible).toHaveBeenCalledTimes(1)
+ })
+})
diff --git a/desktop-app/ui/src/pages/__tests__/FilesPage.test.tsx b/desktop-app/ui/src/pages/__tests__/FilesPage.test.tsx
index c9830e808..f72c463aa 100644
--- a/desktop-app/ui/src/pages/__tests__/FilesPage.test.tsx
+++ b/desktop-app/ui/src/pages/__tests__/FilesPage.test.tsx
@@ -77,6 +77,8 @@ function baseController() {
mutating: false,
reset: vi.fn(),
refreshAffordances: vi.fn(),
+ discoveryFailure: null,
+ retryDiscovery: vi.fn(),
}
}
@@ -2201,6 +2203,51 @@ describe('FilesPage', () => {
expect(revokeObjectURL).toHaveBeenCalledWith('blob:gfs-download')
})
+ it('toasts a rate-limited download in read words, not permission words', async () => {
+ const download = vi.fn(async () => {
+ throw new Error(
+ "Error invoking remote method 'gfs:download': Error: gfs download failed: 429: " +
+ 'Too Many Requests retryAfterSeconds=7'
+ )
+ })
+ const pushToast = vi.fn()
+ Object.defineProperty(window, 'clerum', {
+ configurable: true,
+ value: { gfs: { download } },
+ })
+ hookMock.useGfsBrowserController.mockReturnValue({
+ ...baseController(),
+ accessibleResources: [
+ {
+ resourceId: 'file-1',
+ rid: 'file-1',
+ gfsUri: 'gfs://main/file-1',
+ drive: 'main',
+ parentResourceId: null,
+ name: 'report.pdf',
+ kind: 'file',
+ path: '/report.pdf',
+ version: 0,
+ bytes: 3,
+ sources: ['grant'],
+ permissions: ['read'],
+ coversDescendants: false,
+ },
+ ],
+ })
+
+ renderFilesPage(pushToast)
+ await act(async () => {
+ fireEvent.click(screen.getByRole('button', { name: 'Download report.pdf' }))
+ await Promise.resolve()
+ })
+
+ // Witness: the download really ran and really rejected, so the copy
+ // assertions below describe a handled failure.
+ expect(download).toHaveBeenCalledWith('gfs://main/file-1')
+ expect(pushToast).toHaveBeenCalledWith('Too many file requests — try again in 7s.', 'error')
+ })
+
it('shows the document icon for txt, md, pdf, doc and docx files instead of the clip', () => {
hookMock.useGfsBrowserController.mockReturnValue({
...baseController(),
@@ -3326,4 +3373,63 @@ describe('FilesPage', () => {
expect(listChildren).toHaveBeenCalledWith('folder-a', 'main', undefined)
expect(listChildren).toHaveBeenCalledWith('folder-b', 'main', undefined)
})
+
+ it('renders a rate-limited discovery failure as a card with a retry countdown', async () => {
+ vi.useFakeTimers()
+ const retryDiscovery = vi.fn()
+ const rawMessage =
+ "Error invoking remote method 'gfs:listAccessible': Error: 429 Too Many Requests: " +
+ 'Too Many Requests retryAfterSeconds=7'
+ hookMock.useGfsBrowserController.mockReturnValue({
+ ...baseController(),
+ authorityPending: true,
+ accessibleError: rawMessage,
+ discoveryFailure: { kind: 'rate-limited', message: rawMessage, retryAfterSeconds: 7 },
+ retryDiscovery,
+ })
+
+ renderFilesPage()
+
+ expect(screen.getByTestId('gfs-discovery-retry-seconds').textContent).toBe('7')
+ // None of the three things the user saw during the incident.
+ expect(screen.queryByText('Loading files…')).toBeNull()
+ expect(screen.queryByText(/Error invoking remote method/)).toBeNull()
+ expect(screen.queryByText(/Automatic GFS discovery is not available/)).toBeNull()
+
+ const disabledRetry = screen.getByRole('button', { name: /retry/i }) as HTMLButtonElement
+ expect(disabledRetry.disabled).toBe(true)
+
+ await act(async () => {
+ await vi.advanceTimersByTimeAsync(7_000)
+ })
+
+ expect(screen.queryByTestId('gfs-discovery-retry-seconds')).toBeNull()
+ const enabledRetry = screen.getByRole('button', { name: /retry/i }) as HTMLButtonElement
+ expect(enabledRetry.disabled).toBe(false)
+
+ await act(async () => {
+ fireEvent.click(enabledRetry)
+ })
+ // Witness: the button is wired to the controller, not to a local no-op.
+ expect(retryDiscovery).toHaveBeenCalledTimes(1)
+ })
+
+ it('leaves an unsupported discovery failure on the existing info notice, with no card', () => {
+ hookMock.useGfsBrowserController.mockReturnValue({
+ ...baseController(),
+ accessibleNotice:
+ 'Automatic GFS discovery is not available from this server yet. You can still open any GFS link you have.',
+ discoveryFailure: {
+ kind: 'unsupported',
+ message: '404 Not Found: Not Found',
+ retryAfterSeconds: null,
+ },
+ })
+
+ renderFilesPage()
+
+ expect(screen.getByText(/Automatic GFS discovery is not available/)).toBeTruthy()
+ expect(screen.queryByTestId('gfs-discovery-retry-seconds')).toBeNull()
+ expect(screen.queryByRole('button', { name: /retry file listing/i })).toBeNull()
+ })
})