The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(desktop): lock Home new-session detach against stale project cwd
xxxigm85a55e2b30fa
diff --git a/apps/desktop/src/app/session/hooks/use-session-actions.test.tsx b/apps/desktop/src/app/session/hooks/use-session-actions.test.tsxindex 3a46e8b62d6..1cef8496248 100644--- a/apps/desktop/src/app/session/hooks/use-session-actions.test.tsx+++ b/apps/desktop/src/app/session/hooks/use-session-actions.test.tsx@@ -4,6 +4,7 @@ import type { MutableRefObject } from 'react'import { useEffect, useRef } from 'react'import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'+import { NO_PROJECT_ID } from '@/app/chat/sidebar/projects/workspace-groups'import { $terminalTakeover, setTerminalTakeover } from '@/app/right-sidebar/store'import { noteActiveTreeGroup, revealTreePane } from '@/components/pane-shell/tree/store'import {@@ -91,7 +92,7 @@ const RUNTIME_SESSION_ID = 'rt-new-001'type HarnessHandle = Pick<ReturnType<typeof useSessionActions>,- 'createBackendSessionForSend' | 'removeSession' | 'selectSidebarItem' | 'startFreshSessionDraft'+ 'createBackendSessionForSend' | 'openNewSessionTile' | 'removeSession' | 'selectSidebarItem' | 'startFreshSessionDraft'>function storedSession(overrides: Partial<SessionInfo> = {}): SessionInfo {@@ -2754,6 +2755,7 @@ describe('createBackendSessionForSend workspace target', () => {cleanup()$newChatProfile.set(null)$activeGatewayProfile.set('default')+ $projectScope.set(ALL_PROJECTS)setCurrentCwd('')setNewChatWorkspaceTarget(undefined)vi.restoreAllMocks()@@ -2787,6 +2789,68 @@ describe('createBackendSessionForSend workspace target', () => {expect(params).toMatchObject({ cwd: '/clicked-workspace' })})++ it('does not inherit a stale cwd when Home is the active project scope', async () => {+ const params = await createWith(+ () => {+ $projectScope.set(NO_PROJECT_ID)+ },+ () => {+ // Simulate the stale live path left by the previously selected project+ // before the new draft is submitted.+ $currentCwd.set('/previous-project')+ }+ )++ expect(params).not.toHaveProperty('cwd')+ })+})++describe('openNewSessionTile workspace target', () => {+ afterEach(() => {+ cleanup()+ $projectScope.set(ALL_PROJECTS)+ $projectTree.set([])+ vi.restoreAllMocks()+ })++ it('omits cwd for a Home tile even when project scope resolves to a repo', async () => {+ $projectScope.set('p_voice')+ $projectTree.set([+ {+ id: 'p_voice',+ label: 'Voice Assistant',+ path: '/Users/oschmidt/Checkouts/voice-assistant',+ repos: [],+ sessionCount: 0+ } as never+ ])++ let createParams: Record<string, unknown> | undefined+ const requestGateway = vi.fn(async (method: string, params?: Record<string, unknown>) => {+ if (method === 'session.create') {+ createParams = params++ return {+ info: { cwd: '', model: 'test-model', tools: {}, skills: {} },+ session_id: RUNTIME_SESSION_ID,+ stored_session_id: 'stored-home-tile'+ } as never+ }++ return {} as never+ })++ let handle: HarnessHandle | null = null+ render(<Harness onReady={value => (handle = value)} requestGateway={requestGateway} />)+ await waitFor(() => expect(handle).not.toBeNull())++ await act(async () => {+ await handle!.openNewSessionTile('center', { cwd: null, listed: false })+ })++ expect(createParams).not.toHaveProperty('cwd')+ })})describe('selectSidebarItem', () => {it('fronts the workspace pane when navigating to a sidebar route (issue #72602)', async () => {diff --git a/apps/desktop/src/app/session/workspace-session-target.test.ts b/apps/desktop/src/app/session/workspace-session-target.test.tsindex 4a3ff10d4b5..bbe22859b0c 100644--- a/apps/desktop/src/app/session/workspace-session-target.test.ts+++ b/apps/desktop/src/app/session/workspace-session-target.test.ts@@ -1,9 +1,11 @@import { afterEach, describe, expect, it, vi } from 'vitest'+import { $projectScope, $projectTree, ALL_PROJECTS } from '@/store/projects'import {$currentBranch,$currentCwd,$newChatWorkspaceTarget,+ type NewChatWorkspaceTarget,setCurrentBranch,setCurrentCwd,setNewChatWorkspaceTarget@@ -18,6 +20,8 @@ describe('startWorkspaceSession', () => {setCurrentBranch('')setCurrentCwd('')setNewChatWorkspaceTarget(undefined)+ $projectScope.set(ALL_PROJECTS)+ $projectTree.set([])vi.restoreAllMocks()})@@ -32,7 +36,7 @@ describe('startWorkspaceSession', () => {const activeSessionIdRef = { current: null }- const startFreshSessionDraft = vi.fn((options?: { workspaceTarget: string }) => {+ const startFreshSessionDraft = vi.fn((options?: { workspaceTarget: NewChatWorkspaceTarget }) => {setNewChatWorkspaceTarget(options?.workspaceTarget)setCurrentCwd(options?.workspaceTarget || '')})@@ -70,4 +74,36 @@ describe('startWorkspaceSession', () => {expect($currentCwd.get()).toBe('/normalized-b')expect($currentBranch.get()).toBe('main')})++ it('keeps a Home new-session request detached even when another project scope is active', () => {+ $projectScope.set('p_voice')+ $projectTree.set([+ {+ id: 'p_voice',+ label: 'Voice Assistant',+ path: '/Users/oschmidt/Checkouts/voice-assistant',+ repos: [],+ sessionCount: 0+ }+ ])++ const requestGateway = vi.fn()+ const activeSessionIdRef = { current: null }+ const startFreshSessionDraft = vi.fn((options?: { workspaceTarget: NewChatWorkspaceTarget }) => {+ setNewChatWorkspaceTarget(options?.workspaceTarget)+ setCurrentCwd(options?.workspaceTarget || '')+ })++ startWorkspaceSession({+ activeSessionIdRef,+ path: null,+ requestGateway,+ startFreshSessionDraft+ })++ expect(startFreshSessionDraft).toHaveBeenCalledWith({ workspaceTarget: null })+ expect(requestGateway).not.toHaveBeenCalled()+ expect($newChatWorkspaceTarget.get()).toBeNull()+ expect($currentCwd.get()).toBe('')+ })})