davsclaus opened a new pull request, #27237: URL: https://github.com/apache/camel/pull/27237
`AiCliCommandExecutorTest.productionInvokerRestoresPrinterAndDoesNotQuitMain` failed now and then with: ``` expected: <...Printer$SystemOutPrinter@...> but was: <...tui.ShellPanel$3@...> ``` ### Cause The shell panel's shell thread swaps the printer of the Camel CLI (`CamelJBangMain.setOut`) so command output goes into the panel. Two problems: - the thread read the **static** `CamelJBangMain.getCommandLine()` when it got going, which is later than the panel started it; - `destroy()` only interrupted the thread, and the shell kept running, so the swapped printer was **never put back**. `BorderRenderTest.shellPanelRendersWithBorder` opens and renders a shell panel, which starts a real shell. When that leftover shell got going while `AiCliCommandExecutorTest` had pointed the static command line at its own `CamelJBangMain`, it took that main's printer: the `ShellPanel$3` in the failure. Whether the timing lines up depends on the test order and the machine, hence flaky. The same race exists in the TUI: opening and closing the shell panel quickly. ### Fix (`ShellPanel`) - The command line is taken when the shell **starts**, on the caller's thread, and handed to the shell thread. Without a Camel command line there is no shell; the panel says so. - `destroy()` closes the virtual terminal (the shell's input ends), interrupts, and waits (up to 2s) for the shell to put the printer back. ### Testing - New `ShellPanelLifecycleTest`: starts the shell with command line A, points the static at B right away (as the other test does), and checks the shell took A's printer only, left B's alone, and put A's back before `destroy()` returns. **It fails without the fix** with the same `ShellPanel$3` printer as the flaky test. - `ShellPanelLifecycleTest` + `AiCliCommandExecutorTest` + `BorderRenderTest` 10 times in a row: no failures; the `camel-jbang-plugin-tui` suite twice: 1570 tests, no failures. _Claude Code on behalf of davsclaus_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
