From e1fa54d367573288061eefe2901657c77b7b44cb Mon Sep 17 00:00:00 2001 From: Brooklyn Nicholson Date: Sun, 12 Jul 2026 04:05:44 -0400 Subject: [PATCH] refactor(desktop): extract isRemoteConfig from the reauth predicate Factor the "remote/cloud with a URL" check out of isRemoteReauthFailure into a shared isRemoteConfig helper so the boot-failure overlay can tell any remote failure apart from a local one. --- .../components/boot-failure-reauth.test.ts | 15 ++++++++- .../src/components/boot-failure-reauth.ts | 31 ++++++++----------- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/apps/desktop/src/components/boot-failure-reauth.test.ts b/apps/desktop/src/components/boot-failure-reauth.test.ts index bf6f4f7ab91f..9a973639dda1 100644 --- a/apps/desktop/src/components/boot-failure-reauth.test.ts +++ b/apps/desktop/src/components/boot-failure-reauth.test.ts @@ -2,7 +2,7 @@ import { describe, expect, it } from 'vitest' import type { DesktopConnectionConfig } from '@/global' -import { deriveProviderShape, isRemoteReauthFailure, signInLabel } from './boot-failure-reauth' +import { deriveProviderShape, isRemoteConfig, isRemoteReauthFailure, signInLabel } from './boot-failure-reauth' function config(overrides: Partial = {}): DesktopConnectionConfig { return { @@ -19,6 +19,19 @@ function config(overrides: Partial = {}): DesktopConnec } } +describe('isRemoteConfig', () => { + it('true for remote/cloud with a URL, regardless of auth mode or connection', () => { + expect(isRemoteConfig(config({ remoteAuthMode: 'token', remoteOauthConnected: false }))).toBe(true) + expect(isRemoteConfig(config({ mode: 'cloud', remoteOauthConnected: true }))).toBe(true) + }) + + it('false for local, for a remote with no URL, and for nullish', () => { + expect(isRemoteConfig(config({ mode: 'local' }))).toBe(false) + expect(isRemoteConfig(config({ remoteUrl: '' }))).toBe(false) + expect(isRemoteConfig(null)).toBe(false) + }) +}) + describe('isRemoteReauthFailure', () => { it('true for a remote, gated, disconnected gateway with a URL', () => { expect(isRemoteReauthFailure(config())).toBe(true) diff --git a/apps/desktop/src/components/boot-failure-reauth.ts b/apps/desktop/src/components/boot-failure-reauth.ts index fd2e01ffcb67..95ea90ad72c0 100644 --- a/apps/desktop/src/components/boot-failure-reauth.ts +++ b/apps/desktop/src/components/boot-failure-reauth.ts @@ -26,25 +26,20 @@ const DEFAULT_SIGN_IN_COPY: SignInCopy = { withProvider: provider => `Sign in with ${provider}` } -// A remote, gated (oauth-bucket), not-currently-connected gateway is a -// remote-reauth boot failure: the access cookie lapsed (e.g. the remote -// dashboard restarted) and the local-recovery buttons (Retry/Repair) can't -// fix it — only re-establishing the remote session can. A connected oauth -// session, or a token/local gateway, boots for some other reason the -// local-recovery buttons address, so those return false here. 'cloud' counts -// as remote here — it resolves to a remote oauth backend (cloud-auto-discovery -// Q6), so a lapsed cloud session is the same reauth failure. -export function isRemoteReauthFailure(config: DesktopConnectionConfig | null | undefined): boolean { - if (!config) { - return false - } +// True when the app is pointed at a remote/cloud backend (either resolves to a +// remote URL). Any boot failure in this shape is fixable from Settings → +// Gateway (edit URL / token / sign in) — the local Retry/Repair buttons target +// the bundled backend and can't help. Drives the escape-hatch emphasis. +export function isRemoteConfig(config: DesktopConnectionConfig | null | undefined): boolean { + return Boolean(config && (config.mode === 'remote' || config.mode === 'cloud') && config.remoteUrl) +} - return ( - (config.mode === 'remote' || config.mode === 'cloud') && - config.remoteAuthMode === 'oauth' && - !config.remoteOauthConnected && - Boolean(config.remoteUrl) - ) +// A remote, gated (oauth-bucket), not-currently-connected gateway is a +// remote-reauth boot failure: the access cookie lapsed and the local Retry/Repair +// buttons can't fix it — only re-establishing the remote session can. 'cloud' +// counts as remote (it resolves to a remote oauth backend). +export function isRemoteReauthFailure(config: DesktopConnectionConfig | null | undefined): boolean { + return isRemoteConfig(config) && config!.remoteAuthMode === 'oauth' && !config!.remoteOauthConnected } // Derive the password flag + display label from the probed providers. A