Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

test(hibernate): pin opencode split exit delivery

Alex81da4c5ec279
diff --git a/src/renderer/terminal/agent-restart.test.ts b/src/renderer/terminal/agent-restart.test.ts
index 422798cb8..952f0c75f 100644
--- a/src/renderer/terminal/agent-restart.test.ts
+++ b/src/renderer/terminal/agent-restart.test.ts
@@ -590,6 +590,71 @@ describe('performExitPhase', () => {
await vi.advanceTimersByTimeAsync(200)
expect(await p).toBe('not-eligible') // not a timeout: there is no pane left to time out in
})
+
+ it('splits opencode exit into text then CR (batched-input guard), leaving others one-burst', async () => {
+ // opencode's TUI swallows a one-burst `/exit\r` (measured 1.18.18-1.18.25, Linux, tmux, isolated
+ // socket: `/exit` left in composer with popup armed, exit-timeout at 6s; split CR by 100ms exits
+ // in ~500ms, shipped with 150ms). This pins the split so a refactor cannot silently re-batch it.
+ for (const agentId of ['opencode'] as const) {
+ const { written, io } = fakeIo()
+ let pane = 'opencode'
+ const p = performExitPhase({
+ agentId,
+ sessionId: 'sid-1',
+ io,
+ paneCommand: async () => pane,
+ timeoutMs: 6000,
+ pollMs: 100
+ })
+ // Pre-flight resolves; KILL_LINE + exit text are written, CR not yet.
+ await vi.advanceTimersByTimeAsync(0)
+ expect(written).toEqual(['\x15', '/exit'])
+ await vi.advanceTimersByTimeAsync(150)
+ expect(written).toEqual(['\x15', '/exit', '\r'])
+ pane = 'zsh'
+ await vi.advanceTimersByTimeAsync(5000)
+ expect(await p).toBe('exited')
+ }
+ // Every other agent keeps the historical one-burst path byte-identical.
+ for (const agentId of ['claude', 'codex', 'grok', 'gemini', 'copilot'] as const) {
+ const { written, io } = fakeIo()
+ let pane: string = agentId
+ const p = performExitPhase({
+ agentId,
+ sessionId: 'sid-1',
+ io,
+ paneCommand: async () => pane,
+ timeoutMs: 6000,
+ pollMs: 100
+ })
+ await vi.advanceTimersByTimeAsync(0)
+ const exit = agentId === 'claude' || agentId === 'copilot' ? '/exit' : '/quit'
+ expect(written).toEqual(['\x15', `${exit}\r`])
+ pane = 'zsh'
+ await vi.advanceTimersByTimeAsync(5000)
+ expect(await p).toBe('exited')
+ }
+ })
+
+ it('abandons the split CR when the pane dies mid-delay', async () => {
+ const { written, io } = fakeIo()
+ let live = true
+ const p = performExitPhase({
+ agentId: 'opencode',
+ sessionId: 'sid-1',
+ io,
+ paneCommand: async () => 'opencode',
+ timeoutMs: 6000,
+ pollMs: 100,
+ isLive: () => live
+ })
+ await vi.advanceTimersByTimeAsync(0)
+ expect(written).toEqual(['\x15', '/exit'])
+ live = false
+ await vi.advanceTimersByTimeAsync(200)
+ expect(await p).toBe('not-eligible')
+ expect(written).toEqual(['\x15', '/exit']) // CR never sent into a dead pane
+ })
})
describe('performResumePhase', () => {