fix(daemon): preserve completion inspection for legacy protocols (#10679)
This commit is contained in:
@@ -3,6 +3,7 @@ import {
|
||||
AGENT_SESSION_CLAIM_DAEMON_PROTOCOL_VERSION,
|
||||
AGENT_SESSION_CREATE_OPERATION_DAEMON_PROTOCOL_VERSION,
|
||||
COMPLETION_PROCESS_INSPECTION_PROTOCOL_VERSION,
|
||||
GET_FOREGROUND_PROCESS_PROTOCOL_VERSION,
|
||||
PREVIOUS_DAEMON_PROTOCOL_VERSIONS,
|
||||
PROTOCOL_VERSION
|
||||
} from './daemon-protocol-version'
|
||||
@@ -11,6 +12,7 @@ describe('daemon protocol version', () => {
|
||||
it('ships preflight-cache replacement after completion inspection', () => {
|
||||
expect(PROTOCOL_VERSION).toBe(28)
|
||||
expect(COMPLETION_PROCESS_INSPECTION_PROTOCOL_VERSION).toBe(27)
|
||||
expect(GET_FOREGROUND_PROCESS_PROTOCOL_VERSION).toBe(11)
|
||||
expect(AGENT_SESSION_CLAIM_DAEMON_PROTOCOL_VERSION).toBe(26)
|
||||
expect(AGENT_SESSION_CREATE_OPERATION_DAEMON_PROTOCOL_VERSION).toBe(26)
|
||||
expect(PREVIOUS_DAEMON_PROTOCOL_VERSIONS).toEqual(
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// v28 replaces v26/v27 daemons that can retain permanent macOS preflight rejections (#9756).
|
||||
export const PROTOCOL_VERSION = 28
|
||||
export const COMPLETION_PROCESS_INSPECTION_PROTOCOL_VERSION = 27
|
||||
export const GET_FOREGROUND_PROCESS_PROTOCOL_VERSION = 11
|
||||
export const PTY_STARTUP_INGRESS_PROTOCOL_VERSION = 25
|
||||
export const AGENT_SESSION_CLAIM_DAEMON_PROTOCOL_VERSION = 26
|
||||
export const AGENT_SESSION_CREATE_OPERATION_DAEMON_PROTOCOL_VERSION = 26
|
||||
|
||||
@@ -6,7 +6,11 @@ import { mkdtempSync, mkdirSync, rmSync, existsSync, readFileSync, writeFileSync
|
||||
import { DaemonClient } from './client'
|
||||
import { DaemonProtocolError } from './daemon-errors'
|
||||
import { DaemonPtyAdapter } from './daemon-pty-adapter'
|
||||
import { COMPLETION_PROCESS_INSPECTION_PROTOCOL_VERSION } from './daemon-protocol-version'
|
||||
import {
|
||||
COMPLETION_PROCESS_INSPECTION_PROTOCOL_VERSION,
|
||||
GET_FOREGROUND_PROCESS_PROTOCOL_VERSION,
|
||||
PROTOCOL_VERSION
|
||||
} from './daemon-protocol-version'
|
||||
import { DaemonServer } from './daemon-server'
|
||||
import { HeadlessEmulator } from './headless-emulator'
|
||||
import { getHistorySessionDirName } from './history-paths'
|
||||
@@ -929,31 +933,53 @@ describe('DaemonPtyAdapter (IPtyProvider)', () => {
|
||||
})
|
||||
|
||||
describe('inspectProcess on pre-inspection daemon protocols', () => {
|
||||
// Why: daemons outlive an in-place app update, so a v26 daemon must still answer inspections
|
||||
// client-side; throwing here leaves agent-completion detection permanently retrying.
|
||||
type ClientInternals = {
|
||||
client: { request: ReturnType<typeof vi.fn>; disconnect: ReturnType<typeof vi.fn> }
|
||||
}
|
||||
|
||||
function createLegacyAdapter(request: ReturnType<typeof vi.fn>): DaemonPtyAdapter {
|
||||
const legacy = new DaemonPtyAdapter({
|
||||
function createInspectionAdapter(
|
||||
protocolVersion: number,
|
||||
request: ReturnType<typeof vi.fn>
|
||||
): DaemonPtyAdapter {
|
||||
const inspectionAdapter = new DaemonPtyAdapter({
|
||||
socketPath,
|
||||
tokenPath,
|
||||
protocolVersion: COMPLETION_PROCESS_INSPECTION_PROTOCOL_VERSION - 1
|
||||
protocolVersion
|
||||
})
|
||||
;(legacy as unknown as ClientInternals).client = { request, disconnect: vi.fn() }
|
||||
return legacy
|
||||
;(inspectionAdapter as unknown as ClientInternals).client = {
|
||||
request,
|
||||
disconnect: vi.fn()
|
||||
}
|
||||
return inspectionAdapter
|
||||
}
|
||||
|
||||
it('composes a real inspection from the foreground call the daemon does support', async () => {
|
||||
it('reports protocol 10 inspection as unavailable without unsupported RPCs', async () => {
|
||||
const request = vi.fn()
|
||||
const legacy = createInspectionAdapter(GET_FOREGROUND_PROCESS_PROTOCOL_VERSION - 1, request)
|
||||
|
||||
await expect(legacy.inspectProcess('sess-a')).resolves.toEqual({
|
||||
foregroundProcess: null,
|
||||
hasChildProcesses: true,
|
||||
unavailable: true
|
||||
})
|
||||
await expect(legacy.getForegroundProcess('sess-a')).resolves.toBeNull()
|
||||
await expect(legacy.hasChildProcesses('sess-a')).resolves.toBe(true)
|
||||
expect(request).not.toHaveBeenCalled()
|
||||
|
||||
legacy.dispose()
|
||||
})
|
||||
|
||||
it.each([
|
||||
GET_FOREGROUND_PROCESS_PROTOCOL_VERSION,
|
||||
COMPLETION_PROCESS_INSPECTION_PROTOCOL_VERSION - 1
|
||||
])('composes protocol %s inspection from getForegroundProcess', async (protocolVersion) => {
|
||||
const request = vi.fn(async () => ({ foregroundProcess: 'codex' }))
|
||||
const legacy = createLegacyAdapter(request)
|
||||
const legacy = createInspectionAdapter(protocolVersion, request)
|
||||
|
||||
expect(await legacy.inspectProcess('sess-a')).toEqual({
|
||||
foregroundProcess: 'codex',
|
||||
hasChildProcesses: true
|
||||
})
|
||||
// Why: the fallback must not depend on a capability the legacy daemon lacks.
|
||||
expect(request).toHaveBeenCalledWith('getForegroundProcess', { sessionId: 'sess-a' })
|
||||
expect(request).not.toHaveBeenCalledWith('inspectProcess', expect.anything())
|
||||
|
||||
@@ -961,7 +987,10 @@ describe('DaemonPtyAdapter (IPtyProvider)', () => {
|
||||
})
|
||||
|
||||
it('reports an idle shell as having no child processes', async () => {
|
||||
const legacy = createLegacyAdapter(vi.fn(async () => ({ foregroundProcess: 'bash' })))
|
||||
const legacy = createInspectionAdapter(
|
||||
COMPLETION_PROCESS_INSPECTION_PROTOCOL_VERSION - 1,
|
||||
vi.fn(async () => ({ foregroundProcess: 'bash' }))
|
||||
)
|
||||
|
||||
expect(await legacy.inspectProcess('sess-a')).toEqual({
|
||||
foregroundProcess: 'bash',
|
||||
@@ -972,11 +1001,10 @@ describe('DaemonPtyAdapter (IPtyProvider)', () => {
|
||||
})
|
||||
|
||||
it('reports a null foreground as idle, matching what the legacy daemon can report', async () => {
|
||||
// Why: pins the one response shape whose semantics differ from v27, where inspectProcess goes
|
||||
// through getAliveSession() and throws for a vanished session while getForegroundProcess stays
|
||||
// null-not-throw. Reading it as idle is deliberate — this is also the only shape that reaches a
|
||||
// user-visible completion — so the divergence must not change silently.
|
||||
const legacy = createLegacyAdapter(vi.fn(async () => ({ foregroundProcess: null })))
|
||||
const legacy = createInspectionAdapter(
|
||||
COMPLETION_PROCESS_INSPECTION_PROTOCOL_VERSION - 1,
|
||||
vi.fn(async () => ({ foregroundProcess: null }))
|
||||
)
|
||||
|
||||
expect(await legacy.inspectProcess('sess-a')).toEqual({
|
||||
foregroundProcess: null,
|
||||
@@ -989,7 +1017,8 @@ describe('DaemonPtyAdapter (IPtyProvider)', () => {
|
||||
it('rejects rather than reading as idle when the daemon call fails', async () => {
|
||||
// Why: getForegroundProcess swallows errors into null; composing through it would turn a dead
|
||||
// socket into a false "agent exited" completion, the mirror of the bug this path fixes.
|
||||
const legacy = createLegacyAdapter(
|
||||
const legacy = createInspectionAdapter(
|
||||
COMPLETION_PROCESS_INSPECTION_PROTOCOL_VERSION - 1,
|
||||
vi.fn(async () => {
|
||||
throw new Error('socket_closed')
|
||||
})
|
||||
@@ -1000,21 +1029,19 @@ describe('DaemonPtyAdapter (IPtyProvider)', () => {
|
||||
legacy.dispose()
|
||||
})
|
||||
|
||||
it('still delegates to the daemon once the protocol supports inspectProcess', async () => {
|
||||
const request = vi.fn(async () => ({ foregroundProcess: 'codex', hasChildProcesses: true }))
|
||||
const current = new DaemonPtyAdapter({
|
||||
socketPath,
|
||||
tokenPath,
|
||||
protocolVersion: COMPLETION_PROCESS_INSPECTION_PROTOCOL_VERSION
|
||||
})
|
||||
;(current as unknown as ClientInternals).client = { request, disconnect: vi.fn() }
|
||||
it.each([COMPLETION_PROCESS_INSPECTION_PROTOCOL_VERSION, PROTOCOL_VERSION])(
|
||||
'delegates protocol %s inspection to inspectProcess',
|
||||
async (protocolVersion) => {
|
||||
const request = vi.fn(async () => ({ foregroundProcess: 'codex', hasChildProcesses: true }))
|
||||
const current = createInspectionAdapter(protocolVersion, request)
|
||||
|
||||
await current.inspectProcess('sess-a')
|
||||
await current.inspectProcess('sess-a')
|
||||
|
||||
expect(request).toHaveBeenCalledWith('inspectProcess', { sessionId: 'sess-a' })
|
||||
expect(request).toHaveBeenCalledWith('inspectProcess', { sessionId: 'sess-a' })
|
||||
|
||||
current.dispose()
|
||||
})
|
||||
current.dispose()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
describe('serialize / revive', () => {
|
||||
|
||||
@@ -11,6 +11,7 @@ import { CODEX_SHELL_READY_TIMEOUT_MS } from './session'
|
||||
import {
|
||||
CLEAN_DISCONNECT_PROTOCOL_VERSION,
|
||||
COMPLETION_PROCESS_INSPECTION_PROTOCOL_VERSION,
|
||||
GET_FOREGROUND_PROCESS_PROTOCOL_VERSION,
|
||||
AGENT_SESSION_CLAIM_DAEMON_PROTOCOL_VERSION,
|
||||
AGENT_SESSION_CREATE_OPERATION_DAEMON_PROTOCOL_VERSION,
|
||||
GIT_CREDENTIAL_GUARD_HOST_PROTOCOL_VERSION,
|
||||
@@ -38,6 +39,7 @@ import type {
|
||||
PtySpawnOptions,
|
||||
PtySpawnResult
|
||||
} from '../providers/types'
|
||||
import type { PtyProcessInspection } from '../providers/pty-process-inspection'
|
||||
import { isShellProcess } from '../../shared/agent-detection'
|
||||
import { resolveWslSessionContext } from './wsl-session-context'
|
||||
import { normalizeWslColdRestoreCwd } from './wsl-cold-restore-cwd'
|
||||
@@ -824,12 +826,16 @@ export class DaemonPtyAdapter implements IPtyProvider {
|
||||
}
|
||||
|
||||
async hasChildProcesses(id: string): Promise<boolean> {
|
||||
if (this.protocolVersion < GET_FOREGROUND_PROCESS_PROTOCOL_VERSION) {
|
||||
return true
|
||||
}
|
||||
return this.hasChildProcessesFromForeground(await this.getForegroundProcess(id))
|
||||
}
|
||||
|
||||
async inspectProcess(
|
||||
id: string
|
||||
): Promise<{ foregroundProcess: string | null; hasChildProcesses: boolean }> {
|
||||
async inspectProcess(id: string): Promise<PtyProcessInspection> {
|
||||
if (this.protocolVersion < GET_FOREGROUND_PROCESS_PROTOCOL_VERSION) {
|
||||
return { foregroundProcess: null, hasChildProcesses: true, unavailable: true }
|
||||
}
|
||||
if (this.protocolVersion < COMPLETION_PROCESS_INSPECTION_PROTOCOL_VERSION) {
|
||||
// Why: pre-v27 daemons survive an in-place app update; compose the inspection client-side from the
|
||||
// one call they do support instead of throwing, or completion detection stays dead until recreate.
|
||||
@@ -850,6 +856,9 @@ export class DaemonPtyAdapter implements IPtyProvider {
|
||||
}
|
||||
|
||||
async getForegroundProcess(id: string): Promise<string | null> {
|
||||
if (this.protocolVersion < GET_FOREGROUND_PROCESS_PROTOCOL_VERSION) {
|
||||
return null
|
||||
}
|
||||
try {
|
||||
const result = await this.client.request<{ foregroundProcess: string | null }>(
|
||||
'getForegroundProcess',
|
||||
|
||||
@@ -150,6 +150,26 @@ it('rejects completion inspection when no daemon owns the session', async () =>
|
||||
await expect(router.inspectProcess('unmapped-session')).rejects.toThrow('terminal_gone')
|
||||
})
|
||||
|
||||
it('preserves unavailable inspection from the owning legacy daemon', async () => {
|
||||
const legacy = createAdapter('legacy', ['legacy-session'])
|
||||
vi.mocked(legacy.inspectProcess).mockResolvedValue({
|
||||
foregroundProcess: null,
|
||||
hasChildProcesses: true,
|
||||
unavailable: true
|
||||
})
|
||||
const router = new DaemonPtyRouter({
|
||||
current: createAdapter('current'),
|
||||
legacy: [legacy]
|
||||
})
|
||||
await router.discoverLegacySessions()
|
||||
|
||||
await expect(router.inspectProcess('legacy-session')).resolves.toEqual({
|
||||
foregroundProcess: null,
|
||||
hasChildProcesses: true,
|
||||
unavailable: true
|
||||
})
|
||||
})
|
||||
|
||||
describe('DaemonPtyRouter', () => {
|
||||
it('reports separate conservative resume and fresh-create boundaries', () => {
|
||||
const current = createAdapter(
|
||||
|
||||
@@ -8,6 +8,7 @@ import type {
|
||||
PtySpawnResult
|
||||
} from '../providers/types'
|
||||
import type { PtyIncarnationId } from '../../shared/pty-incarnation'
|
||||
import type { PtyProcessInspection } from '../providers/pty-process-inspection'
|
||||
|
||||
export class DaemonPtyRouter implements IPtyProvider {
|
||||
private current: DaemonPtyAdapter
|
||||
@@ -189,9 +190,7 @@ export class DaemonPtyRouter implements IPtyProvider {
|
||||
return this.adapterFor(id).getForegroundProcess(id)
|
||||
}
|
||||
|
||||
async inspectProcess(
|
||||
id: string
|
||||
): Promise<{ foregroundProcess: string | null; hasChildProcesses: boolean }> {
|
||||
async inspectProcess(id: string): Promise<PtyProcessInspection> {
|
||||
return this.adapterForInspection(id).inspectProcess(id)
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,10 @@ import { describe, expect, it, vi } from 'vitest'
|
||||
import { DegradedDaemonPtyProvider } from './degraded-daemon-pty-provider'
|
||||
import type { DaemonPtyAdapter } from './daemon-pty-adapter'
|
||||
import type { IPtyProvider, PtySpawnOptions, PtySpawnResult } from '../providers/types'
|
||||
import type { PtyProcessInspection } from '../providers/pty-process-inspection'
|
||||
|
||||
type ProviderMock = IPtyProvider & {
|
||||
inspectProcess: (id: string) => Promise<PtyProcessInspection>
|
||||
emitData: (id: string, data: string, sequenceChars?: number) => void
|
||||
emitReplay: (id: string, data: string) => void
|
||||
emitExit: (id: string, code: number) => void
|
||||
@@ -42,6 +44,7 @@ function createProvider(
|
||||
acknowledgeDataEvent: vi.fn(),
|
||||
hasChildProcesses: vi.fn(async () => false),
|
||||
getForegroundProcess: vi.fn(async () => null),
|
||||
inspectProcess: vi.fn(async () => ({ foregroundProcess: null, hasChildProcesses: false })),
|
||||
confirmForegroundProcess: vi.fn(async () => `${label}-confirmed`),
|
||||
serialize: vi.fn(async () => '{}'),
|
||||
revive: vi.fn(async () => {}),
|
||||
@@ -123,6 +126,27 @@ it('rejects completion inspection instead of borrowing the fallback provider', a
|
||||
await expect(provider.inspectProcess('unmapped-session')).rejects.toThrow('terminal_gone')
|
||||
})
|
||||
|
||||
it('preserves unavailable inspection from an owning daemon', async () => {
|
||||
const daemon = createDaemonAdapter('daemon', ['daemon-session'])
|
||||
vi.mocked(daemon.inspectProcess).mockResolvedValue({
|
||||
foregroundProcess: null,
|
||||
hasChildProcesses: true,
|
||||
unavailable: true
|
||||
})
|
||||
const provider = new DegradedDaemonPtyProvider({
|
||||
current: daemon,
|
||||
legacy: [],
|
||||
fallback: createProvider('fallback')
|
||||
})
|
||||
await provider.discoverDaemonSessions()
|
||||
|
||||
await expect(provider.inspectProcess('daemon-session')).resolves.toEqual({
|
||||
foregroundProcess: null,
|
||||
hasChildProcesses: true,
|
||||
unavailable: true
|
||||
})
|
||||
})
|
||||
|
||||
describe('DegradedDaemonPtyProvider', () => {
|
||||
it('only delegates owner-listing authority to the provider that owns the id', async () => {
|
||||
const current = createDaemonAdapter('daemon', ['daemon-session'])
|
||||
|
||||
@@ -27,6 +27,7 @@ export {
|
||||
AGENT_SESSION_CREATE_OPERATION_DAEMON_PROTOCOL_VERSION,
|
||||
CLEAN_DISCONNECT_PROTOCOL_VERSION,
|
||||
COMPLETION_PROCESS_INSPECTION_PROTOCOL_VERSION,
|
||||
GET_FOREGROUND_PROCESS_PROTOCOL_VERSION,
|
||||
GIT_CREDENTIAL_GUARD_HOST_PROTOCOL_VERSION,
|
||||
PREVIOUS_DAEMON_PROTOCOL_VERSIONS,
|
||||
PROTOCOL_VERSION,
|
||||
|
||||
@@ -5905,6 +5905,24 @@ describe('registerPtyHandlers', () => {
|
||||
expect(provider.confirmForegroundProcess).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('preserves unavailable process inspection results from the provider', async () => {
|
||||
const inspectProcess = vi.fn(async () => ({
|
||||
foregroundProcess: null,
|
||||
hasChildProcesses: true,
|
||||
unavailable: true as const
|
||||
}))
|
||||
registerPtyHandlers(mainWindow as never)
|
||||
setLocalPtyProvider({ inspectProcess } as never)
|
||||
|
||||
await expect(
|
||||
handlers.get('pty:inspectProcess')!(null, { id: 'legacy-daemon-pty' })
|
||||
).resolves.toEqual({
|
||||
foregroundProcess: null,
|
||||
hasChildProcesses: true,
|
||||
unavailable: true
|
||||
})
|
||||
})
|
||||
|
||||
// Why: daemon resize is fire-and-forget, so pty:getSize must report the APPLIED size, not the requested one (Claude-Code split-pane desync).
|
||||
describe('pty:getSize reports applied size, not requested size', () => {
|
||||
function setupProviderWithAppliedSize(args: {
|
||||
|
||||
@@ -25,6 +25,18 @@ describe('PTY provider process inspection', () => {
|
||||
expect(inspectProcess).toHaveBeenCalledExactlyOnceWith('pty-1')
|
||||
})
|
||||
|
||||
it('preserves an unavailable inspection result', async () => {
|
||||
const inspection = {
|
||||
foregroundProcess: null,
|
||||
hasChildProcesses: true,
|
||||
unavailable: true as const
|
||||
}
|
||||
const inspectProcess = vi.fn().mockResolvedValue(inspection)
|
||||
const provider = { inspectProcess } as unknown as IPtyProvider
|
||||
|
||||
await expect(inspectPtyProviderProcess(provider, 'pty-1')).resolves.toEqual(inspection)
|
||||
})
|
||||
|
||||
it('falls back to the existing provider process APIs', async () => {
|
||||
const getForegroundProcess = vi.fn().mockResolvedValue('codex')
|
||||
const hasChildProcesses = vi.fn().mockResolvedValue(true)
|
||||
|
||||
@@ -3,6 +3,7 @@ import type { IPtyProvider } from './types'
|
||||
export type PtyProcessInspection = {
|
||||
foregroundProcess: string | null
|
||||
hasChildProcesses: boolean
|
||||
unavailable?: true
|
||||
}
|
||||
|
||||
type CompletionSensitivePtyProvider = IPtyProvider & {
|
||||
|
||||
@@ -835,6 +835,18 @@ describe('SshPtyProvider', () => {
|
||||
expect(mux.request).toHaveBeenCalledWith('pty.getForegroundProcess', { id: 'pty-1' })
|
||||
})
|
||||
|
||||
it('preserves unavailable process inspection', async () => {
|
||||
const inspection = {
|
||||
foregroundProcess: null,
|
||||
hasChildProcesses: true,
|
||||
unavailable: true as const
|
||||
}
|
||||
mux.request.mockResolvedValue(inspection)
|
||||
|
||||
await expect(provider.inspectProcess(scopedPty1)).resolves.toEqual(inspection)
|
||||
expect(mux.request).toHaveBeenCalledWith('pty.inspectProcess', { id: 'pty-1' })
|
||||
})
|
||||
|
||||
it('serializes scoped app ids using raw relay ids', async () => {
|
||||
mux.request.mockResolvedValue('serialized')
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
import { buildSshPtySpawnRequest } from './ssh-pty-spawn-request'
|
||||
import { SshPtySpawnExitRaceTracker } from './ssh-pty-spawn-exit-race'
|
||||
import { SshAgentSessionCapabilities } from './ssh-agent-session-capabilities'
|
||||
import type { PtyProcessInspection } from './pty-process-inspection'
|
||||
|
||||
// Why: sequential relay teardown calls share one absolute budget; convert to the mux-relative timeout only at dispatch.
|
||||
function relayTimeoutOptions(deadlineMs: number | undefined): { timeoutMs: number } | undefined {
|
||||
@@ -281,12 +282,10 @@ export class SshPtyProvider implements IPtyProvider {
|
||||
return result as string | null
|
||||
}
|
||||
|
||||
async inspectProcess(
|
||||
id: string
|
||||
): Promise<{ foregroundProcess: string | null; hasChildProcesses: boolean }> {
|
||||
async inspectProcess(id: string): Promise<PtyProcessInspection> {
|
||||
return (await this.mux.request('pty.inspectProcess', {
|
||||
id: this.toRelayPtyId(id)
|
||||
})) as { foregroundProcess: string | null; hasChildProcesses: boolean }
|
||||
})) as PtyProcessInspection
|
||||
}
|
||||
|
||||
async serialize(ids: string[]): Promise<string> {
|
||||
|
||||
@@ -1297,7 +1297,7 @@ async function createExplicitAgentStatusHarness(options: {
|
||||
getForegroundProcess: (ptyId: string) => Promise<string | null>
|
||||
inspectProcess?: (
|
||||
ptyId: string
|
||||
) => Promise<{ foregroundProcess: string | null; hasChildProcesses: boolean }>
|
||||
) => Promise<{ foregroundProcess: string | null; hasChildProcesses: boolean; unavailable?: true }>
|
||||
confirmForegroundProcess?: (ptyId: string) => Promise<string | null>
|
||||
title?: string
|
||||
}): Promise<{
|
||||
@@ -10545,6 +10545,24 @@ describe('OrcaRuntimeService', () => {
|
||||
expect(getForegroundProcess).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('preserves provider unavailable results during process inspection', async () => {
|
||||
const inspection = {
|
||||
foregroundProcess: null,
|
||||
hasChildProcesses: true,
|
||||
unavailable: true as const
|
||||
}
|
||||
const inspectProcess = vi.fn(async () => inspection)
|
||||
const getForegroundProcess = vi.fn(async () => null)
|
||||
const { runtime, handle } = await createExplicitAgentStatusHarness({
|
||||
getForegroundProcess,
|
||||
inspectProcess
|
||||
})
|
||||
|
||||
await expect(runtime.inspectTerminalProcess(handle)).resolves.toEqual(inspection)
|
||||
expect(inspectProcess).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(
|
||||
|
||||
@@ -1464,7 +1464,7 @@ type RuntimePtyController = {
|
||||
getForegroundProcess(ptyId: string): Promise<string | null>
|
||||
inspectProcess?(
|
||||
ptyId: string
|
||||
): Promise<{ foregroundProcess: string | null; hasChildProcesses: boolean }>
|
||||
): Promise<{ foregroundProcess: string | null; hasChildProcesses: boolean; unavailable?: true }>
|
||||
confirmForegroundProcess?(ptyId: string): Promise<string | null>
|
||||
hasChildProcesses?(ptyId: string): Promise<boolean>
|
||||
clearBuffer?(ptyId: string): Promise<void>
|
||||
@@ -15832,7 +15832,7 @@ export class OrcaRuntimeService {
|
||||
|
||||
async inspectTerminalProcess(
|
||||
terminalSelector: string
|
||||
): Promise<{ foregroundProcess: string | null; hasChildProcesses: boolean }> {
|
||||
): Promise<{ foregroundProcess: string | null; hasChildProcesses: boolean; unavailable?: true }> {
|
||||
const leaf = this.resolveLiveLeafForHandle(terminalSelector)
|
||||
if (!leaf?.ptyId || !this.ptyController) {
|
||||
throw new Error('terminal_gone')
|
||||
|
||||
@@ -1374,9 +1374,11 @@ export type PreloadApi = {
|
||||
publishTerminalViewAttributes: (attributes: TerminalViewAttributes) => void
|
||||
hasChildProcesses: (id: string) => Promise<boolean>
|
||||
getForegroundProcess: (id: string) => Promise<string | null>
|
||||
inspectProcess: (
|
||||
id: string
|
||||
) => Promise<{ foregroundProcess: string | null; hasChildProcesses: boolean }>
|
||||
inspectProcess: (id: string) => Promise<{
|
||||
foregroundProcess: string | null
|
||||
hasChildProcesses: boolean
|
||||
unavailable?: true
|
||||
}>
|
||||
confirmForegroundProcess: (id: string) => Promise<string | null>
|
||||
getCwd: (id: string) => Promise<string>
|
||||
getSize: (id: string) => Promise<{ cols: number; rows: number } | null>
|
||||
|
||||
@@ -984,8 +984,11 @@ const api = {
|
||||
ipcRenderer.invoke('pty:getForegroundProcess', { id }),
|
||||
inspectProcess: (
|
||||
id: string
|
||||
): Promise<{ foregroundProcess: string | null; hasChildProcesses: boolean }> =>
|
||||
ipcRenderer.invoke('pty:inspectProcess', { id }),
|
||||
): Promise<{
|
||||
foregroundProcess: string | null
|
||||
hasChildProcesses: boolean
|
||||
unavailable?: true
|
||||
}> => ipcRenderer.invoke('pty:inspectProcess', { id }),
|
||||
confirmForegroundProcess: (id: string): Promise<string | null> =>
|
||||
ipcRenderer.invoke('pty:confirmForegroundProcess', { id }),
|
||||
|
||||
|
||||
@@ -284,6 +284,80 @@ describe('agent completion coordinator', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('keeps hook working evidence across unavailable inspections', async () => {
|
||||
const dispatchCompletion = vi.fn()
|
||||
const coordinator = createAgentCompletionCoordinator({
|
||||
paneKey: 'tab-1:leaf-1',
|
||||
getPtyId: () => 'pty-1',
|
||||
getSettings: () => null,
|
||||
inspectProcess: vi.fn(async () => ({
|
||||
foregroundProcess: null,
|
||||
hasChildProcesses: true,
|
||||
unavailable: true as const
|
||||
})),
|
||||
dispatchCompletion,
|
||||
isLive: () => true
|
||||
})
|
||||
|
||||
coordinator.startProcessTracking()
|
||||
coordinator.observeHookStatus({ state: 'working', agentType: 'codex', prompt: 'test' })
|
||||
await vi.advanceTimersByTimeAsync(2_000)
|
||||
coordinator.observeHookStatus({ state: 'done', agentType: 'codex', prompt: 'test' })
|
||||
|
||||
expect(dispatchCompletion).not.toHaveBeenCalled()
|
||||
await vi.advanceTimersByTimeAsync(HOOK_DONE_QUIET_MS)
|
||||
expect(dispatchCompletion).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('keeps explicit-title evidence across unavailable inspections', async () => {
|
||||
const dispatchCompletion = vi.fn()
|
||||
const coordinator = createAgentCompletionCoordinator({
|
||||
paneKey: 'tab-1:leaf-1',
|
||||
getPtyId: () => 'pty-1',
|
||||
getSettings: () => null,
|
||||
inspectProcess: vi.fn(async () => ({
|
||||
foregroundProcess: null,
|
||||
hasChildProcesses: true,
|
||||
unavailable: true as const
|
||||
})),
|
||||
dispatchCompletion,
|
||||
isLive: () => true
|
||||
})
|
||||
|
||||
coordinator.startProcessTracking()
|
||||
coordinator.observeTitle('Codex working')
|
||||
await vi.advanceTimersByTimeAsync(2_000)
|
||||
coordinator.observeClassifiedTitleCompletion('done')
|
||||
|
||||
expect(dispatchCompletion).toHaveBeenCalledExactlyOnceWith('done')
|
||||
})
|
||||
|
||||
it('resets exit confirmation across an unavailable inspection', async () => {
|
||||
let result: RuntimeTerminalProcessInspection = processResult('codex')
|
||||
const dispatchCompletion = vi.fn()
|
||||
const coordinator = createAgentCompletionCoordinator({
|
||||
paneKey: 'tab-1:leaf-1',
|
||||
getPtyId: () => 'pty-1',
|
||||
getSettings: () => null,
|
||||
inspectProcess: vi.fn(async () => result),
|
||||
dispatchCompletion,
|
||||
isLive: () => true
|
||||
})
|
||||
|
||||
coordinator.startProcessTracking()
|
||||
await vi.advanceTimersByTimeAsync(2_000)
|
||||
result = processResult(null, false)
|
||||
await vi.advanceTimersByTimeAsync(750)
|
||||
result = { foregroundProcess: null, hasChildProcesses: true, unavailable: true }
|
||||
await vi.advanceTimersByTimeAsync(750)
|
||||
result = processResult(null, false)
|
||||
await vi.advanceTimersByTimeAsync(1_500)
|
||||
expect(dispatchCompletion).not.toHaveBeenCalled()
|
||||
|
||||
await vi.advanceTimersByTimeAsync(750)
|
||||
expect(dispatchCompletion).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('does not mark an agent-to-agent process replacement as terminal idle', async () => {
|
||||
let foregroundProcess = 'codex'
|
||||
const dispatchCompletion = vi.fn()
|
||||
|
||||
@@ -116,6 +116,27 @@ describe('runtime terminal owner routing', () => {
|
||||
expect(localHasChildren).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('preserves unavailable inspection from the PTY owning environment', async () => {
|
||||
runtimeCall.mockResolvedValue({
|
||||
ok: true,
|
||||
result: {
|
||||
process: { foregroundProcess: null, hasChildProcesses: true, unavailable: true }
|
||||
},
|
||||
_meta: { runtimeId: 'runtime-1' }
|
||||
})
|
||||
|
||||
await expect(
|
||||
inspectRuntimeTerminalProcess(
|
||||
{ activeRuntimeEnvironmentId: 'env-2' },
|
||||
'remote:env-1@@terminal-1'
|
||||
)
|
||||
).resolves.toEqual({
|
||||
foregroundProcess: null,
|
||||
hasChildProcesses: true,
|
||||
unavailable: true
|
||||
})
|
||||
})
|
||||
|
||||
it('uses strict main-process inspection for a direct SSH PTY', async () => {
|
||||
localInspect.mockResolvedValue({ foregroundProcess: 'codex', hasChildProcesses: true })
|
||||
|
||||
@@ -128,6 +149,20 @@ describe('runtime terminal owner routing', () => {
|
||||
expect(localHasChildren).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('preserves unavailable inspection for a direct SSH PTY', async () => {
|
||||
localInspect.mockResolvedValue({
|
||||
foregroundProcess: null,
|
||||
hasChildProcesses: true,
|
||||
unavailable: true
|
||||
})
|
||||
|
||||
await expect(inspectRuntimeTerminalProcess(null, 'ssh:host@@pty-1')).resolves.toEqual({
|
||||
foregroundProcess: null,
|
||||
hasChildProcesses: true,
|
||||
unavailable: true
|
||||
})
|
||||
})
|
||||
|
||||
it.each(['no_connected_pty', 'terminal_handle_stale', 'terminal_gone'])(
|
||||
'reports %s remote process inspection as unavailable',
|
||||
async (code) => {
|
||||
|
||||
Reference in New Issue
Block a user