From 803a0c4e338b60c6e8bfae7243cb9adad5de17a1 Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Sat, 11 Jul 2026 01:49:48 -0700 Subject: [PATCH] test: reproduce pre-handler PTY exit retention --- .../pty-pre-handler-buffer.test.ts | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/renderer/src/components/terminal-pane/pty-pre-handler-buffer.test.ts b/src/renderer/src/components/terminal-pane/pty-pre-handler-buffer.test.ts index 7d95304ba90..1095e404d72 100644 --- a/src/renderer/src/components/terminal-pane/pty-pre-handler-buffer.test.ts +++ b/src/renderer/src/components/terminal-pane/pty-pre-handler-buffer.test.ts @@ -1,17 +1,23 @@ import { afterEach, describe, expect, it } from 'vitest' import { bufferPreHandlerPtyData, + bufferPreHandlerPtyExit, clearPreHandlerPtyState, - drainPreHandlerPtyData + drainPreHandlerPtyData, + drainPreHandlerPtyExit } from './pty-pre-handler-buffer' const RESCAN_PTY_ID = 'pty-pre-handler-rescan' const TRIM_PTY_ID = 'pty-pre-handler-trim' +const EXIT_PTY_IDS = Array.from({ length: 65 }, (_, index) => `pty-pre-handler-exit-${index}`) describe('pre-handler PTY buffer', () => { afterEach(() => { clearPreHandlerPtyState(RESCAN_PTY_ID) clearPreHandlerPtyState(TRIM_PTY_ID) + for (const ptyId of EXIT_PTY_IDS) { + clearPreHandlerPtyState(ptyId) + } }) it('does not rescan historical chunks while buffering small startup output', () => { @@ -71,4 +77,22 @@ describe('pre-handler PTY buffer', () => { expect(drained).toHaveLength(512) expect(drained.join('')).toHaveLength(512 * 1_024) }) + + it('bounds exits that arrive before any handler is registered', () => { + for (let index = 0; index < EXIT_PTY_IDS.length; index += 1) { + bufferPreHandlerPtyExit(EXIT_PTY_IDS[index], index) + } + + let oldestExit: number | null = null + drainPreHandlerPtyExit(EXIT_PTY_IDS[0], (code) => { + oldestExit = code + }) + let newestExit: number | null = null + drainPreHandlerPtyExit(EXIT_PTY_IDS.at(-1)!, (code) => { + newestExit = code + }) + + expect(oldestExit).toBeNull() + expect(newestExit).toBe(64) + }) })