@@ -196,6 +196,9 @@ describe("TerminalProcess", () => {
196196
197197 beforeEach ( ( ) => {
198198 vi . useFakeTimers ( )
199+ // abort() runs against the terminal's *current* process; mirror that wiring so
200+ // the reuse guard (terminal.process === this) lets the retry loop proceed.
201+ mockTerminalInfo . process = terminalProcess
199202 } )
200203
201204 afterEach ( ( ) => {
@@ -242,8 +245,29 @@ describe("TerminalProcess", () => {
242245 await vi . advanceTimersByTimeAsync ( RETRY_DELAY_MS )
243246 expect ( mockTerminal . sendText ) . toHaveBeenCalledTimes ( 2 )
244247
245- // Process exits before the next tick.
246- mockTerminalInfo . busy = false
248+ // Process exits before the next tick — drive the real completion lifecycle
249+ // (shellExecutionComplete clears busy and releases terminal.process) rather than
250+ // mutating busy directly, so the test exercises the production wiring.
251+ mockTerminalInfo . shellExecutionComplete ( { exitCode : 0 } )
252+ await vi . advanceTimersByTimeAsync ( RETRY_DELAY_MS * MAX_ATTEMPTS )
253+
254+ expect ( mockTerminal . sendText ) . toHaveBeenCalledTimes ( 2 )
255+ } )
256+
257+ it ( "stops re-sending Ctrl+C if the terminal is reused for a different process (#266)" , async ( ) => {
258+ mockTerminalInfo . busy = true
259+
260+ terminalProcess . abort ( )
261+ expect ( mockTerminal . sendText ) . toHaveBeenCalledTimes ( 1 )
262+
263+ // First retry tick: still busy, re-send.
264+ await vi . advanceTimersByTimeAsync ( RETRY_DELAY_MS )
265+ expect ( mockTerminal . sendText ) . toHaveBeenCalledTimes ( 2 )
266+
267+ // The original command exits and the terminal is reused for a NEW command before
268+ // the next tick: terminal stays busy, but terminal.process now points at a
269+ // different process. The retry must not interrupt that unrelated command.
270+ mockTerminalInfo . process = new TestTerminalProcess ( mockTerminalInfo )
247271 await vi . advanceTimersByTimeAsync ( RETRY_DELAY_MS * MAX_ATTEMPTS )
248272
249273 expect ( mockTerminal . sendText ) . toHaveBeenCalledTimes ( 2 )
0 commit comments