mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
test: remove 36 low-value terminal lifecycle cases (#40503)
Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
This commit is contained in:
-172
@@ -55,96 +55,6 @@ export function registerPtyConnectionDeliberateSleepGuardTests(): void {
|
||||
await restoreTerminalTestGlobals()
|
||||
})
|
||||
|
||||
// Manual sleep retains tab.ptyId as a wake hint; unguarded remount would reattach and respawn its dead shell (#10205).
|
||||
it('does not reattach a slept pane through its retained session id', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks = await vi.importMock<PtyConnectionAgentTitleMocks>(
|
||||
'@/lib/agent-status/aggregation/worktree-agent-status'
|
||||
)
|
||||
const { markWorktreeSleepIntent } = await import('@/lib/worktree-sleep-intent')
|
||||
const transport = createMockTransport()
|
||||
transportFactoryQueue.push(transport)
|
||||
mockStoreState = {
|
||||
...mockStoreState,
|
||||
activeWorktreeId: 'wt-other',
|
||||
tabsByWorktree: { 'wt-1': [{ id: 'tab-slept', ptyId: 'wt-1@@dead' }] }
|
||||
}
|
||||
markWorktreeSleepIntent('wt-1')
|
||||
const deps = createDeps({
|
||||
tabId: 'tab-slept',
|
||||
restoredLeafId: LEAF_1,
|
||||
restoredPtyIdByLeafId: { [LEAF_1]: 'wt-1@@dead' },
|
||||
isVisibleRef: { current: false }
|
||||
})
|
||||
|
||||
connectPanePty(
|
||||
createPane(1) as never,
|
||||
createManager(1) as never,
|
||||
bindPaneAgentTitleMocks(deps as never, agentTitleMocks)
|
||||
)
|
||||
await flushAsyncTicks()
|
||||
|
||||
expect(transport.connect).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('does not fresh-spawn a slept pane that has no session id', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks2 = await vi.importMock<PtyConnectionAgentTitleMocks>(
|
||||
'@/lib/agent-status/aggregation/worktree-agent-status'
|
||||
)
|
||||
const { markWorktreeSleepIntent } = await import('@/lib/worktree-sleep-intent')
|
||||
const transport = createMockTransport()
|
||||
transportFactoryQueue.push(transport)
|
||||
mockStoreState = { ...mockStoreState, activeWorktreeId: 'wt-other' }
|
||||
markWorktreeSleepIntent('wt-1')
|
||||
const deps = createDeps({ tabId: 'tab-slept-bare', isVisibleRef: { current: false } })
|
||||
|
||||
connectPanePty(
|
||||
createPane(1) as never,
|
||||
createManager(1) as never,
|
||||
bindPaneAgentTitleMocks(deps as never, agentTitleMocks2)
|
||||
)
|
||||
await flushAsyncTicks()
|
||||
|
||||
expect(transport.connect).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('connects a waiting pane once the workspace is woken', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks3 = await vi.importMock<PtyConnectionAgentTitleMocks>(
|
||||
'@/lib/agent-status/aggregation/worktree-agent-status'
|
||||
)
|
||||
const { clearWorktreeSleepIntent, markWorktreeSleepIntent } =
|
||||
await import('@/lib/worktree-sleep-intent')
|
||||
const transport = createMockTransport()
|
||||
transportFactoryQueue.push(transport)
|
||||
mockStoreState = {
|
||||
...mockStoreState,
|
||||
activeWorktreeId: 'wt-other',
|
||||
tabsByWorktree: { 'wt-1': [{ id: 'tab-woken', ptyId: 'wt-1@@dead' }] }
|
||||
}
|
||||
markWorktreeSleepIntent('wt-1')
|
||||
const deps = createDeps({
|
||||
tabId: 'tab-woken',
|
||||
restoredLeafId: LEAF_1,
|
||||
restoredPtyIdByLeafId: { [LEAF_1]: 'wt-1@@dead' },
|
||||
isVisibleRef: { current: false }
|
||||
})
|
||||
|
||||
connectPanePty(
|
||||
createPane(1) as never,
|
||||
createManager(1) as never,
|
||||
bindPaneAgentTitleMocks(deps as never, agentTitleMocks3)
|
||||
)
|
||||
await flushAsyncTicks()
|
||||
expect(transport.connect).not.toHaveBeenCalled()
|
||||
|
||||
clearWorktreeSleepIntent('wt-1')
|
||||
await flushAsyncTicks()
|
||||
|
||||
expect(transport.connect).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('does not connect a waiting pane whose tab was remounted by the wake', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks4 = await vi.importMock<PtyConnectionAgentTitleMocks>(
|
||||
@@ -184,39 +94,6 @@ export function registerPtyConnectionDeliberateSleepGuardTests(): void {
|
||||
expect(transport.connect).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('resumes a waiting pane mounted under a unified tab id', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks5 = await vi.importMock<PtyConnectionAgentTitleMocks>(
|
||||
'@/lib/agent-status/aggregation/worktree-agent-status'
|
||||
)
|
||||
const { clearWorktreeSleepIntent, markWorktreeSleepIntent } =
|
||||
await import('@/lib/worktree-sleep-intent')
|
||||
const transport = createMockTransport()
|
||||
transportFactoryQueue.push(transport)
|
||||
mockStoreState = {
|
||||
...mockStoreState,
|
||||
activeWorktreeId: 'wt-other',
|
||||
tabsByWorktree: { 'wt-1': [{ id: 'tab-entity', ptyId: null, generation: 3 }] },
|
||||
getTab: (id: string) =>
|
||||
id === 'unified-1' ? { id, contentType: 'terminal', entityId: 'tab-entity' } : null
|
||||
} as never
|
||||
markWorktreeSleepIntent('wt-1')
|
||||
const deps = createDeps({ tabId: 'unified-1', isVisibleRef: { current: false } })
|
||||
|
||||
connectPanePty(
|
||||
createPane(1) as never,
|
||||
createManager(1) as never,
|
||||
bindPaneAgentTitleMocks(deps as never, agentTitleMocks5)
|
||||
)
|
||||
await flushAsyncTicks()
|
||||
expect(transport.connect).not.toHaveBeenCalled()
|
||||
|
||||
clearWorktreeSleepIntent('wt-1')
|
||||
await flushAsyncTicks()
|
||||
|
||||
expect(transport.connect).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('re-arms after a wake so a second sleep can hold the pane again', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks6 = await vi.importMock<PtyConnectionAgentTitleMocks>(
|
||||
@@ -299,54 +176,5 @@ export function registerPtyConnectionDeliberateSleepGuardTests(): void {
|
||||
subscribeSpy.mockRestore()
|
||||
}
|
||||
})
|
||||
|
||||
it('still connects a slept pane that carries a queued startup', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks8 = await vi.importMock<PtyConnectionAgentTitleMocks>(
|
||||
'@/lib/agent-status/aggregation/worktree-agent-status'
|
||||
)
|
||||
const { markWorktreeSleepIntent } = await import('@/lib/worktree-sleep-intent')
|
||||
const transport = createMockTransport()
|
||||
transportFactoryQueue.push(transport)
|
||||
markWorktreeSleepIntent('wt-1')
|
||||
const deps = createDeps({
|
||||
tabId: 'tab-slept-startup',
|
||||
isVisibleRef: { current: false },
|
||||
startup: { command: 'printf wake', launchAgent: undefined }
|
||||
})
|
||||
|
||||
connectPanePty(
|
||||
createPane(1) as never,
|
||||
createManager(1) as never,
|
||||
bindPaneAgentTitleMocks(deps as never, agentTitleMocks8)
|
||||
)
|
||||
await flushAsyncTicks()
|
||||
|
||||
expect(transport.connect).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('connects normally once the marker is released', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks9 = await vi.importMock<PtyConnectionAgentTitleMocks>(
|
||||
'@/lib/agent-status/aggregation/worktree-agent-status'
|
||||
)
|
||||
const transport = createMockTransport()
|
||||
transportFactoryQueue.push(transport)
|
||||
const deps = createDeps({
|
||||
tabId: 'tab-awake',
|
||||
restoredLeafId: LEAF_1,
|
||||
restoredPtyIdByLeafId: { [LEAF_1]: 'wt-1@@live' },
|
||||
isVisibleRef: { current: false }
|
||||
})
|
||||
|
||||
connectPanePty(
|
||||
createPane(1) as never,
|
||||
createManager(1) as never,
|
||||
bindPaneAgentTitleMocks(deps as never, agentTitleMocks9)
|
||||
)
|
||||
await flushAsyncTicks()
|
||||
|
||||
expect(transport.connect).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
-312
@@ -12,12 +12,10 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { ORCA_LAYOUT_OWNER_IS_MAIN } from '../../../../../../shared/layout-owner-switch'
|
||||
|
||||
import {
|
||||
LEAF_2,
|
||||
leafIdForPane,
|
||||
createMockTransport,
|
||||
createPane,
|
||||
createManager,
|
||||
type ConnectCallbacks,
|
||||
type MockTransport
|
||||
} from '../test-fixtures/pty-connection-test-pane-fixtures'
|
||||
import {
|
||||
@@ -67,235 +65,6 @@ export function registerPtyConnectionHibernationWakeTests(): void {
|
||||
await restoreTerminalTestGlobals()
|
||||
})
|
||||
|
||||
it('disarms input modes and resumes a hibernated agent session on visibility reveal', async () => {
|
||||
// Regression: hibernation suppresses its kill's PTY exit while hidden; before the wake fix onExit permanently latched handledExitPtyId, leaving a frozen inert ghost pane on reveal.
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks = await vi.importMock<PtyConnectionAgentTitleMocks>(
|
||||
'@/lib/agent-status/aggregation/worktree-agent-status'
|
||||
)
|
||||
const transport = createMockTransport('pty-pane-2')
|
||||
transportFactoryQueue.push(transport)
|
||||
const manager = createManager(1)
|
||||
// Hibernation only targets hidden panes, so the exit lands while not visible and the wake must wait for the reveal.
|
||||
const deps = createDeps({
|
||||
consumeSuppressedPtyExit: vi.fn(() => true),
|
||||
isVisibleRef: { current: false }
|
||||
})
|
||||
const pane = createPane(2)
|
||||
const paneKey = `tab-1:${leafIdForPane(2)}`
|
||||
if (ORCA_LAYOUT_OWNER_IS_MAIN) {
|
||||
await mainStartsPaneAs({
|
||||
ptyId: 'pty-main',
|
||||
bind: bindsPaneInStore(() => mockStoreState, 'tab-1', leafIdForPane(2))
|
||||
})
|
||||
}
|
||||
mockStoreState.sleepingAgentSessionsByPaneKey[paneKey] = {
|
||||
paneKey,
|
||||
tabId: 'tab-1',
|
||||
worktreeId: 'wt-1',
|
||||
agent: 'claude',
|
||||
providerSession: { key: 'session_id', id: 'sess-hibernated-1' },
|
||||
prompt: 'test prompt',
|
||||
state: 'done',
|
||||
capturedAt: 1,
|
||||
updatedAt: 1,
|
||||
origin: 'worktree-sleep'
|
||||
}
|
||||
mockStoreState.suppressedPtyExitIds['tab-pty'] = true
|
||||
|
||||
const binding = connectPanePty(
|
||||
...mockPanePtyArgs(pane, manager, bindPaneAgentTitleMocks(deps, agentTitleMocks))
|
||||
)
|
||||
await flushAsyncTicks()
|
||||
|
||||
const onPtyExit = createdTransportOptions[0]?.onPtyExit as
|
||||
| ((ptyId: string) => void)
|
||||
| undefined
|
||||
expect(onPtyExit).toBeTypeOf('function')
|
||||
// The deferred connect attached this transport to the persisted tab PTY, so the kill's exit must carry that id for the wake guard's same-pty check.
|
||||
expect((transport.getPtyId as unknown as () => string | null)()).toBe('tab-pty')
|
||||
const connectCallsBeforeExit = transport.connect.mock.calls.length
|
||||
onPtyExit?.('tab-pty')
|
||||
await flushAsyncTicks()
|
||||
|
||||
// The frozen frame's input-eating modes are disarmed at hibernation-exit (mouse tracking / bracketed paste would otherwise swallow clicks).
|
||||
const writesAfterExit = pane.terminal.write.mock.calls.flat().join('')
|
||||
expect(writesAfterExit).toContain('\x1b[?1003l')
|
||||
expect(writesAfterExit).toContain('\x1b[?2004l')
|
||||
// A hidden pane must not respawn on exit — the wake waits for the reveal.
|
||||
expect(transport.connect.mock.calls.length).toBe(connectCallsBeforeExit)
|
||||
|
||||
binding.noteVisibilityResume()
|
||||
await flushAsyncTicks()
|
||||
|
||||
if (ORCA_LAYOUT_OWNER_IS_MAIN) {
|
||||
// The wake asks main to start the pane; the window attaches to what main binds.
|
||||
await expectWindowStartAskedMain(transport, paneKey)
|
||||
expect(transport.connect).toHaveBeenLastCalledWith(
|
||||
expect.objectContaining({ sessionId: 'pty-main', attachOnlyView: true })
|
||||
)
|
||||
binding.noteVisibilityResume()
|
||||
await flushAsyncTicks()
|
||||
expect((await mainLayoutApplyTransport()).sentOfType('startPane')).toHaveLength(1)
|
||||
return
|
||||
}
|
||||
expect(transport.connect.mock.calls.length).toBeGreaterThan(connectCallsBeforeExit)
|
||||
const resumeConnectOptions = transport.connect.mock.calls.at(-1)?.[0] as
|
||||
| { command?: string }
|
||||
| undefined
|
||||
expect(resumeConnectOptions?.command).toContain('--resume')
|
||||
expect(resumeConnectOptions?.command).toContain('sess-hibernated-1')
|
||||
|
||||
const connectCallsAfterWake = transport.connect.mock.calls.length
|
||||
binding.noteVisibilityResume()
|
||||
await flushAsyncTicks()
|
||||
expect(transport.connect.mock.calls.length).toBe(connectCallsAfterWake)
|
||||
})
|
||||
|
||||
// A suppressed exit over a finished turn’s live anchor still arms reveal resume despite its worktree-sleep note (#16308).
|
||||
it('arms an in-place resume from a finished turn idle anchor on a suppressed exit', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks2 = await vi.importMock<PtyConnectionAgentTitleMocks>(
|
||||
'@/lib/agent-status/aggregation/worktree-agent-status'
|
||||
)
|
||||
const transport = createMockTransport('pty-pane-2')
|
||||
transportFactoryQueue.push(transport)
|
||||
const deps = createDeps({
|
||||
consumeSuppressedPtyExit: vi.fn(() => true),
|
||||
isVisibleRef: { current: false }
|
||||
})
|
||||
const pane = createPane(2)
|
||||
const paneKey = `tab-1:${leafIdForPane(2)}`
|
||||
if (ORCA_LAYOUT_OWNER_IS_MAIN) {
|
||||
await mainStartsPaneAs({
|
||||
ptyId: 'pty-main',
|
||||
bind: bindsPaneInStore(() => mockStoreState, 'tab-1', leafIdForPane(2))
|
||||
})
|
||||
}
|
||||
mockStoreState.sleepingAgentSessionsByPaneKey[paneKey] = {
|
||||
paneKey,
|
||||
tabId: 'tab-1',
|
||||
worktreeId: 'wt-1',
|
||||
agent: 'claude',
|
||||
providerSession: { key: 'session_id', id: 'sess-idle-anchor' },
|
||||
prompt: '',
|
||||
state: 'done',
|
||||
capturedAt: 1,
|
||||
updatedAt: 1,
|
||||
origin: 'live'
|
||||
}
|
||||
mockStoreState.suppressedPtyExitIds['tab-pty'] = true
|
||||
const args = mockPanePtyArgs(pane, createManager(1), deps)
|
||||
bindPaneAgentTitleMocks(args[2], agentTitleMocks2)
|
||||
|
||||
const binding = connectPanePty(...args)
|
||||
await flushAsyncTicks()
|
||||
const onPtyExit = createdTransportOptions[0]?.onPtyExit
|
||||
expect(onPtyExit).toBeTypeOf('function')
|
||||
const connectCallsBeforeExit = transport.connect.mock.calls.length
|
||||
if (typeof onPtyExit === 'function') {
|
||||
onPtyExit('tab-pty')
|
||||
}
|
||||
await flushAsyncTicks()
|
||||
|
||||
binding.noteVisibilityResume()
|
||||
await flushAsyncTicks()
|
||||
|
||||
if (ORCA_LAYOUT_OWNER_IS_MAIN) {
|
||||
await expectWindowStartAskedMain(transport, paneKey)
|
||||
expect(transport.connect).toHaveBeenLastCalledWith(
|
||||
expect.objectContaining({ sessionId: 'pty-main', attachOnlyView: true })
|
||||
)
|
||||
return
|
||||
}
|
||||
const resumeConnectOptions: { command?: string } | undefined =
|
||||
transport.connect.mock.calls.at(-1)?.[0]
|
||||
expect(transport.connect.mock.calls.length).toBeGreaterThan(connectCallsBeforeExit)
|
||||
expect(resumeConnectOptions?.command).toContain('sess-idle-anchor')
|
||||
})
|
||||
|
||||
it('resumes a hibernated agent from a navigation-free wake without a visibility reveal', async () => {
|
||||
// Mobile wakes hidden panes without visibility changes; duplicate wake events must resume exactly once (INV-1).
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks3 = await vi.importMock<PtyConnectionAgentTitleMocks>(
|
||||
'@/lib/agent-status/aggregation/worktree-agent-status'
|
||||
)
|
||||
const transport = createMockTransport('pty-pane-2')
|
||||
transportFactoryQueue.push(transport)
|
||||
const manager = createManager(1)
|
||||
const deps = createDeps({
|
||||
consumeSuppressedPtyExit: vi.fn(() => true),
|
||||
isVisibleRef: { current: false }
|
||||
})
|
||||
const pane = createPane(2)
|
||||
const paneKey = `tab-1:${leafIdForPane(2)}`
|
||||
if (ORCA_LAYOUT_OWNER_IS_MAIN) {
|
||||
await mainStartsPaneAs({
|
||||
ptyId: 'pty-main',
|
||||
bind: bindsPaneInStore(() => mockStoreState, 'tab-1', leafIdForPane(2))
|
||||
})
|
||||
}
|
||||
mockStoreState.sleepingAgentSessionsByPaneKey[paneKey] = {
|
||||
paneKey,
|
||||
tabId: 'tab-1',
|
||||
worktreeId: 'wt-1',
|
||||
agent: 'claude',
|
||||
providerSession: { key: 'session_id', id: 'sess-hibernated-bg' },
|
||||
prompt: 'test prompt',
|
||||
state: 'done',
|
||||
capturedAt: 1,
|
||||
updatedAt: 1,
|
||||
origin: 'worktree-sleep'
|
||||
}
|
||||
mockStoreState.suppressedPtyExitIds['tab-pty'] = true
|
||||
|
||||
const binding = connectPanePty(
|
||||
...mockPanePtyArgs(pane, manager, bindPaneAgentTitleMocks(deps, agentTitleMocks3))
|
||||
)
|
||||
await flushAsyncTicks()
|
||||
|
||||
const onPtyExit = createdTransportOptions[0]?.onPtyExit as
|
||||
| ((ptyId: string) => void)
|
||||
| undefined
|
||||
expect((transport.getPtyId as unknown as () => string | null)()).toBe('tab-pty')
|
||||
const connectCallsBeforeExit = transport.connect.mock.calls.length
|
||||
onPtyExit?.('tab-pty')
|
||||
await flushAsyncTicks()
|
||||
// Still hidden: no reveal happened, so nothing respawned on exit.
|
||||
expect(transport.connect.mock.calls.length).toBe(connectCallsBeforeExit)
|
||||
|
||||
// The wake reports the claim it consumed so the dispatcher's generic resume never launches the same provider session into a second tab.
|
||||
const claimKey = 'wt-1\0claude\0session_id\0sess-hibernated-bg'
|
||||
expect(binding.wakeHibernatedAgentIfArmed(new Set([claimKey]))).toBeNull()
|
||||
expect(transport.connect.mock.calls.length).toBe(connectCallsBeforeExit)
|
||||
const claimedProviderSessions = new Set<string>()
|
||||
expect(binding.wakeHibernatedAgentIfArmed(claimedProviderSessions)).toBe(claimKey)
|
||||
expect(claimedProviderSessions).toEqual(new Set([claimKey]))
|
||||
await flushAsyncTicks()
|
||||
|
||||
if (ORCA_LAYOUT_OWNER_IS_MAIN) {
|
||||
await expectWindowStartAskedMain(transport, paneKey)
|
||||
expect(transport.connect).toHaveBeenLastCalledWith(
|
||||
expect.objectContaining({ sessionId: 'pty-main', attachOnlyView: true })
|
||||
)
|
||||
binding.wakeHibernatedAgentIfArmed()
|
||||
await flushAsyncTicks()
|
||||
expect((await mainLayoutApplyTransport()).sentOfType('startPane')).toHaveLength(1)
|
||||
return
|
||||
}
|
||||
expect(transport.connect.mock.calls.length).toBeGreaterThan(connectCallsBeforeExit)
|
||||
const resumeConnectOptions = transport.connect.mock.calls.at(-1)?.[0] as
|
||||
| { command?: string }
|
||||
| undefined
|
||||
expect(resumeConnectOptions?.command).toContain('--resume')
|
||||
expect(resumeConnectOptions?.command).toContain('sess-hibernated-bg')
|
||||
|
||||
const connectCallsAfterWake = transport.connect.mock.calls.length
|
||||
binding.wakeHibernatedAgentIfArmed()
|
||||
await flushAsyncTicks()
|
||||
expect(transport.connect.mock.calls.length).toBe(connectCallsAfterWake)
|
||||
})
|
||||
|
||||
it('names the replaced PTY on the restart spawn only, never on a later wake of the same pane', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks4 = await vi.importMock<PtyConnectionAgentTitleMocks>(
|
||||
@@ -376,52 +145,6 @@ export function registerPtyConnectionHibernationWakeTests(): void {
|
||||
await flushAsyncTicks()
|
||||
expect(window.api.pty.kill).not.toHaveBeenCalledWith('pty-replaced')
|
||||
})
|
||||
|
||||
it('keeps an established split pane mounted when main labels its exit as a restart replacement', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks5 = await vi.importMock<PtyConnectionAgentTitleMocks>(
|
||||
'@/lib/agent-status/aggregation/worktree-agent-status'
|
||||
)
|
||||
const { deliverPtyExitToHandlers } =
|
||||
await import('../../pty-transport/delivery/pty-exit-delivery')
|
||||
let onData: ((data: string) => void) | undefined
|
||||
const transport = createMockTransport('pty-pane-2')
|
||||
transport.connect.mockImplementation(
|
||||
async ({ callbacks }: { callbacks: ConnectCallbacks }) => {
|
||||
onData = callbacks.onData
|
||||
return 'pty-pane-2'
|
||||
}
|
||||
)
|
||||
transportFactoryQueue.push(transport)
|
||||
const manager = createManager(2)
|
||||
const deps = createDeps({
|
||||
restoredLeafId: LEAF_2,
|
||||
paneTransportsRef: { current: new Map([[1, createMockTransport('pty-pane-1')]]) }
|
||||
})
|
||||
const args = mockPanePtyArgs(createPane(2), manager, deps)
|
||||
bindPaneAgentTitleMocks(args[2], agentTitleMocks5)
|
||||
|
||||
connectPanePty(...args)
|
||||
const onPtyExit = createdTransportOptions[0]?.onPtyExit
|
||||
expect(onPtyExit).toBeTypeOf('function')
|
||||
await flushAsyncTicks()
|
||||
onData?.('codex prompt')
|
||||
|
||||
deliverPtyExitToHandlers({
|
||||
ptyId: 'pty-pane-2',
|
||||
code: 0,
|
||||
replacedByRestart: true,
|
||||
primary: (code) => {
|
||||
if (typeof onPtyExit === 'function') {
|
||||
onPtyExit('pty-pane-2', code)
|
||||
}
|
||||
},
|
||||
sidecars: []
|
||||
})
|
||||
|
||||
expect(manager.closePane).not.toHaveBeenCalled()
|
||||
expect(deps.clearExitedPanePtyLayoutBinding).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -666,41 +389,6 @@ export function registerPtyConnectionHibernationWakeClaimTests(): void {
|
||||
expect(transport.connect.mock.calls.length).toBe(connectCallsAfterFailure + 1)
|
||||
})
|
||||
|
||||
it('does not latch a stale sleeping record beside an unsuppressed live PTY', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks10 = await vi.importMock<PtyConnectionAgentTitleMocks>(
|
||||
'@/lib/agent-status/aggregation/worktree-agent-status'
|
||||
)
|
||||
const transport = createMockTransport('pty-pane-2')
|
||||
transportFactoryQueue.push(transport)
|
||||
const paneKey = `tab-1:${leafIdForPane(2)}`
|
||||
mockStoreState.sleepingAgentSessionsByPaneKey[paneKey] = {
|
||||
paneKey,
|
||||
tabId: 'tab-1',
|
||||
worktreeId: 'wt-1',
|
||||
agent: 'claude',
|
||||
providerSession: { key: 'session_id', id: 'sess-stale' },
|
||||
prompt: 'test prompt',
|
||||
state: 'done',
|
||||
capturedAt: 1,
|
||||
updatedAt: 1,
|
||||
origin: 'worktree-sleep'
|
||||
}
|
||||
const binding = connectPanePty(
|
||||
...mockPanePtyArgs(
|
||||
createPane(2),
|
||||
createManager(1),
|
||||
bindPaneAgentTitleMocks(
|
||||
createDeps({ isVisibleRef: { current: false } }),
|
||||
agentTitleMocks10
|
||||
)
|
||||
)
|
||||
)
|
||||
await flushAsyncTicks()
|
||||
|
||||
expect(binding.wakeHibernatedAgentIfArmed()).toBeNull()
|
||||
})
|
||||
|
||||
it('auto-resumes a hibernated pane when its kill lands after the pane is already revealed', async () => {
|
||||
// If reveal precedes wake arming, the arm-time visibility check must resume the pane immediately.
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
|
||||
-263
@@ -5,7 +5,6 @@ import { ORCA_LAYOUT_OWNER_IS_MAIN } from '../../../../../../shared/layout-owner
|
||||
import {
|
||||
bindsPaneInStore,
|
||||
expectNoWindowStart,
|
||||
expectWindowStartAskedMain,
|
||||
mainLayoutApplyTransport,
|
||||
mainStartsPaneAs
|
||||
} from '../test-fixtures/pty-connection-test-main-pane-start-fixtures'
|
||||
@@ -130,17 +129,6 @@ export function registerPtyConnectionHiddenSleepingResumeTests(): void {
|
||||
vi.mocked(window.api.pty.hasPty).mockResolvedValue(isLive)
|
||||
}
|
||||
|
||||
function resumeCommands(transport: MockTransport): (string | undefined)[] {
|
||||
return transport.connect.mock.calls.map((call) => call[0]?.command)
|
||||
}
|
||||
|
||||
async function expectAttachedToMainStart(transport: MockTransport): Promise<void> {
|
||||
await expectWindowStartAskedMain(transport, PANE_KEY, mockStoreState)
|
||||
expect(transport.connect).toHaveBeenLastCalledWith(
|
||||
expect.objectContaining({ sessionId: MAIN_PTY_ID, attachOnlyView: true })
|
||||
)
|
||||
}
|
||||
|
||||
describe('connectPanePty', () => {
|
||||
beforeEach(async () => {
|
||||
vi.clearAllMocks()
|
||||
@@ -170,213 +158,6 @@ export function registerPtyConnectionHiddenSleepingResumeTests(): void {
|
||||
await restoreTerminalTestGlobals()
|
||||
})
|
||||
|
||||
it('waits for the reveal before resuming a hidden pane that has no PTY to reattach', async () => {
|
||||
seedSleepingPane(null)
|
||||
const { transport, binding, isVisibleRef } = connectHiddenPane(
|
||||
null,
|
||||
await vi.importMock<PtyConnectionAgentTitleMocks>(
|
||||
'@/lib/agent-status/aggregation/worktree-agent-status'
|
||||
)
|
||||
)
|
||||
await flushAsyncTicks(10)
|
||||
|
||||
expect(transport.connect).not.toHaveBeenCalled()
|
||||
expect(mockStoreState.sleepingAgentSessionsByPaneKey[PANE_KEY]).toBeDefined()
|
||||
|
||||
isVisibleRef.current = true
|
||||
binding.noteVisibilityResume()
|
||||
await flushAsyncTicks(10)
|
||||
|
||||
expect(transport.connect).toHaveBeenCalledTimes(1)
|
||||
if (ORCA_LAYOUT_OWNER_IS_MAIN) {
|
||||
await expectAttachedToMainStart(transport)
|
||||
return
|
||||
}
|
||||
expect(resumeCommands(transport)[0]).toContain("'resume' 'codex-session-1'")
|
||||
})
|
||||
|
||||
it('holds a hidden reattach the host reports gone, then reattaches it on reveal', async () => {
|
||||
seedSleepingPane(DEAD_SESSION_ID)
|
||||
setHostLiveness(false)
|
||||
const { transport, binding, isVisibleRef } = connectHiddenPane(
|
||||
DEAD_SESSION_ID,
|
||||
await vi.importMock<PtyConnectionAgentTitleMocks>(
|
||||
'@/lib/agent-status/aggregation/worktree-agent-status'
|
||||
)
|
||||
)
|
||||
await flushAsyncTicks(10)
|
||||
|
||||
expect(transport.connect).not.toHaveBeenCalled()
|
||||
|
||||
isVisibleRef.current = true
|
||||
binding.noteVisibilityResume()
|
||||
await flushAsyncTicks(10)
|
||||
|
||||
expect(transport.connect).toHaveBeenCalledTimes(1)
|
||||
// The reveal takes the same reattach a visible pane would, so the host restores its scrollback.
|
||||
expect(transport.connect.mock.calls[0]?.[0]).toMatchObject({ sessionId: DEAD_SESSION_ID })
|
||||
if (ORCA_LAYOUT_OWNER_IS_MAIN) {
|
||||
expect(transport.connect.mock.calls[0]?.[0]).toMatchObject({ attachOnlyView: true })
|
||||
expectNoWindowStart(transport, mockStoreState)
|
||||
return
|
||||
}
|
||||
expect(resumeCommands(transport)[0]).toContain("'resume' 'codex-session-1'")
|
||||
})
|
||||
|
||||
it.each([
|
||||
['live', true],
|
||||
['unverifiable', null]
|
||||
] as const)('reattaches a hidden %s session at mount', async (_label, isLive) => {
|
||||
seedSleepingPane(DEAD_SESSION_ID)
|
||||
setHostLiveness(isLive)
|
||||
const { transport } = connectHiddenPane(
|
||||
DEAD_SESSION_ID,
|
||||
await vi.importMock<PtyConnectionAgentTitleMocks>(
|
||||
'@/lib/agent-status/aggregation/worktree-agent-status'
|
||||
)
|
||||
)
|
||||
await flushAsyncTicks(10)
|
||||
|
||||
expect(transport.connect).toHaveBeenCalledTimes(1)
|
||||
expect(transport.connect.mock.calls[0]?.[0]).toMatchObject({ sessionId: DEAD_SESSION_ID })
|
||||
})
|
||||
|
||||
it('resumes a hidden pane at mount when a background mount asked for its tab', async () => {
|
||||
seedSleepingPane(null)
|
||||
const { requestSleepingAgentWakeOnMount } = await import('@/lib/sleeping-agent-wake-requests')
|
||||
requestSleepingAgentWakeOnMount('wt-1', ['tab-1'])
|
||||
const { transport } = connectHiddenPane(
|
||||
null,
|
||||
await vi.importMock<PtyConnectionAgentTitleMocks>(
|
||||
'@/lib/agent-status/aggregation/worktree-agent-status'
|
||||
)
|
||||
)
|
||||
await flushAsyncTicks(10)
|
||||
|
||||
expect(transport.connect).toHaveBeenCalledTimes(1)
|
||||
if (ORCA_LAYOUT_OWNER_IS_MAIN) {
|
||||
await expectAttachedToMainStart(transport)
|
||||
return
|
||||
}
|
||||
expect(resumeCommands(transport)[0]).toContain("'resume' 'codex-session-1'")
|
||||
})
|
||||
|
||||
it('keeps an initial hidden workspace-sleep wake explicit', async () => {
|
||||
seedSleepingPane(null, { origin: 'worktree-sleep' })
|
||||
const resumeSleptPane = vi.fn(async () => true)
|
||||
window.api.worktrees = { ...window.api.worktrees, resumeSleptPane }
|
||||
const { requestSleepingAgentWakeOnMount } = await import('@/lib/sleeping-agent-wake-requests')
|
||||
requestSleepingAgentWakeOnMount('wt-1', ['tab-1'])
|
||||
connectHiddenPane(
|
||||
null,
|
||||
await vi.importMock<PtyConnectionAgentTitleMocks>(
|
||||
'@/lib/agent-status/aggregation/worktree-agent-status'
|
||||
)
|
||||
)
|
||||
await flushAsyncTicks(20)
|
||||
expect(resumeSleptPane).toHaveBeenCalledWith(
|
||||
{ worktreeId: 'wt-1', tabId: 'tab-1', leafId: LEAF_2 },
|
||||
undefined
|
||||
)
|
||||
})
|
||||
|
||||
it('resumes a held hidden pane immediately on a phone wake', async () => {
|
||||
seedSleepingPane(DEAD_SESSION_ID)
|
||||
setHostLiveness(false)
|
||||
const { transport, binding } = connectHiddenPane(
|
||||
DEAD_SESSION_ID,
|
||||
await vi.importMock<PtyConnectionAgentTitleMocks>(
|
||||
'@/lib/agent-status/aggregation/worktree-agent-status'
|
||||
)
|
||||
)
|
||||
await flushAsyncTicks(10)
|
||||
expect(transport.connect).not.toHaveBeenCalled()
|
||||
|
||||
const claimed = new Set<string>()
|
||||
expect(binding.wakeHibernatedAgentIfArmed(claimed)).not.toBeNull()
|
||||
expect(binding.wakeHibernatedAgentIfArmed(claimed)).toBeNull()
|
||||
await flushAsyncTicks(10)
|
||||
|
||||
expect(transport.connect).toHaveBeenCalledTimes(1)
|
||||
expect(transport.connect.mock.calls[0]?.[0]).toMatchObject({ sessionId: DEAD_SESSION_ID })
|
||||
})
|
||||
|
||||
it('owns its record while held, so an activation sweep does not relaunch it elsewhere', async () => {
|
||||
seedSleepingPane(null)
|
||||
const { isPaneSpawnDeferred } = await import('@/lib/pane-spawn-deferral-registry')
|
||||
const { binding, isVisibleRef } = connectHiddenPane(
|
||||
null,
|
||||
await vi.importMock<PtyConnectionAgentTitleMocks>(
|
||||
'@/lib/agent-status/aggregation/worktree-agent-status'
|
||||
)
|
||||
)
|
||||
await flushAsyncTicks(10)
|
||||
expect(isPaneSpawnDeferred(PANE_KEY)).toBe(true)
|
||||
|
||||
isVisibleRef.current = true
|
||||
binding.noteVisibilityResume()
|
||||
await flushAsyncTicks(10)
|
||||
expect(isPaneSpawnDeferred(PANE_KEY)).toBe(false)
|
||||
})
|
||||
|
||||
it('keeps a background wake released through a failed reattach fallback', async () => {
|
||||
seedSleepingPane(DEAD_SESSION_ID)
|
||||
setHostLiveness(false)
|
||||
const { requestSleepingAgentWakeOnMount } = await import('@/lib/sleeping-agent-wake-requests')
|
||||
requestSleepingAgentWakeOnMount('wt-1', ['tab-1'])
|
||||
const transport = createMockTransport()
|
||||
// The reattach comes back with no PTY, so the pane falls back to a fresh resume.
|
||||
transport.connect.mockResolvedValueOnce(undefined).mockResolvedValue('resumed-pty')
|
||||
transportFactoryQueue.push(transport)
|
||||
connectPane(
|
||||
buildPaneConnectionDeps(() => mockStoreState, {
|
||||
restoredLeafId: LEAF_2,
|
||||
restoredPtyIdByLeafId: { [LEAF_2]: DEAD_SESSION_ID },
|
||||
isVisibleRef: { current: false }
|
||||
}),
|
||||
await vi.importMock<PtyConnectionAgentTitleMocks>(
|
||||
'@/lib/agent-status/aggregation/worktree-agent-status'
|
||||
)
|
||||
)
|
||||
await flushAsyncTicks(20)
|
||||
|
||||
expect(transport.connect).toHaveBeenCalledTimes(2)
|
||||
if (ORCA_LAYOUT_OWNER_IS_MAIN) {
|
||||
await expectAttachedToMainStart(transport)
|
||||
return
|
||||
}
|
||||
expect(resumeCommands(transport)[1]).toContain("'resume' 'codex-session-1'")
|
||||
})
|
||||
|
||||
it('keeps owning its record while the woken resume is still starting', async () => {
|
||||
seedSleepingPane(null)
|
||||
const { isPaneSpawnDeferred } = await import('@/lib/pane-spawn-deferral-registry')
|
||||
const spawn = createDeferred<string>()
|
||||
const { transport, binding, isVisibleRef } = connectHiddenPane(
|
||||
null,
|
||||
await vi.importMock<PtyConnectionAgentTitleMocks>(
|
||||
'@/lib/agent-status/aggregation/worktree-agent-status'
|
||||
)
|
||||
)
|
||||
transport.connect.mockImplementation(() =>
|
||||
spawn.promise.then((ptyId) => {
|
||||
transport.getPtyId.mockReturnValue(ptyId)
|
||||
return ptyId
|
||||
})
|
||||
)
|
||||
await flushAsyncTicks(10)
|
||||
|
||||
isVisibleRef.current = true
|
||||
binding.noteVisibilityResume()
|
||||
await flushAsyncTicks(10)
|
||||
expect(transport.connect).toHaveBeenCalledTimes(1)
|
||||
expect(isPaneSpawnDeferred(PANE_KEY)).toBe(true)
|
||||
|
||||
spawn.resolve('resumed-pty')
|
||||
await flushAsyncTicks(10)
|
||||
expect(isPaneSpawnDeferred(PANE_KEY)).toBe(false)
|
||||
})
|
||||
|
||||
it('does not count a later in-session sleep of the woken pane as held', async () => {
|
||||
seedSleepingPane(null)
|
||||
const { isPaneSpawnDeferred } = await import('@/lib/pane-spawn-deferral-registry')
|
||||
@@ -424,29 +205,6 @@ export function registerPtyConnectionHiddenSleepingResumeTests(): void {
|
||||
}
|
||||
})
|
||||
|
||||
it('resumes a held pane whose record was re-captured for the same session', async () => {
|
||||
seedSleepingPane(null)
|
||||
const { transport, binding, isVisibleRef } = connectHiddenPane(
|
||||
null,
|
||||
await vi.importMock<PtyConnectionAgentTitleMocks>(
|
||||
'@/lib/agent-status/aggregation/worktree-agent-status'
|
||||
)
|
||||
)
|
||||
await flushAsyncTicks(10)
|
||||
const held = mockStoreState.sleepingAgentSessionsByPaneKey[PANE_KEY]!
|
||||
mockStoreState.sleepingAgentSessionsByPaneKey[PANE_KEY] = { ...held, updatedAt: 2 }
|
||||
|
||||
isVisibleRef.current = true
|
||||
binding.noteVisibilityResume()
|
||||
await flushAsyncTicks(10)
|
||||
|
||||
if (ORCA_LAYOUT_OWNER_IS_MAIN) {
|
||||
await expectAttachedToMainStart(transport)
|
||||
return
|
||||
}
|
||||
expect(resumeCommands(transport)[0]).toContain("'resume' 'codex-session-1'")
|
||||
})
|
||||
|
||||
it('drops a held wake once the record names a different session', async () => {
|
||||
seedSleepingPane(null)
|
||||
const { transport, binding, isVisibleRef } = connectHiddenPane(
|
||||
@@ -499,26 +257,5 @@ export function registerPtyConnectionHiddenSleepingResumeTests(): void {
|
||||
await flushAsyncTicks(10)
|
||||
expect(isPaneSpawnDeferred(PANE_KEY)).toBe(false)
|
||||
})
|
||||
|
||||
it('keeps holding when an exit lands that its held wake did not start', async () => {
|
||||
seedSleepingPane(null)
|
||||
const { isPaneSpawnDeferred } = await import('@/lib/pane-spawn-deferral-registry')
|
||||
connectHiddenPane(
|
||||
null,
|
||||
await vi.importMock<PtyConnectionAgentTitleMocks>(
|
||||
'@/lib/agent-status/aggregation/worktree-agent-status'
|
||||
)
|
||||
)
|
||||
await flushAsyncTicks(10)
|
||||
const onPtyExit = createdTransportOptions[0]?.onPtyExit
|
||||
if (typeof onPtyExit !== 'function') {
|
||||
throw new Error('expected the transport exit handler')
|
||||
}
|
||||
|
||||
onPtyExit('stale-restored-pty')
|
||||
await flushAsyncTicks(10)
|
||||
|
||||
expect(isPaneSpawnDeferred(PANE_KEY)).toBe(true)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
-217
@@ -267,35 +267,6 @@ export function registerPtyConnectionPtyExitTeardownTests(): void {
|
||||
expect(manager.closePane).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('forwards a synthetic host-loss exit code to the tab-level handler', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks9 = await vi.importMock<PtyConnectionAgentTitleMocks>(
|
||||
'@/lib/agent-status/aggregation/worktree-agent-status'
|
||||
)
|
||||
const transport = createMockTransport('tab-pty')
|
||||
transportFactoryQueue.push(transport)
|
||||
const manager = createManager(1)
|
||||
const deps = createDeps()
|
||||
|
||||
connectPanePty(
|
||||
createPane(1) as never,
|
||||
manager as never,
|
||||
bindPaneAgentTitleMocks(deps as never, agentTitleMocks9)
|
||||
)
|
||||
const onPtyExit = createdTransportOptions[0]?.onPtyExit as
|
||||
| ((ptyId: string, exitCode?: number) => void)
|
||||
| undefined
|
||||
expect(onPtyExit).toBeTypeOf('function')
|
||||
|
||||
onPtyExit?.('tab-pty', -1)
|
||||
|
||||
// Synthetic remote exit is unverifiable; retain the persisted binding for tab-level recovery.
|
||||
expect(deps.clearExitedPanePtyLayoutBinding).not.toHaveBeenCalled()
|
||||
expect(deps.clearTabPtyId).not.toHaveBeenCalled()
|
||||
expect(deps.onPtyExitRef.current).toHaveBeenCalledWith('tab-pty', -1)
|
||||
expect(manager.closePane).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('keeps a mounted split pane binding across a synthetic host-loss exit', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks10 = await vi.importMock<PtyConnectionAgentTitleMocks>(
|
||||
@@ -361,58 +332,6 @@ export function registerPtyConnectionPtyExitTeardownTests(): void {
|
||||
expect(manager.closePane).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('tears down a failed local terminal after user input', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks12 = await vi.importMock<PtyConnectionAgentTitleMocks>(
|
||||
'@/lib/agent-status/aggregation/worktree-agent-status'
|
||||
)
|
||||
const pane = createPane(1)
|
||||
const transport = createMockTransport('tab-pty')
|
||||
transportFactoryQueue.push(transport)
|
||||
const manager = createManager(1)
|
||||
const deps = createDeps({ onPaneProcessDied: vi.fn() })
|
||||
|
||||
connectPanePty(
|
||||
pane as never,
|
||||
manager as never,
|
||||
bindPaneAgentTitleMocks(deps as never, agentTitleMocks12)
|
||||
)
|
||||
const onPtyExit = createdTransportOptions[0]?.onPtyExit as
|
||||
| ((ptyId: string, exitCode?: number) => void)
|
||||
| undefined
|
||||
|
||||
sendTerminalInputThroughPane(pane, 'agent startup\r')
|
||||
onPtyExit?.('tab-pty', 1)
|
||||
|
||||
expect(deps.onPaneProcessDied).not.toHaveBeenCalled()
|
||||
expect(deps.onPtyExitRef.current).toHaveBeenCalled()
|
||||
expect(manager.closePane).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('does not claim a capacity overlay for a failed local split pane', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks13 = await vi.importMock<PtyConnectionAgentTitleMocks>(
|
||||
'@/lib/agent-status/aggregation/worktree-agent-status'
|
||||
)
|
||||
const transport = createMockTransport('tab-pty')
|
||||
transportFactoryQueue.push(transport)
|
||||
const manager = createManager(2)
|
||||
const deps = createDeps({ onPaneProcessDied: vi.fn() })
|
||||
|
||||
connectPanePty(
|
||||
createPane(1) as never,
|
||||
manager as never,
|
||||
bindPaneAgentTitleMocks(deps as never, agentTitleMocks13)
|
||||
)
|
||||
const onPtyExit = createdTransportOptions[0]?.onPtyExit as
|
||||
| ((ptyId: string, exitCode?: number) => void)
|
||||
| undefined
|
||||
onPtyExit?.('tab-pty', 1)
|
||||
|
||||
expect(deps.onPaneProcessDied).not.toHaveBeenCalled()
|
||||
expect(manager.closePane).toHaveBeenCalledWith(1)
|
||||
})
|
||||
|
||||
it('retains the cold-restore resume startup when its replacement hits capacity', async () => {
|
||||
restoreUserAgent = temporarilySetNavigatorUserAgent(
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64)'
|
||||
@@ -524,34 +443,6 @@ export function registerPtyConnectionPtyExitTeardownTests(): void {
|
||||
expect(deps.onPaneProcessDied).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('tears down the sole terminal when a reattached (not freshly spawned) PTY exits', async () => {
|
||||
// Reattach skips onPtySpawn; the unused-new-shell guard must not retain a dead previously-live session.
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks16 = await vi.importMock<PtyConnectionAgentTitleMocks>(
|
||||
'@/lib/agent-status/aggregation/worktree-agent-status'
|
||||
)
|
||||
const transport = createMockTransport('tab-pty')
|
||||
transportFactoryQueue.push(transport)
|
||||
const manager = createManager(1)
|
||||
const deps = createDeps()
|
||||
|
||||
connectPanePty(
|
||||
createPane(1) as never,
|
||||
manager as never,
|
||||
bindPaneAgentTitleMocks(deps as never, agentTitleMocks16)
|
||||
)
|
||||
const onPtyExit = createdTransportOptions[0]?.onPtyExit as
|
||||
| ((ptyId: string, exitCode?: number) => void)
|
||||
| undefined
|
||||
expect(onPtyExit).toBeTypeOf('function')
|
||||
|
||||
// No onPtySpawn call: simulates a reattach to a persisted session.
|
||||
onPtyExit?.('tab-pty')
|
||||
|
||||
expect(deps.onPtyExitRef.current).toHaveBeenCalledWith('tab-pty', 0)
|
||||
expect(manager.closePane).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('rebinds a provider replacement without granting fresh-spawn exit protection', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks17 = await vi.importMock<PtyConnectionAgentTitleMocks>(
|
||||
@@ -634,114 +525,6 @@ export function registerPtyConnectionEstablishedPtyExitTests(): void {
|
||||
await restoreTerminalTestGlobals()
|
||||
})
|
||||
|
||||
it('closes a split pane when an established PTY exits after output', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks21 = await vi.importMock<PtyConnectionAgentTitleMocks>(
|
||||
'@/lib/agent-status/aggregation/worktree-agent-status'
|
||||
)
|
||||
const capturedDataCallback: { current: ((data: string) => void) | null } = { current: null }
|
||||
const transport = createMockTransport('pty-pane-2')
|
||||
transport.connect.mockImplementation(
|
||||
async ({ callbacks }: { callbacks: ConnectCallbacks }) => {
|
||||
capturedDataCallback.current = callbacks.onData ?? null
|
||||
return 'pty-pane-2'
|
||||
}
|
||||
)
|
||||
transportFactoryQueue.push(transport)
|
||||
const manager = createManager(2)
|
||||
const deps = createDeps({
|
||||
restoredLeafId: LEAF_2,
|
||||
paneTransportsRef: { current: new Map([[1, createMockTransport('pty-pane-1')]]) }
|
||||
})
|
||||
|
||||
connectPanePty(
|
||||
createPane(2) as never,
|
||||
manager as never,
|
||||
bindPaneAgentTitleMocks(deps as never, agentTitleMocks21)
|
||||
)
|
||||
const onPtyExit = createdTransportOptions[0]?.onPtyExit as
|
||||
| ((ptyId: string) => void)
|
||||
| undefined
|
||||
expect(onPtyExit).toBeTypeOf('function')
|
||||
expect(capturedDataCallback.current).toBeTypeOf('function')
|
||||
|
||||
capturedDataCallback.current?.('shell prompt')
|
||||
onPtyExit?.('pty-pane-2')
|
||||
|
||||
if (ORCA_LAYOUT_OWNER_IS_MAIN) {
|
||||
await expectMainFrameClosesExitedSplitPaneOnce(manager)
|
||||
} else {
|
||||
expect(manager.closePane).toHaveBeenCalledWith(2)
|
||||
}
|
||||
})
|
||||
|
||||
it('removes the agent row when an established PTY exits through EOF (#12907)', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks22 = await vi.importMock<PtyConnectionAgentTitleMocks>(
|
||||
'@/lib/agent-status/aggregation/worktree-agent-status'
|
||||
)
|
||||
const transport = createMockTransport('pty-pane-2')
|
||||
transportFactoryQueue.push(transport)
|
||||
const manager = createManager(2)
|
||||
const deps = createDeps({
|
||||
restoredLeafId: LEAF_2,
|
||||
paneTransportsRef: { current: new Map([[1, createMockTransport('pty-pane-1')]]) }
|
||||
})
|
||||
|
||||
connectPanePty(
|
||||
createPane(2) as never,
|
||||
manager as never,
|
||||
bindPaneAgentTitleMocks(deps as never, agentTitleMocks22)
|
||||
)
|
||||
const onPtyExit = createdTransportOptions[0]?.onPtyExit as
|
||||
| ((ptyId: string) => void)
|
||||
| undefined
|
||||
expect(onPtyExit).toBeTypeOf('function')
|
||||
|
||||
onPtyExit?.('pty-pane-2')
|
||||
|
||||
expect(mockStoreState.removeAgentStatus).toHaveBeenCalledWith(makePaneKey('tab-1', LEAF_2))
|
||||
})
|
||||
|
||||
it('closes a split pane when an established PTY exits after terminal input', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks23 = await vi.importMock<PtyConnectionAgentTitleMocks>(
|
||||
'@/lib/agent-status/aggregation/worktree-agent-status'
|
||||
)
|
||||
const pane = createPane(2)
|
||||
const transport = createMockTransport('pty-pane-2')
|
||||
transportFactoryQueue.push(transport)
|
||||
const manager = createManager(2)
|
||||
const deps = createDeps({
|
||||
restoredLeafId: LEAF_2,
|
||||
paneTransportsRef: { current: new Map([[1, createMockTransport('pty-pane-1')]]) }
|
||||
})
|
||||
|
||||
connectPanePty(
|
||||
pane as never,
|
||||
manager as never,
|
||||
bindPaneAgentTitleMocks(deps as never, agentTitleMocks23)
|
||||
)
|
||||
const onDataMock = pane.terminal.onData as unknown as {
|
||||
mock: { calls: [[(data: string) => void] | []] }
|
||||
}
|
||||
const terminalInputHandler = onDataMock.mock.calls[0]?.[0]
|
||||
const onPtyExit = createdTransportOptions[0]?.onPtyExit as
|
||||
| ((ptyId: string) => void)
|
||||
| undefined
|
||||
expect(terminalInputHandler).toBeTypeOf('function')
|
||||
expect(onPtyExit).toBeTypeOf('function')
|
||||
|
||||
terminalInputHandler?.('exit\r')
|
||||
onPtyExit?.('pty-pane-2')
|
||||
|
||||
if (ORCA_LAYOUT_OWNER_IS_MAIN) {
|
||||
await expectMainFrameClosesExitedSplitPaneOnce(manager)
|
||||
} else {
|
||||
expect(manager.closePane).toHaveBeenCalledWith(2)
|
||||
}
|
||||
})
|
||||
|
||||
it('ignores a late exit from a transport that no longer owns the pane', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks3 = await vi.importMock<PtyConnectionAgentTitleMocks>(
|
||||
|
||||
+1
-237
@@ -16,10 +16,7 @@ import {
|
||||
type PtyConnectionAgentTitleMocks,
|
||||
bindPaneAgentTitleMocks
|
||||
} from '../test-fixtures/pty-connection-test-deps'
|
||||
import {
|
||||
createInitialStoreState,
|
||||
buildActiveRuntimeEnvironmentState
|
||||
} from '../test-fixtures/pty-connection-test-store-fixtures'
|
||||
import { createInitialStoreState } from '../test-fixtures/pty-connection-test-store-fixtures'
|
||||
import type { StoreState } from '../test-fixtures/pty-connection-test-store-state'
|
||||
import {
|
||||
installTerminalTestGlobals,
|
||||
@@ -37,10 +34,6 @@ export function registerPtyConnectionSessionLivenessTests(): void {
|
||||
return buildPaneConnectionDeps(() => mockStoreState, overrides)
|
||||
}
|
||||
|
||||
// Why: activeRuntimeEnvironmentId exercises the remote-runtime path where the renderer still owns OSC 9999 status.
|
||||
function enableActiveRuntimeEnvironment(environmentId = 'env-1'): void {
|
||||
mockStoreState = buildActiveRuntimeEnvironmentState(mockStoreState, environmentId)
|
||||
}
|
||||
describe('connectPanePty', () => {
|
||||
beforeEach(async () => {
|
||||
vi.clearAllMocks()
|
||||
@@ -65,73 +58,6 @@ export function registerPtyConnectionSessionLivenessTests(): void {
|
||||
})
|
||||
|
||||
describe('reconcileIfSessionMissing', () => {
|
||||
it('closes a split pane when targeted liveness says its local session is missing', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks = await vi.importMock<PtyConnectionAgentTitleMocks>(
|
||||
'@/lib/agent-status/aggregation/worktree-agent-status'
|
||||
)
|
||||
const capturedDataCallback: { current: ((data: string) => void) | null } = { current: null }
|
||||
const transport = createMockTransport('pty-pane-2')
|
||||
transport.connect.mockImplementation(
|
||||
async ({ callbacks }: { callbacks: ConnectCallbacks }) => {
|
||||
capturedDataCallback.current = callbacks.onData ?? null
|
||||
return 'pty-pane-2'
|
||||
}
|
||||
)
|
||||
transportFactoryQueue.push(transport)
|
||||
const manager = createManager(2)
|
||||
const deps = createDeps({
|
||||
restoredLeafId: LEAF_2,
|
||||
paneTransportsRef: { current: new Map([[1, createMockTransport('pty-pane-1')]]) }
|
||||
})
|
||||
const hasPty = vi.fn(async () => false)
|
||||
|
||||
const binding = connectPanePty(
|
||||
...mockPanePtyArgs(createPane(2), manager, bindPaneAgentTitleMocks(deps, agentTitleMocks))
|
||||
)
|
||||
capturedDataCallback.current?.('shell prompt')
|
||||
|
||||
binding.reconcileIfSessionMissing(hasPty)
|
||||
await flushAsyncTicks()
|
||||
|
||||
expect(hasPty).toHaveBeenCalledWith('pty-pane-2')
|
||||
// Switch on: the host's authoritative absence is a confirmed end; main closes, the frame shows it.
|
||||
if (ORCA_LAYOUT_OWNER_IS_MAIN) {
|
||||
await expectMainFrameClosesExitedSplitPaneOnce(manager)
|
||||
} else {
|
||||
expect(manager.closePane).toHaveBeenCalledWith(2)
|
||||
}
|
||||
})
|
||||
|
||||
it('does not close when targeted liveness is live or unknown', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks2 = await vi.importMock<PtyConnectionAgentTitleMocks>(
|
||||
'@/lib/agent-status/aggregation/worktree-agent-status'
|
||||
)
|
||||
const transport = createMockTransport('pty-pane-2')
|
||||
transportFactoryQueue.push(transport)
|
||||
const manager = createManager(2)
|
||||
const deps = createDeps({
|
||||
restoredLeafId: LEAF_2,
|
||||
paneTransportsRef: { current: new Map([[1, createMockTransport('pty-pane-1')]]) }
|
||||
})
|
||||
|
||||
const binding = connectPanePty(
|
||||
...mockPanePtyArgs(
|
||||
createPane(2),
|
||||
manager,
|
||||
bindPaneAgentTitleMocks(deps, agentTitleMocks2)
|
||||
)
|
||||
)
|
||||
|
||||
binding.reconcileIfSessionMissing(vi.fn(async () => true))
|
||||
binding.reconcileIfSessionMissing(vi.fn(async () => null))
|
||||
await flushAsyncTicks()
|
||||
|
||||
expect(manager.closePane).not.toHaveBeenCalled()
|
||||
expect(deps.onPtyExitRef.current).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('does not apply a stale targeted liveness result after reattach', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks3 = await vi.importMock<PtyConnectionAgentTitleMocks>(
|
||||
@@ -265,122 +191,6 @@ export function registerPtyConnectionSessionLivenessTests(): void {
|
||||
}
|
||||
})
|
||||
|
||||
it('routes the last pane through onPtyExitRef when its session is dead', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks6 = await vi.importMock<PtyConnectionAgentTitleMocks>(
|
||||
'@/lib/agent-status/aggregation/worktree-agent-status'
|
||||
)
|
||||
const transport = createMockTransport('pty-pane-1')
|
||||
transportFactoryQueue.push(transport)
|
||||
const manager = createManager(1)
|
||||
const deps = createDeps()
|
||||
|
||||
const binding = connectPanePty(
|
||||
...mockPanePtyArgs(
|
||||
createPane(1),
|
||||
manager,
|
||||
bindPaneAgentTitleMocks(deps, agentTitleMocks6)
|
||||
)
|
||||
)
|
||||
|
||||
// The last pane reattaches to the tab's persisted ptyId ('tab-pty'); let that bind first.
|
||||
await flushAsyncTicks()
|
||||
binding.reconcileIfSessionMissing(async () => false)
|
||||
await flushAsyncTicks()
|
||||
|
||||
expect(deps.onPtyExitRef.current).toHaveBeenCalledWith('tab-pty', 0)
|
||||
expect(manager.closePane).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('is a no-op for remote: web-runtime ids', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks7 = await vi.importMock<PtyConnectionAgentTitleMocks>(
|
||||
'@/lib/agent-status/aggregation/worktree-agent-status'
|
||||
)
|
||||
enableActiveRuntimeEnvironment('env-1')
|
||||
const transport = createMockTransport('remote:env-1:pane-2')
|
||||
transport.getConnectionId.mockReturnValue(null)
|
||||
transportFactoryQueue.push(transport)
|
||||
const manager = createManager(2)
|
||||
const deps = createDeps({
|
||||
restoredLeafId: LEAF_2,
|
||||
paneTransportsRef: { current: new Map([[1, createMockTransport('pty-pane-1')]]) }
|
||||
})
|
||||
|
||||
const binding = connectPanePty(
|
||||
...mockPanePtyArgs(
|
||||
createPane(2),
|
||||
manager,
|
||||
bindPaneAgentTitleMocks(deps, agentTitleMocks7)
|
||||
)
|
||||
)
|
||||
|
||||
binding.reconcileIfSessionMissing(async () => false)
|
||||
await flushAsyncTicks()
|
||||
|
||||
expect(manager.closePane).not.toHaveBeenCalled()
|
||||
expect(deps.onPtyExitRef.current).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('is a no-op for SSH/non-local ids (non-null connectionId)', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks8 = await vi.importMock<PtyConnectionAgentTitleMocks>(
|
||||
'@/lib/agent-status/aggregation/worktree-agent-status'
|
||||
)
|
||||
const transport = createMockTransport('pty-pane-2')
|
||||
transport.getConnectionId.mockReturnValue('ssh-target-1')
|
||||
transportFactoryQueue.push(transport)
|
||||
const manager = createManager(2)
|
||||
const deps = createDeps({
|
||||
restoredLeafId: LEAF_2,
|
||||
paneTransportsRef: { current: new Map([[1, createMockTransport('pty-pane-1')]]) }
|
||||
})
|
||||
|
||||
const binding = connectPanePty(
|
||||
...mockPanePtyArgs(
|
||||
createPane(2),
|
||||
manager,
|
||||
bindPaneAgentTitleMocks(deps, agentTitleMocks8)
|
||||
)
|
||||
)
|
||||
|
||||
binding.reconcileIfSessionMissing(async () => false)
|
||||
await flushAsyncTicks()
|
||||
|
||||
expect(manager.closePane).not.toHaveBeenCalled()
|
||||
expect(deps.onPtyExitRef.current).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('respects suppression: a suppressed dead session keeps the pane mounted', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks9 = await vi.importMock<PtyConnectionAgentTitleMocks>(
|
||||
'@/lib/agent-status/aggregation/worktree-agent-status'
|
||||
)
|
||||
const transport = createMockTransport('pty-pane-2')
|
||||
transportFactoryQueue.push(transport)
|
||||
const manager = createManager(2)
|
||||
const deps = createDeps({
|
||||
restoredLeafId: LEAF_2,
|
||||
consumeSuppressedPtyExit: vi.fn(() => true),
|
||||
paneTransportsRef: { current: new Map([[1, createMockTransport('pty-pane-1')]]) }
|
||||
})
|
||||
|
||||
const binding = connectPanePty(
|
||||
...mockPanePtyArgs(
|
||||
createPane(2),
|
||||
manager,
|
||||
bindPaneAgentTitleMocks(deps, agentTitleMocks9)
|
||||
)
|
||||
)
|
||||
|
||||
binding.reconcileIfSessionMissing(async () => false)
|
||||
await flushAsyncTicks()
|
||||
|
||||
expect(deps.consumeSuppressedPtyExit).toHaveBeenCalledWith('pty-pane-2')
|
||||
expect(manager.closePane).not.toHaveBeenCalled()
|
||||
expect(deps.onPtyExitRef.current).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('still closes the replacement PTY after a suppressed restart rebinds the pane', async () => {
|
||||
// Scope exit guards by PTY ID so a rebound replacement’s later exit still tears down.
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
@@ -480,52 +290,6 @@ export function registerPtyConnectionSessionLivenessTests(): void {
|
||||
expect(manager.closePane).toHaveBeenCalledWith(2)
|
||||
}
|
||||
})
|
||||
|
||||
it('closes a genuinely-dead non-suppressed pane once (not misread as suppressed)', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks12 = await vi.importMock<PtyConnectionAgentTitleMocks>(
|
||||
'@/lib/agent-status/aggregation/worktree-agent-status'
|
||||
)
|
||||
const capturedDataCallback: { current: ((data: string) => void) | null } = { current: null }
|
||||
const transport = createMockTransport('pty-pane-2')
|
||||
transport.connect.mockImplementation(
|
||||
async ({ callbacks }: { callbacks: ConnectCallbacks }) => {
|
||||
capturedDataCallback.current = callbacks.onData ?? null
|
||||
return 'pty-pane-2'
|
||||
}
|
||||
)
|
||||
transportFactoryQueue.push(transport)
|
||||
const manager = createManager(2)
|
||||
const deps = createDeps({
|
||||
restoredLeafId: LEAF_2,
|
||||
consumeSuppressedPtyExit: vi.fn(() => false),
|
||||
paneTransportsRef: { current: new Map([[1, createMockTransport('pty-pane-1')]]) }
|
||||
})
|
||||
|
||||
const binding = connectPanePty(
|
||||
...mockPanePtyArgs(
|
||||
createPane(2),
|
||||
manager,
|
||||
bindPaneAgentTitleMocks(deps, agentTitleMocks12)
|
||||
)
|
||||
)
|
||||
capturedDataCallback.current?.('shell prompt')
|
||||
const onPtyExit = createdTransportOptions[0]?.onPtyExit as
|
||||
| ((ptyId: string) => void)
|
||||
| undefined
|
||||
|
||||
binding.reconcileIfSessionMissing(async () => false)
|
||||
await flushAsyncTicks()
|
||||
onPtyExit?.('pty-pane-2')
|
||||
|
||||
if (ORCA_LAYOUT_OWNER_IS_MAIN) {
|
||||
expect(deps.clearExitedPanePtyLayoutBinding).toHaveBeenCalledTimes(1)
|
||||
await expectMainFrameClosesExitedSplitPaneOnce(manager)
|
||||
} else {
|
||||
expect(manager.closePane).toHaveBeenCalledTimes(1)
|
||||
expect(manager.closePane).toHaveBeenCalledWith(2)
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user