The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): save hand-registered Cloud connections as oauth with a sign-in row
brooklyn!9a2507e0a76d
diff --git a/apps/desktop/electron/connection-registry.test.ts b/apps/desktop/electron/connection-registry.test.tsindex de49aba630f..2c37e4179f6 100644--- a/apps/desktop/electron/connection-registry.test.ts+++ b/apps/desktop/electron/connection-registry.test.ts@@ -1082,6 +1082,53 @@ test('token only persists on token-auth remotes; oauth/cloud drop it', () => {assert.equal(cloud.token, undefined)})+test('a cloud entry is saved as oauth even when the payload says token (#89529)', () => {+ // Cloud never keeps a pasted token (above), so token auth would leave the+ // entry with no credential and Test failing with "no saved session token".+ for (const authMode of [undefined, 'token'] as const) {+ const cloud = normalizeConnectionInput(+ { kind: 'cloud', label: 'C', url: 'https://c.hermes.cloud', authMode, token: { enc: 'x' } },+ emptyRegistry()+ )++ assert.equal(cloud.authMode, 'oauth')+ assert.equal(cloud.token, undefined)+ }++ // Remote keeps its explicit choice and its token default.+ const remote = normalizeConnectionInput({ kind: 'remote', label: 'R', url: 'http://r:1' }, emptyRegistry())++ assert.equal(remote.authMode, 'token')+})++test('a stored cloud entry left on token auth with no token reads back as oauth (#89529)', () => {+ const registry = normalizeRegistry({+ version: REGISTRY_VERSION,+ primary: 'local',+ connections: [+ { id: 'local', kind: 'local', label: 'This device' },+ { id: 'cloud-bare', kind: 'cloud', label: 'Bare cloud', url: 'https://a.hermes.cloud', authMode: 'token' },+ {+ id: 'cloud-keyed',+ kind: 'cloud',+ label: 'Keyed cloud',+ url: 'https://b.hermes.cloud',+ authMode: 'token',+ token: { v: 1 }+ },+ { id: 'homelab', kind: 'remote', label: 'Homelab', url: 'http://10.0.0.5:9119', authMode: 'token' }+ ]+ })++ const byId = Object.fromEntries(registry.connections.map(c => [c.id, c]))++ assert.equal(byId['cloud-bare'].authMode, 'oauth')+ // A real saved credential is never discarded, and remotes are untouched.+ assert.equal(byId['cloud-keyed'].authMode, 'token')+ assert.deepEqual(byId['cloud-keyed'].token, { v: 1 })+ assert.equal(byId.homelab.authMode, 'token')+})+test('an ssh entry keeps its session token through a label rename', () => {// #103795, second half: saveRegistryConnection resolves the surviving// envelope (resolvePersistedRemoteToken keeps the stored one when thediff --git a/apps/desktop/electron/connection-registry.ts b/apps/desktop/electron/connection-registry.tsindex 72f52cf5b0e..45ebce0e465 100644--- a/apps/desktop/electron/connection-registry.ts+++ b/apps/desktop/electron/connection-registry.ts@@ -840,6 +840,17 @@ export interface ConnectionInput {* uniqueness context; when `input.id` matches an existing entry this is an* edit and that entry is excluded from the label-collision check.*/+/**+ * Auth mode a stored remote-shaped entry actually uses. A Hermes Cloud gateway+ * signs in through its OAuth session and never keeps a pasted token (the save+ * path drops one), so a cloud entry on token auth with no token has no+ * credential at all and Test can only fail (#89529). Read it as oauth; a cloud+ * entry that does carry a token keeps its mode.+ */+function storedAuthMode(kind: ConnectionKind, authMode: unknown, token: unknown): 'oauth' | 'token' {+ return kind === 'cloud' && !token ? 'oauth' : normAuthMode(authMode)+}+export function normalizeConnectionInput(input: ConnectionInput, registry: ConnectionRegistry): RegistryConnection {const label = String(input.label || '').trim()@@ -939,7 +950,8 @@ export function normalizeConnectionInput(input: ConnectionInput, registry: Connethrow new Error(`A connection to this gateway URL already exists ("${urlDupe.label}").`)}- const authMode = normAuthMode(input.authMode)+ // Cloud never stores a token (below), so it is always oauth.+ const authMode = storedAuthMode(kind, input.authMode, undefined)const entry: RegistryConnection = { id, kind, label, url, authMode }// A token is only meaningful for token-auth remotes. Dropping it here is@@ -1190,7 +1202,7 @@ export function normalizeRegistry(raw: unknown): ConnectionRegistry {}clean.url = url- clean.authMode = normAuthMode(entry.authMode)+ clean.authMode = storedAuthMode(kind, entry.authMode, entry.token)if (entry.token !== undefined) {clean.token = entry.tokendiff --git a/apps/desktop/src/app/settings/connections-registry.test.tsx b/apps/desktop/src/app/settings/connections-registry.test.tsxindex 7bdd378b499..1f60709b0b6 100644--- a/apps/desktop/src/app/settings/connections-registry.test.tsx+++ b/apps/desktop/src/app/settings/connections-registry.test.tsx@@ -109,6 +109,37 @@ describe('ConnectionsRegistrySection', () => {})})+ it('signs a hand-registered Cloud connection in and saves it as oauth (#89529)', async () => {+ const oauthLoginConnectionConfig = vi.fn().mockResolvedValue({ connected: true, ok: true })+ Object.assign(window.hermesDesktop!, { oauthLoginConnectionConfig })++ render(<ConnectionsRegistrySection />)++ await screen.findByText('Homelab')+ fireEvent.click(screen.getByText('Add connection'))+ fireEvent.click(screen.getByRole('button', { name: 'Hermes Cloud' }))+ fireEvent.change(screen.getByPlaceholderText('Homelab'), { target: { value: 'Team cloud' } })+ fireEvent.change(screen.getByPlaceholderText('http://homelab.lan:9119'), {+ target: { value: 'https://team.hermes.cloud' }+ })++ // Cloud never takes a pasted token: no token box, a sign-in button instead.+ expect(screen.queryByPlaceholderText('Paste session token')).toBeNull()+ fireEvent.click(await screen.findByRole('button', { name: /sign in/i }))+ await waitFor(() => expect(oauthLoginConnectionConfig).toHaveBeenCalledWith('https://team.hermes.cloud'))++ fireEvent.click(screen.getByText('Save connection').closest('button')!)++ await waitFor(() => expect(save).toHaveBeenCalledTimes(1))+ expect(save.mock.calls[0][0]).toMatchObject({+ authMode: 'oauth',+ kind: 'cloud',+ label: 'Team cloud',+ url: 'https://team.hermes.cloud'+ })+ expect(save.mock.calls[0][0].token).toBeUndefined()+ })+it('saves a custom remote Hermes path for SSH connections', async () => {render(<ConnectionsRegistrySection />)diff --git a/apps/desktop/src/app/settings/connections-registry.tsx b/apps/desktop/src/app/settings/connections-registry.tsxindex 29660a02f5d..77bcc3723bb 100644--- a/apps/desktop/src/app/settings/connections-registry.tsx+++ b/apps/desktop/src/app/settings/connections-registry.tsx@@ -69,6 +69,17 @@ interface EditorState {headers: { name: string; stored: boolean; value: string }[]}+/**+ * The auth mode the editor saves. A Hermes Cloud gateway signs in through its+ * OAuth session and never keeps a pasted token (the main process drops one),+ * so cloud is always oauth whatever the shared editor state last held for a+ * remote; token auth left a hand-registered cloud entry with no credential+ * (#89529).+ */+function editorAuthMode(editor: Pick<EditorState, 'authMode' | 'kind'>): EditorState['authMode'] {+ return editor.kind === 'cloud' ? 'oauth' : editor.authMode+}+function editorFromConnection(conn: DesktopRegistryConnection): EditorState {return {id: conn.id,@@ -277,8 +288,9 @@ export function ConnectionsRegistrySection() {setConnectionsRegistry(next)}, [])- const editorUrl = editor?.kind === 'remote' ? coerceRemoteUrlScheme(editor.url) : ''- const editorWantsOauth = editor?.kind === 'remote' && editor.authMode === 'oauth'+ const editorIsGateway = editor?.kind === 'remote' || editor?.kind === 'cloud'+ const editorUrl = editor && editorIsGateway ? coerceRemoteUrlScheme(editor.url) : ''+ const editorWantsOauth = Boolean(editor && editorIsGateway && editorAuthMode(editor) === 'oauth')const authProviderShape = deriveRemoteAuthProviderShape(authProbe?.providers, t.boot.failure.identityProvider)// Probe only while the sign-in row is on screen, and debounce it so typing a@@ -428,7 +440,7 @@ export function ConnectionsRegistrySection() {if (editor.kind === 'remote' || editor.kind === 'cloud') {payload.url = editor.url- payload.authMode = editor.authMode+ payload.authMode = editorAuthMode(editor)if (editor.token.trim()) {payload.token = editor.token.trim()@@ -850,37 +862,38 @@ export function ConnectionsRegistrySection() {title={t.settings.gateway.tokenTitle}/>)}- {editor.authMode === 'oauth' && (- <ListRow- action={- oauthConnected ? (- <Pill tone="primary">- <Check className="size-3" /> {t.settings.gateway.signedIn}- </Pill>- ) : (- <Button disabled={signingIn || !editorUrl} onClick={() => void signInOauth()} size="sm">- {signingIn ? <Loader2 className="size-4 animate-spin" /> : <LogIn className="size-4" />}- {authProviderShape.isPassword- ? t.settings.gateway.signIn- : t.settings.gateway.signInWith(authProviderShape.providerLabel)}- </Button>- )- }- description={- oauthConnected- ? authProviderShape.isPassword- ? t.settings.gateway.authSignedInPassword- : t.settings.gateway.authSignedInOauth- : authProviderShape.isPassword- ? t.settings.gateway.authNeedsPassword- : t.settings.gateway.authNeedsOauth(authProviderShape.providerLabel)- }- title={t.settings.gateway.authTitle}- />- )}</>)}+ {editorWantsOauth && (+ <ListRow+ action={+ oauthConnected ? (+ <Pill tone="primary">+ <Check className="size-3" /> {t.settings.gateway.signedIn}+ </Pill>+ ) : (+ <Button disabled={signingIn || !editorUrl} onClick={() => void signInOauth()} size="sm">+ {signingIn ? <Loader2 className="size-4 animate-spin" /> : <LogIn className="size-4" />}+ {authProviderShape.isPassword+ ? t.settings.gateway.signIn+ : t.settings.gateway.signInWith(authProviderShape.providerLabel)}+ </Button>+ )+ }+ description={+ oauthConnected+ ? authProviderShape.isPassword+ ? t.settings.gateway.authSignedInPassword+ : t.settings.gateway.authSignedInOauth+ : authProviderShape.isPassword+ ? t.settings.gateway.authNeedsPassword+ : t.settings.gateway.authNeedsOauth(authProviderShape.providerLabel)+ }+ title={t.settings.gateway.authTitle}+ />+ )}+{(editor.kind === 'remote' || editor.kind === 'cloud') && (<div className="grid gap-2"><div>