Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/renderer/src/components/WorktreeJumpPalette.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ describe('WorktreeJumpPalette', () => {
// The first row names ITS OWN host — the wrong-host open is gone.
await act(async () => fireEvent.click(rows[0]!))
expect(activateAndRevealWorktree).toHaveBeenLastCalledWith('shared', {
navigationIntent: 'user-open',
executionHostId: 'local'
})
})
Expand All @@ -443,6 +444,7 @@ describe('WorktreeJumpPalette', () => {

await act(async () => fireEvent.click(rows[1]!))
expect(activateAndRevealWorktree).toHaveBeenLastCalledWith('shared', {
navigationIntent: 'user-open',
executionHostId: 'ssh:box'
})
})
Expand Down Expand Up @@ -487,6 +489,7 @@ describe('WorktreeJumpPalette', () => {

await act(async () => fireEvent.click(hubARow!))
expect(activateAndRevealWorktree).toHaveBeenLastCalledWith('shared-runtime', {
navigationIntent: 'user-open',
executionHostId: 'runtime:hub-a'
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ describe('activity thread host routing', () => {

expect(acknowledgeAgents).toHaveBeenCalledWith([thread.paneKey])
expect(mocks.activateAndRevealWorkspace).toHaveBeenCalledWith(thread.worktree.id, {
navigationIntent: 'user-open',
executionHostId: REMOTE_HOST
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { CheckRunDetailsPanel } from './CheckRunDetailsPanel'
const writeClipboardText = vi.fn<(text: string) => Promise<void>>()

vi.mock('@/i18n/i18n', () => ({
i18n: { language: 'en' },
translate: (_key: string, fallback: string) => fallback
}))

Expand Down
5 changes: 4 additions & 1 deletion src/renderer/src/components/editor/IpynbRendering.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import { IpynbRunPrompt } from './IpynbCellToolbar'
import { TooltipProvider } from '@/components/ui/tooltip'
import type { IpynbCell, IpynbOutput } from './ipynb-parse'

vi.mock('@/i18n/i18n', () => ({ translate: (_key: string, fallback: string) => fallback }))
vi.mock('@/i18n/i18n', () => ({
i18n: { language: 'en' },
translate: (_key: string, fallback: string) => fallback
}))
vi.mock('./use-document-dark-theme', () => ({ useDocumentDarkTheme: () => true }))
vi.mock('@/lib/monaco-setup', () => ({ monaco: {} }))
vi.mock('./MonacoCodeExcerpt', () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ vi.mock('@/lib/connection-context', () => ({
vi.mock('@/lib/connection-owner-resolution', () => ({
createConnectionIdForFileSelector: () => () => connectionOwner.value
}))
vi.mock('@/i18n/i18n', () => ({ translate: (_key: string, fallback: string) => fallback }))
vi.mock('@/i18n/i18n', () => ({
i18n: { language: 'en' },
translate: (_key: string, fallback: string) => fallback
}))
vi.mock('./useLocalImageSrc', () => ({ useLocalImageSrc: (src?: string) => src }))
vi.mock('./MermaidBlock', () => ({ default: () => null }))
vi.mock('./CodeBlockCopyButton', () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ vi.mock('@/lib/connection-context', () => ({ getConnectionIdForFile: () => null
vi.mock('@/lib/connection-owner-resolution', () => ({
createConnectionIdForFileSelector: () => () => null
}))
vi.mock('@/i18n/i18n', () => ({ translate: (_key: string, fallback: string) => fallback }))
vi.mock('@/i18n/i18n', () => ({
i18n: { language: 'en' },
translate: (_key: string, fallback: string) => fallback
}))
vi.mock('./useLocalImageSrc', () => ({ useLocalImageSrc: (src?: string) => src }))
vi.mock('./MermaidBlock', () => ({ default: () => null }))
vi.mock('./CodeBlockCopyButton', () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ export default function GitHubItemDialog({
return
}

const result = activateAndRevealWorktree(currentAttached.id)
const result = activateAndRevealWorktree(currentAttached.id, {
navigationIntent: 'user-open'
})
if (result === false) {
toast.error(
translate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ export default function PullRequestPage({
return
}

const result = activateAndRevealWorktree(currentAttached.id)
const result = activateAndRevealWorktree(currentAttached.id, {
navigationIntent: 'user-open'
})
if (result === false) {
toast.error(
translate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ vi.mock('lucide-react', async () =>
)

vi.mock('@/i18n/i18n', () => ({
i18n: { language: 'en' },
translate: (_key: string, fallback: string) => fallback
}))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ describe('sleep flow vs slept-workspace activation', () => {
expect(mocks.resumeWorkspace).toHaveBeenCalledWith({ workspaceId: 'wt-parent' })
expect(mocks.activateAndRevealWorktree).toHaveBeenCalledTimes(1)
expect(mocks.activateAndRevealWorktree).toHaveBeenCalledWith('wt-parent', {
navigationIntent: 'user-open',
revealInSidebar: false
})

Expand All @@ -102,6 +103,7 @@ describe('sleep flow vs slept-workspace activation', () => {
await activateWorktreeFromSidebar('wt-parent')

expect(mocks.activateAndRevealWorktree).toHaveBeenCalledWith('wt-parent', {
navigationIntent: 'user-open',
revealInSidebar: false
})
expect(mocks.toastError).toHaveBeenCalledWith(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export function useWorktreeContextMenuCommands(args: {
}, [args])
const handleOpenParent = useCallback(() => {
if (args.validParentWorktreeId) {
activateAndRevealWorktree(args.validParentWorktreeId)
activateAndRevealWorktree(args.validParentWorktreeId, { navigationIntent: 'user-open' })
}
}, [args.validParentWorktreeId])
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ describe('workspace list focus ownership', () => {
expect(document.activeElement).toBe(list)
press('ArrowUp')
expect(activate.mock.calls.map(([id]) => id)).toEqual(['b', 'c', 'b'])
expect(activate).toHaveBeenLastCalledWith('b', { executionHostId: 'ssh:fixture' })
expect(activate).toHaveBeenLastCalledWith('b', {
navigationIntent: 'user-open',
executionHostId: 'ssh:fixture'
})
expect(terminal.focus).not.toHaveBeenCalled()
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,22 +101,22 @@ describe('worktree keyboard cycling with a resolved active host', () => {

press('down')

expect(activateAndRevealWorktree).toHaveBeenCalledWith('c', {})
expect(activateAndRevealWorktree).toHaveBeenCalledWith('c', { navigationIntent: 'user-open' })
})

it('steps to the previous row when the active host resolved to local', () => {
renderProbe('b', 'local')

press('up')

expect(activateAndRevealWorktree).toHaveBeenCalledWith('a', {})
expect(activateAndRevealWorktree).toHaveBeenCalledWith('a', { navigationIntent: 'user-open' })
})

it('still steps normally when the active host is unqualified', () => {
renderProbe('b', null)

press('down')

expect(activateAndRevealWorktree).toHaveBeenCalledWith('c', {})
expect(activateAndRevealWorktree).toHaveBeenCalledWith('c', { navigationIntent: 'user-open' })
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ export function useWorktreeListKeyboardNavigation(args: {
}

// Why: keyboard cycling is real navigation; route through the activation helper that records history.
activateAndRevealWorktree(
nextWorktree.id,
nextWorktree.hostId ? { executionHostId: nextWorktree.hostId } : {}
)
activateAndRevealWorktree(nextWorktree.id, {
navigationIntent: 'user-open',
...(nextWorktree.hostId ? { executionHostId: nextWorktree.hostId } : {})
})

const rowIndex = findPreferredRenderRowIndexForWorktreeIdentity(
renderRows,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ vi.mock('@/lib/react-error-boundary-reporting', () => ({
}))

vi.mock('@/i18n/i18n', () => ({
i18n: { language: 'en' },
translate: (_key: string, fallback: string, options?: Record<string, unknown>) =>
options
? fallback.replace(/{{(\w+)}}/g, (_match, name: string) => String(options[name] ?? ''))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ vi.mock('@/components/ui/tooltip', () => ({
}))

vi.mock('@/i18n/i18n', () => ({
i18n: { language: 'en' },
translate: (_key: string, fallback: string, values?: Record<string, string>) =>
values
? Object.entries(values).reduce(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ describe('workspace space manager source boundaries', () => {
expect(controller).toContain(
'removeWorktree(\n { id: worktree.worktreeId, executionHostId: worktree.executionHostId ?? null },\n true,\n { allowUnverifiedPtyStop: true }\n )'
)
expect(table).toContain('activateAndRevealWorktree(worktree.worktreeId)')
expect(table).toContain('activateAndRevealWorktree(worktree.worktreeId, {')
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,11 @@ export function WorkspaceSpaceManagerTable({
deleteState={getDeleteStateForWorktree(worktree)}
onToggleSelected={() => toggleSelection(worktree)}
onInspect={() => setInspectedWorktreeId(identity)}
onOpenWorkspace={() => activateAndRevealWorktree(worktree.worktreeId)}
onOpenWorkspace={() =>
activateAndRevealWorktree(worktree.worktreeId, {
navigationIntent: 'user-open'
})
}
onDelete={() => deleteWorktrees([worktree])}
onForceDelete={() => forceDeleteWorktree(worktree)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ describe('TaskPage workspace creation source boundaries', () => {
expect(section).toContain('findGithubWorkItemWorkspaceAttachment(')
expect(section).toContain('if (!currentAttached)')
expect(section).toContain('handleUseWorkItem(item)')
expect(section).toContain('activateAndRevealWorktree(currentAttached.id)')
expect(section).toContain('activateAndRevealWorktree(currentAttached.id, {')
})

it('uses the shared composer handler from GitHub detail and start-new actions', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { act, StrictMode } from 'react'
import { createRoot, type Root } from 'react-dom/client'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { useTerminalWatcherEffects } from '../use-terminal-watcher-effects'
import {
claimEmptyWorkspaceDefaultSurface,
releaseEmptyWorkspaceDefaultSurface
} from '@/lib/empty-workspace-default-surface-claims'

const mocks = vi.hoisted(() => {
const storeTabsByWorktree: Record<string, unknown[]> = {}
Expand Down Expand Up @@ -202,6 +206,19 @@ describe('passive terminal seeding retries until a decision applies', () => {
expect(mocks.createTab).toHaveBeenCalledTimes(1)
})

it('leaves the seed to an activation reseed awaiting agent detection', async () => {
const finishGate = deferredGate()
root = createRoot(document.createElement('div'))
await act(async () => root?.render(<Watcher />))
claimEmptyWorkspaceDefaultSurface('wt-1')
try {
await finishGate('empty')
expect(mocks.createTab).not.toHaveBeenCalled()
} finally {
releaseEmptyWorkspaceDefaultSurface('wt-1')
}
})

it('seeds after leaving and returning to a blocked workspace', async () => {
mocks.gate.mockResolvedValue('blocked')
root = createRoot(document.createElement('div'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ export function useTaskPageWorkspaceActions(model: TaskPageSearchActionsModel) {
handleUseWorkItem(item)
return
}
const result = activateAndRevealWorktree(currentAttached.id)
const result = activateAndRevealWorktree(currentAttached.id, {
navigationIntent: 'user-open'
})
if (result === false) {
toast.error(
item.type === 'pr'
Expand Down
4 changes: 3 additions & 1 deletion src/renderer/src/components/use-terminal-watcher-effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { isTerminalWorkspaceEmptiedOnPurpose } from '../../../shared/closed-term
import { gateWorktreeAgentActivation } from '@/lib/worktree-agent-activation-gate'
import { createWorkspaceTerminalHostAuthoritySelector } from '@/lib/workspace-terminal-host-authority'
import { getStructuredAgentLaunchStatus } from '@/lib/structured-agent-session-launch'
import { isEmptyWorkspaceDefaultSurfacePending } from '@/lib/empty-workspace-default-surface-claims'
import { AGENT_SESSION_PROVIDER_HANDLE_PROVIDERS } from '../../../shared/agent-session-provider-handle'
import type { TerminalColdActivationController } from './terminal-cold-activation'
import { selectParkedEquivalentMountTabIds } from './terminal/startup-terminal-tab-hold'
Expand Down Expand Up @@ -229,8 +230,9 @@ export function useTerminalWatcherEffects(controller: TerminalWatcherController)
if (outcome !== 'empty') {
return
}
// A pending or unanswered chat create owns the surface even before its tab is published.
// A reseed awaiting agent detection, or a pending chat create, owns the surface already.
if (
isEmptyWorkspaceDefaultSurfacePending(activeWorktreeId) ||
AGENT_SESSION_PROVIDER_HANDLE_PROVIDERS.some(
(agent) => getStructuredAgentLaunchStatus(activeWorktreeId, agent) !== 'idle'
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ export function useWorktreeJumpPaletteSelectionActions({
)
return
}
const activation = activateAndRevealWorktree(
worktree.id,
executionHostId ? { executionHostId } : {}
)
const activation = activateAndRevealWorktree(worktree.id, {
navigationIntent: 'user-open',
...(executionHostId ? { executionHostId } : {})
})
recordFeatureInteraction('cmd-j-workspace-open')
skipRestoreFocusRef.current = true
closeModal()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,10 @@ export function registerWorkspaceShortcutIpcBridge(unsubs: (() => void)[]): void
const visibleTargets = getVisibleWorktreeShortcutTargets()
const target = visibleTargets[index]
if (target) {
if (target.executionHostId) {
activateAndRevealWorkspace(target.id, { executionHostId: target.executionHostId })
} else {
activateAndRevealWorkspace(target.id)
}
activateAndRevealWorkspace(target.id, {
navigationIntent: 'user-open',
...(target.executionHostId ? { executionHostId: target.executionHostId } : {})
})
}
})
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ describe('useIpcEvents digit-chord routing while Cmd+J is open', () => {

expect(rowJumps).toEqual([])
// Why assert the activation and not just the silent bus: a premature return would also emit nothing.
expect(harness.activateAndRevealWorkspace).toHaveBeenCalledWith('wt-c')
expect(harness.activateAndRevealWorkspace).toHaveBeenCalledWith('wt-c', {
navigationIntent: 'user-open'
})
})

it('routes duplicate ids at different positions to their rendered hosts', async () => {
Expand All @@ -67,6 +69,7 @@ describe('useIpcEvents digit-chord routing while Cmd+J is open', () => {
harness.jumpToWorktreeIndex(1)

expect(harness.activateAndRevealWorkspace).toHaveBeenCalledWith('repo::path', {
navigationIntent: 'user-open',
executionHostId: 'ssh:box'
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('agent launch caller profiles', () => {
const ids = AGENT_LAUNCH_CALLER_PROFILES.map((profile) => profile.id)

expect(new Set(ids).size).toBe(ids.length)
expect(ids.length).toBe(12)
expect(ids.length).toBe(13)
})

it.each(AGENT_LAUNCH_CALLER_PROFILES.map((profile) => [profile.id, profile] as const))(
Expand Down Expand Up @@ -70,6 +70,7 @@ describe('agent launch caller profiles', () => {
// Why: this is the coupling a move to an async launch RPC threatens most directly — these
// call sites cannot tolerate a tab id that only exists after the launch settles.
expect(readers.sort()).toEqual([
'empty-workspace-default-chat',
'fix-checks',
'floating-default-agent',
'quick-command',
Expand Down
15 changes: 15 additions & 0 deletions src/renderer/src/lib/agent-launch-caller-profiles-test-harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ export const AGENT_LAUNCH_CALLER_PROFILES: readonly AgentLaunchCallerProfile[] =
passesOnPromptDelivered: false,
readsBack: ['null-only']
},
{
id: 'empty-workspace-default-chat',
caller: 'src/renderer/src/lib/empty-workspace-default-agent-chat.ts',
sourceMarkers: ["launchSource: 'unknown'", 'pendingActivationSpawn: true'],
args: {
agent: 'codex',
worktreeId: 'wt-1',
launchSource: 'unknown',
pendingActivationSpawn: true
},
passesBeforeSurfaceOpen: false,
passesLaunchPlan: true,
passesOnPromptDelivered: false,
readsBack: ['surface-tab-id']
},
{
id: 'floating-default-agent',
caller: 'src/renderer/src/components/floating-terminal/FloatingTerminalWindowControls.tsx',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const LAUNCH_AGENT_IN_NEW_TAB_CALLERS = [
'src/renderer/src/components/tab-bar/use-tab-bar-create-menu-controller.ts',
'src/renderer/src/components/terminal-pane/terminal-agent-session-fork.ts',
'src/renderer/src/components/use-terminal-create-actions.ts',
'src/renderer/src/lib/empty-workspace-default-agent-chat.ts',
'src/renderer/src/lib/fix-checks-agent-launch.ts',
'src/renderer/src/lib/launch-agent-session-continuation.ts',
'src/renderer/src/lib/run-quick-command-in-new-tab.ts'
Expand Down
Loading
Loading