The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(desktop): settle the cookie window before destroying it; hoist its types
kshitijk4poor01382698fc32
diff --git a/apps/desktop/electron/portal-session.ts b/apps/desktop/electron/portal-session.tsindex 6d802416487..c8b9ce78a98 100644--- a/apps/desktop/electron/portal-session.ts+++ b/apps/desktop/electron/portal-session.ts@@ -12,6 +12,16 @@ interface PortalSessionDependencies {rememberLog: (message: string) => void}+interface CookieWindowOptions {+ kind: string+ title: string+ show: boolean+ pollMs: number+ deadlineMs?: number+}++type CookieWindowOutcome = 'landed' | 'closed' | 'timeout' | Error+// Portal credentials belong to NAS, independently of the selected gateway.// Read the jar on every operation so provider changes never latch in Desktop.export function createPortalSession({@@ -90,20 +100,8 @@ export function createPortalSession({return access.some(cookie => !previous.some(old => old.name === cookie.name && old.value === cookie.value))}- interface CookieWindowOptions {- kind: string- title: string- show: boolean- pollMs: number- deadlineMs?: number- }-- type CookieWindowOutcome = 'landed' | 'closed' | 'timeout' | Error-- // Load the portal root in the OAuth partition and settle once a new access- // cookie lands, the window closes, the deadline passes, or the window cannot- // be created/loaded. The portal owns provider selection, provisioning and- // refresh redirects; Desktop only watches the jar.+ // The portal owns provider selection, provisioning and refresh redirects;+ // Desktop only watches the jar for a new access cookie.function driveCookieWindow(sess: Session, previous: PortalCookie[], options: CookieWindowOptions) {const portalBaseUrl = resolvePortalBaseUrl()@@ -128,11 +126,12 @@ export function createPortalSession({clearTimeout(deadlineTimer)}+ // Settle first: a destroy() that throws must not leave the caller hanging.+ resolve(outcome)+if (win && !win.isDestroyed()) {win.destroy()}-- resolve(outcome)}const checkCookie = async () => {diff --git a/apps/desktop/src/app/gateway/hooks/use-gateway-boot.test.tsx b/apps/desktop/src/app/gateway/hooks/use-gateway-boot.test.tsxindex 44e5f722cc7..908f885f4cc 100644--- a/apps/desktop/src/app/gateway/hooks/use-gateway-boot.test.tsx+++ b/apps/desktop/src/app/gateway/hooks/use-gateway-boot.test.tsx@@ -546,8 +546,9 @@ describe('primary failure foreground isolation', () => {// about it from where they are — without the foreground being hijacked.expect(isActivePrimary()).toBe(false)expect($desktopBoot.get().error).toBeNull()- const toast = $notifications.get().find(entry => entry.kind === 'error')- expect(toast?.action?.label).toBe('Open Gateways')+ const toasts = $notifications.get().filter(entry => entry.kind === 'error')+ expect(toasts).toHaveLength(1)+ expect(toasts[0].action?.label).toBe('Open Gateways')})it.each(['progress', 'reconnect'] as const)(