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 <roo-code@z.ewheeler.org>
This commit is contained in:
Eric Wheeler 2025-03-10 21:22:19 -07:00
parent 62ffa7973c
commit 701b5a7d87

View file

@ -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<void>((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,