Skip to content

Commit 90b89f4

Browse files
committed
fix(hub): keep PTY restart retryable
1 parent 6a26f09 commit 90b89f4

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

packages/hub/src/node/__tests__/host-terminals.test.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -538,17 +538,17 @@ describe('devframeTerminalHost interactive PTY sessions', () => {
538538
expect(secondOutput.output).not.toContain(`run:${firstResult.pid}`)
539539
})
540540

541-
itPty('reports a structured error when restart fails to spawn a PTY', async () => {
542-
expect.assertions(5)
541+
itPty('allows retry after a structured PTY restart spawn error', async () => {
542+
expect.assertions(9)
543543

544544
const { host } = createTerminalHost()
545545
const session = await host.startPtySession({
546546
command: NODE,
547-
args: ['-e', 'process.stdout.write("started"); setInterval(() => {}, 4000)'],
547+
args: ['-e', 'process.stdout.write("started:" + process.pid); setInterval(() => {}, 4000)'],
548548
}, { id: 'pty-result-restart-error', title: 'PTY result restart error' })
549549
const result = session.getResult()
550550
await waitUntil(() => {
551-
if (!session.buffer?.join('').includes('started'))
551+
if (!session.buffer?.join('').includes(`started:${result.pid}`))
552552
throw new Error('PTY output has not started')
553553
})
554554
zigptyModuleMock.spawn.mockImplementationOnce(() => {
@@ -559,10 +559,22 @@ describe('devframeTerminalHost interactive PTY sessions', () => {
559559
expect(session.status).toBe('error')
560560
expect(session.getProcessName()).toBeUndefined()
561561
expect(session.getResult()).toBe(result)
562+
563+
await expect(session.restart()).resolves.toBeUndefined()
564+
expect(session.status).toBe('running')
565+
const retryResult = session.getResult()
566+
expect(retryResult).not.toBe(result)
567+
await waitUntil(() => {
568+
if (!session.buffer?.join('').includes(`started:${retryResult.pid}`))
569+
throw new Error('Retried PTY output has not started')
570+
})
571+
expect(session.buffer?.join('')).toContain(`started:${retryResult.pid}`)
572+
await session.terminate()
562573
await expect(result).resolves.toMatchObject({
563-
output: expect.stringContaining('started'),
574+
output: expect.stringContaining(`started:${result.pid}`),
564575
exitCode: undefined,
565576
})
577+
await retryResult
566578
})
567579

568580
itPty('does not accept resize after termination without throwing', async () => {

packages/hub/src/node/host-terminals.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,12 +548,12 @@ export class DevframeTerminalsHost implements DevframeTerminalsHostType {
548548
if (streamClosed)
549549
throw diagnostics.DF8206({ id: terminal.id })
550550
killCurrentRun?.()
551+
killCurrentRun = undefined
551552
pty = undefined
552553
try {
553554
pty = spawnPty()
554555
}
555556
catch (error) {
556-
errorStream(error)
557557
markStatus('error')
558558
throw diagnostics.DF8203({
559559
command: executeOptions.command,

0 commit comments

Comments
 (0)