Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop): warn toast styling and retried-listing abort race (PR review)
Md6b37a00bf41
diff --git a/desktop-app/ui/src/components/Common/ToastStack/__tests__/ToastStack.test.tsx b/desktop-app/ui/src/components/Common/ToastStack/__tests__/ToastStack.test.tsxindex 5d2996d07..cdf162720 100644--- a/desktop-app/ui/src/components/Common/ToastStack/__tests__/ToastStack.test.tsx+++ b/desktop-app/ui/src/components/Common/ToastStack/__tests__/ToastStack.test.tsx@@ -1,8 +1,19 @@// @vitest-environment jsdomimport { afterEach, describe, expect, it, vi } from 'vitest'import { cleanup, fireEvent, render, screen } from '@testing-library/react'+import { readFileSync } from 'node:fs'+import { resolve } from 'node:path'import { ToastStack } from '../index'+// Resolve the stylesheet relative to THIS test file so the assertion passes+// regardless of the directory vitest is launched from.+const toastStyles = readFileSync(resolve(__dirname, '../../../../styles.css'), 'utf8')++function cssRule(selector: string) {+ const match = toastStyles.match(new RegExp(`${selector}\\s*\\{([^}]*)\\}`))+ return match?.[1] ?? ''+}+afterEach(() => {cleanup()vi.restoreAllMocks()@@ -28,6 +39,14 @@ describe('ToastStack', () => {expect(screen.queryByRole('button')).toBeNull()})+ it('renders a warn toast with the warn tone class, warning glyph and amber border (L1)', () => {+ render(<ToastStack items={[{ id: 3, tone: 'warn', text: 'Skipped 1 entry' }]} />)+ const toast = screen.getByRole('status')+ expect(toast.className).toBe('toast tone-warn')+ expect(toast.querySelector('.toast-icon')?.textContent).toBe('▲')+ expect(cssRule('.toast.tone-warn')).toContain('rgba(var(--warning-rgb)')+ })+it('runs the toast action and dismisses through onDismiss when clicked', () => {const onAction = vi.fn()const onDismiss = vi.fn()diff --git a/desktop-app/ui/src/components/Common/ToastStack/index.tsx b/desktop-app/ui/src/components/Common/ToastStack/index.tsxindex e3f7c96cf..6598b6b83 100644--- a/desktop-app/ui/src/components/Common/ToastStack/index.tsx+++ b/desktop-app/ui/src/components/Common/ToastStack/index.tsx@@ -17,7 +17,13 @@ export function ToastStack({ items, onDismiss }: ToastStackProps) {className={`toast tone-${item.tone}`}><span aria-hidden className="toast-icon">- {item.tone === 'success' ? '●' : item.tone === 'error' ? '!' : 'i'}+ {item.tone === 'success'+ ? '●'+ : item.tone === 'error'+ ? '!'+ : item.tone === 'warn'+ ? '▲'+ : 'i'}</span><span className="toast-body">{item.text}</span>{item.action ? (diff --git a/desktop-app/ui/src/lib/__tests__/gfsFolderZip.test.ts b/desktop-app/ui/src/lib/__tests__/gfsFolderZip.test.tsindex a48f0cd4f..73bd9bcd7 100644--- a/desktop-app/ui/src/lib/__tests__/gfsFolderZip.test.ts+++ b/desktop-app/ui/src/lib/__tests__/gfsFolderZip.test.ts@@ -7,6 +7,7 @@ import {GfsFolderZipLimitError,type GfsFolderZipProgress,type GfsZipChildItem,+ type GfsZipChildrenPage,createGfsFolderZip,createGfsReadThrottle,} from '../gfsFolderZip'@@ -349,6 +350,36 @@ describe('createGfsFolderZip', () => {await expectation})+ it('stops during the RETRIED listing, not only its first attempt (review L3)', async () => {+ const controller = new AbortController()+ let attempts = 0+ const deps: GfsFolderZipDeps = {+ listChildren: vi.fn(() => {+ attempts += 1+ if (attempts === 1)+ return Promise.reject(new Error('429 httpStatus=429 retryAfterSeconds=0'))+ // The retried listing hangs: without the abort race on the retry the+ // walk would park here forever and a Stop could never land.+ return new Promise<GfsZipChildrenPage>(() => undefined)+ }),+ download: async () => ({ bytes: new ArrayBuffer(0) }),+ throttle: { acquire: async () => undefined },+ sleep: async () => undefined,+ }++ const walk = createGfsFolderZip(+ { resourceId: 'root', drive: 'main', name: 'Stopped' },+ { deps, signal: controller.signal }+ )+ const expectation = expect(walk).rejects.toMatchObject({ name: 'AbortError' })+ // Let the first attempt reject, the backoff elapse and the retry fire+ // (each await in the retry chain is its own microtask tick).+ for (let index = 0; index < 200 && attempts < 2; index += 1) await Promise.resolve()+ expect(attempts).toBe(2)+ controller.abort()+ await expectation+ })+it('aborts on a non-permission download failure instead of a holey archive', async () => {const deps: GfsFolderZipDeps = {listChildren: vi.fn(async () => ({diff --git a/desktop-app/ui/src/lib/gfsFolderZip.ts b/desktop-app/ui/src/lib/gfsFolderZip.tsindex 66d428d67..3b30d2190 100644--- a/desktop-app/ui/src/lib/gfsFolderZip.ts+++ b/desktop-app/ui/src/lib/gfsFolderZip.ts@@ -218,6 +218,8 @@ export async function createGfsFolderZip(* re-enters the budget through `throttle.acquire()`, so a* `retryAfterSeconds=0` answer cannot fire the retry with zero spacing* against the same per-minute budget that just refused the first attempt.+ * Both attempts race the abort signal, so a Stop during the retried request+ * preempts immediately instead of waiting out the in-flight call.*/const withRateLimitRetry = async <T>(operation: () => Promise<T>): Promise<T> => {try {@@ -228,7 +230,7 @@ export async function createGfsFolderZip(if (!isRateLimited(message)) throw errorawait withAbort(sleep(Math.min((parseRetryAfterSeconds(message) ?? 15) * 1000, 120_000)))await withAbort(throttle.acquire())- return operation()+ return withAbort(operation())}}@@ -333,7 +335,7 @@ export async function createGfsFolderZip(await withAbort(throttle.acquire())let bytes: ArrayBuffertry {- bytes = (await withRateLimitRetry(() => withAbort(download(file.uri)))).bytes+ bytes = (await withRateLimitRetry(() => download(file.uri))).bytes} catch (error) {if (isFolderZipAbortError(error)) throw errorconst message = toMessage(error)diff --git a/desktop-app/ui/src/styles.css b/desktop-app/ui/src/styles.cssindex 32fbadc3d..7d202a4b1 100644--- a/desktop-app/ui/src/styles.css+++ b/desktop-app/ui/src/styles.css@@ -10637,6 +10637,10 @@ button.page-breadcrumb-link--plain-action:hover:enabled {border-color: rgba(var(--success-rgb), 0.5);}+.toast.tone-warn {+ border-color: rgba(var(--warning-rgb), 0.5);+}+.toast.tone-error {border-color: rgba(var(--danger-rgb), 0.52);}