From 701b5a7d876fd38d076b67118ba469627657b7ab Mon Sep 17 00:00:00 2001 From: Eric Wheeler Date: Mon, 10 Mar 2025 21:22:19 -0700 Subject: [PATCH] test: align terminal tests with shell integration safeguards Update TerminalProcessExec tests to properly handle shell integration event sequences: - Set terminal.running=true before command execution - Remove duplicate command execution that could trigger extra events - Replace arbitrary timeout with event-based waiting for output - Ensure proper event sequence (run -> start -> output -> end) This aligns the tests with the safeguards added in 62ffa797 that prevent spurious shell integration events from corrupting terminal state. Signed-off-by: Eric Wheeler --- .../__tests__/TerminalProcessExec.test.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/integrations/terminal/__tests__/TerminalProcessExec.test.ts b/src/integrations/terminal/__tests__/TerminalProcessExec.test.ts index ab14a503c8..0e719daa1b 100644 --- a/src/integrations/terminal/__tests__/TerminalProcessExec.test.ts +++ b/src/integrations/terminal/__tests__/TerminalProcessExec.test.ts @@ -129,8 +129,9 @@ async function testTerminalCommand( sendText: jest.fn(), } - // Create terminal info + // Create terminal info with running state const mockTerminalInfo = new Terminal(1, mockTerminal, "/test/path") + mockTerminalInfo.running = true // Add the terminal to the registry TerminalRegistry["terminals"] = [mockTerminalInfo] @@ -150,9 +151,6 @@ async function testTerminalCommand( } }) - // Execute the command - terminalProcess.run(command) - // Set up event listeners to capture output let capturedOutput = "" terminalProcess.on("completed", (output) => { @@ -181,6 +179,9 @@ async function testTerminalCommand( // Get the event handlers from the mock const eventHandlers = (vscode as any).__eventHandlers + // Execute the command first to set up the process + terminalProcess.run(command) + // Trigger the start terminal shell execution event through VSCode mock if (eventHandlers.startTerminalShellExecution) { eventHandlers.startTerminalShellExecution({ @@ -192,10 +193,12 @@ async function testTerminalCommand( }) } - // Wait a short time to ensure stream processing has started - await new Promise((resolve) => setTimeout(resolve, 100)) + // Wait for some output to be processed + await new Promise((resolve) => { + terminalProcess.once("line", () => resolve()) + }) - // Trigger the end terminal shell execution event through VSCode mock + // Then trigger the end event if (eventHandlers.endTerminalShellExecution) { eventHandlers.endTerminalShellExecution({ terminal: mockTerminal,