diff --git a/apps/desktop/src/app/session/hooks/use-hermes-config.test.ts b/apps/desktop/src/app/session/hooks/use-hermes-config.test.ts new file mode 100644 index 000000000000..f4c6878b7f64 --- /dev/null +++ b/apps/desktop/src/app/session/hooks/use-hermes-config.test.ts @@ -0,0 +1,144 @@ +// @vitest-environment jsdom +import { act, renderHook } from '@testing-library/react' +import { beforeEach, describe, expect, it, vi } from 'vitest' + +import { getHermesConfig } from '@/hermes' +import { persistString } from '@/lib/storage' +import { $currentCwd, setCurrentCwd } from '@/store/session' + +import { useHermesConfig } from './use-hermes-config' + +vi.mock('@/hermes', () => ({ + getHermesConfig: vi.fn(), + getHermesConfigDefaults: vi.fn().mockResolvedValue({}) +})) + +const WORKSPACE_CWD_KEY = 'hermes.desktop.workspace-cwd' + +const mockConfig = (config: Record) => + vi.mocked(getHermesConfig).mockResolvedValue(config as Awaited>) + +describe('useHermesConfig refreshHermesConfig', () => { + beforeEach(() => { + // Reset atoms and localStorage between tests + setCurrentCwd('') + persistString(WORKSPACE_CWD_KEY, null) + }) + + it('applies terminal.cwd from config even when localStorage has a stale value', async () => { + // Simulate a stale remembered workspace cwd + persistString(WORKSPACE_CWD_KEY, '/Users/old/stale-project') + setCurrentCwd('/Users/old/stale-project') + + mockConfig({ terminal: { cwd: '/Users/example/new-workspace' } }) + + const { result } = renderHook(() => + useHermesConfig({ + activeSessionIdRef: { current: null }, + refreshProjectBranch: vi.fn().mockResolvedValue(undefined) + }) + ) + + await act(async () => { + await result.current.refreshHermesConfig() + }) + + // The configured terminal.cwd must override the stale localStorage value + expect($currentCwd.get()).toBe('/Users/example/new-workspace') + }) + + it('keeps the active session workspace when a session is running', async () => { + setCurrentCwd('/workspace/attached-project') + + mockConfig({ terminal: { cwd: '/Users/example/new-workspace' } }) + + const { result } = renderHook(() => + useHermesConfig({ + activeSessionIdRef: { current: 'session-1' }, + refreshProjectBranch: vi.fn().mockResolvedValue(undefined) + }) + ) + + await act(async () => { + await result.current.refreshHermesConfig() + }) + + // Config refreshes mid-session must not yank the workspace out from + // under the attached session. + expect($currentCwd.get()).toBe('/workspace/attached-project') + }) + + it('uses empty string when terminal.cwd is not set and localStorage is empty', async () => { + mockConfig({}) + + const { result } = renderHook(() => + useHermesConfig({ + activeSessionIdRef: { current: null }, + refreshProjectBranch: vi.fn().mockResolvedValue(undefined) + }) + ) + + await act(async () => { + await result.current.refreshHermesConfig() + }) + + expect($currentCwd.get()).toBe('') + }) + + it('ignores terminal.cwd when it is "."', async () => { + mockConfig({ terminal: { cwd: '.' } }) + + const { result } = renderHook(() => + useHermesConfig({ + activeSessionIdRef: { current: null }, + refreshProjectBranch: vi.fn().mockResolvedValue(undefined) + }) + ) + + await act(async () => { + await result.current.refreshHermesConfig() + }) + + expect($currentCwd.get()).toBe('') + }) + + it('calls refreshProjectBranch with the configured cwd', async () => { + const refreshProjectBranch = vi.fn().mockResolvedValue(undefined) + setCurrentCwd('') + + mockConfig({ terminal: { cwd: '/workspace/project-a' } }) + + const { result } = renderHook(() => + useHermesConfig({ + activeSessionIdRef: { current: null }, + refreshProjectBranch + }) + ) + + await act(async () => { + await result.current.refreshHermesConfig() + }) + + expect(refreshProjectBranch).toHaveBeenCalledWith('/workspace/project-a') + }) + + it('refreshes the branch for the session cwd (not config) when a session is active', async () => { + const refreshProjectBranch = vi.fn().mockResolvedValue(undefined) + setCurrentCwd('/workspace/attached-project') + + mockConfig({ terminal: { cwd: '/Users/example/new-workspace' } }) + + const { result } = renderHook(() => + useHermesConfig({ + activeSessionIdRef: { current: 'session-1' }, + refreshProjectBranch + }) + ) + + await act(async () => { + await result.current.refreshHermesConfig() + }) + + expect(refreshProjectBranch).toHaveBeenCalledWith('/workspace/attached-project') + }) +}) diff --git a/apps/desktop/src/app/session/hooks/use-hermes-config.ts b/apps/desktop/src/app/session/hooks/use-hermes-config.ts index 84bff0e59430..16242ba71c59 100644 --- a/apps/desktop/src/app/session/hooks/use-hermes-config.ts +++ b/apps/desktop/src/app/session/hooks/use-hermes-config.ts @@ -53,7 +53,10 @@ export function useHermesConfig({ activeSessionIdRef, refreshProjectBranch }: He const cwd = (config.terminal?.cwd ?? '').trim() if (cwd && cwd !== '.') { - setCurrentCwd(prev => prev || cwd) + // Configured terminal.cwd beats a stale remembered workspace cwd + // (#38855) — but never yank the workspace out from under an active + // session; those keep their own cwd until the user detaches. + setCurrentCwd(prev => (activeSessionIdRef.current ? prev : cwd)) void refreshProjectBranch($currentCwd.get() || cwd) } diff --git a/scripts/release.py b/scripts/release.py index 17ab714e65db..a5e023da9b6a 100755 --- a/scripts/release.py +++ b/scripts/release.py @@ -45,6 +45,7 @@ # Auto-extracted from noreply emails + manual overrides AUTHOR_MAP = { + "sahibzada@fastino.ai": "sahibzada-allahyar", # PR #39227 salvage (desktop: configured terminal.cwd overrides a stale remembered workspace-cwd localStorage value when no session is active; #38855) "jvsantos.cunha@gmail.com": "plcunha", # PR #55300 salvage (gateway: record child gateway peer metadata after a compression session-id rotation and repoint stale sessions.json compression-parent entries to the recovered live child; consolidated in the compression-routing-integrity salvage) "jakepresent1@gmail.com": "jakepresent", # PR #55721 salvage (gateway: identity-guard stale in-flight compression splits — a late run may publish its compressed child only if its run generation is still current and the session key still points at the run's original parent, so an old run can't overwrite a newer /new or moved binding) "zhangml@tech.icbc.com.cn": "zmlgit", # PR #54872 salvage (multiplex-profile kanban: route task notifications via the owning profile's adapter + wake the creator agent with a synthetic internal MessageEvent on terminal events)