fix(remote): don't classify a stale/gone remote handle as agent completion (#9263)
Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
This commit is contained in:
@@ -86,6 +86,8 @@ import {
|
||||
unregisterSshFilesystemProvider
|
||||
} from '../providers/ssh-filesystem-dispatch'
|
||||
import { registerSshGitProvider, unregisterSshGitProvider } from '../providers/ssh-git-dispatch'
|
||||
import { inspectPtyProviderProcess } from '../providers/pty-process-inspection'
|
||||
import type { IPtyProvider } from '../providers/types'
|
||||
import * as worktreePathComparison from '../ipc/worktree-path-comparison'
|
||||
import * as localWorktreeFilesystem from '../local-worktree-filesystem'
|
||||
import {
|
||||
@@ -1279,6 +1281,9 @@ function createRuntimeWithSshLease(
|
||||
|
||||
async function createExplicitAgentStatusHarness(options: {
|
||||
getForegroundProcess: (ptyId: string) => Promise<string | null>
|
||||
inspectProcess?: (
|
||||
ptyId: string
|
||||
) => Promise<{ foregroundProcess: string | null; hasChildProcesses: boolean }>
|
||||
confirmForegroundProcess?: (ptyId: string) => Promise<string | null>
|
||||
title?: string
|
||||
}): Promise<{
|
||||
@@ -1308,6 +1313,7 @@ async function createExplicitAgentStatusHarness(options: {
|
||||
write: () => true,
|
||||
kill: () => true,
|
||||
getForegroundProcess: options.getForegroundProcess,
|
||||
inspectProcess: options.inspectProcess,
|
||||
confirmForegroundProcess: options.confirmForegroundProcess
|
||||
})
|
||||
runtime.attachWindow(1)
|
||||
@@ -10368,6 +10374,23 @@ describe('OrcaRuntimeService', () => {
|
||||
expect(confirmForegroundProcess).toHaveBeenCalledWith('pty-1')
|
||||
})
|
||||
|
||||
it('preserves provider failure during completion-sensitive process inspection', async () => {
|
||||
const failure = new Error('daemon unavailable')
|
||||
const providerInspectProcess = vi.fn().mockRejectedValue(failure)
|
||||
const provider = { inspectProcess: providerInspectProcess } as unknown as IPtyProvider
|
||||
const inspectProcess = vi.fn((ptyId: string) => inspectPtyProviderProcess(provider, ptyId))
|
||||
const getForegroundProcess = vi.fn(async () => null)
|
||||
const { runtime, handle } = await createExplicitAgentStatusHarness({
|
||||
getForegroundProcess,
|
||||
inspectProcess
|
||||
})
|
||||
|
||||
await expect(runtime.inspectTerminalProcess(handle)).rejects.toBe(failure)
|
||||
expect(inspectProcess).toHaveBeenCalledExactlyOnceWith('pty-1')
|
||||
expect(providerInspectProcess).toHaveBeenCalledExactlyOnceWith('pty-1')
|
||||
expect(getForegroundProcess).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('calls foreground confirmation with its controller receiver', async () => {
|
||||
const getForegroundProcess = vi.fn(async () => 'powershell.exe')
|
||||
const confirmForegroundProcess = vi.fn(
|
||||
|
||||
@@ -1427,6 +1427,9 @@ type RuntimePtyController = {
|
||||
markReversibleStops?(ptyIds: readonly string[]): () => void
|
||||
getCwd?(ptyId: string): Promise<string | null>
|
||||
getForegroundProcess(ptyId: string): Promise<string | null>
|
||||
inspectProcess?(
|
||||
ptyId: string
|
||||
): Promise<{ foregroundProcess: string | null; hasChildProcesses: boolean }>
|
||||
confirmForegroundProcess?(ptyId: string): Promise<string | null>
|
||||
hasChildProcesses?(ptyId: string): Promise<boolean>
|
||||
clearBuffer?(ptyId: string): Promise<void>
|
||||
@@ -15723,13 +15726,15 @@ export class OrcaRuntimeService {
|
||||
async inspectTerminalProcess(
|
||||
terminalSelector: string
|
||||
): Promise<{ foregroundProcess: string | null; hasChildProcesses: boolean }> {
|
||||
const leaf = this.resolveLeafForHandle(terminalSelector)
|
||||
const leaf = this.resolveLiveLeafForHandle(terminalSelector)
|
||||
if (!leaf?.ptyId || !this.ptyController) {
|
||||
return { foregroundProcess: null, hasChildProcesses: false }
|
||||
throw new Error('terminal_gone')
|
||||
}
|
||||
if (this.ptyController.inspectProcess) {
|
||||
return this.ptyController.inspectProcess(leaf.ptyId)
|
||||
}
|
||||
const foregroundProcess = await this.ptyController.getForegroundProcess(leaf.ptyId)
|
||||
const hasChildProcesses =
|
||||
(await this.ptyController.hasChildProcesses?.(leaf.ptyId).catch(() => false)) ?? false
|
||||
const hasChildProcesses = (await this.ptyController.hasChildProcesses?.(leaf.ptyId)) ?? false
|
||||
return { foregroundProcess, hasChildProcesses }
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user