tests: keep the TUI's os._exit(130) SIGINT handler out of the test process (TEST-LEONIDA-TUI-SIGINT-LEAK) #2286
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2286"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ubiquitarianism/leonida. Originally posted by DeadlyChirp on 2026-11-26T12:45:35Z.
Claimed in the coordination issue as: TEST-LEONIDA-TUI-SIGINT-LEAK (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7191378304)
What and why
pytest tests(one process for the whole top-level suite) stops at about 62% with exit code 130 and no summary, attests/test_run_semantic_tests.py::RunnerTest::test_parallel_interrupt_stops_active_processes_and_cancels_queued_jobs.Cause:
tests/test_leonida_tui.pycalls the realleonida_tui.run_setup()andLeonidaBoard.__enter__, and bothcall
install_interrupt_handlers(). That replaces the process-wide SIGINT handler (and on Windows SIGBREAK and theSetConsoleCtrlHandlerhandler) with one that callsos._exit(130), and nothing puts the old one back. Any latertest in the same process that raises KeyboardInterrupt on purpose (the semantic runner's tests use
_thread.interrupt_main()) then runs that handler and ends the test process.Each file passes on its own, so this only shows up under a shared runner. Reproduce on
main:exits 130 after the TUI tests, with no result line.
The fix is in the test file only:
setUpModulepatchesinstall_interrupt_handlersto a no-op for the module (notest here checks the handlers themselves;
force_exit_interruptis still mocked where it was), and a new test checksthat the process SIGINT handler is unchanged after
run_setup().Tested
Windows 11, Python 3.12.10, branch based on
mainata73a57e13:python -m pytest tests/test_leonida_tui.py: 28 passed.python -I tests/test_leonida_tui.py: OK.main: exit 130, no summary).python -m pytest tests/test_leonida_tui.py tests/test_run_semantic_tests.py: 53 passed, 1 skipped.maindoes) fails:AssertionError: <function install_interrupt_handlers.<locals>.<lambda> ...> is not <built-in function default_int_handler>.python -m pytest --ignore=tests/semantic --ignore=tests/test_run_game_wine.py tests(the second path is thefcntlimport fixed by #1876): now runs to the end,46 failed, 10068 passed, 265 skippedin 38 min. The failures are in other files and unrelated to this change (environment ones on this PC: Application Control, symlink privilege, timeouts under load). Onmainthe same command ends at about 62% with exit 130.python -I scripts/check_no_game_data.py tests/test_leonida_tui.py: exit 0.GPUs tested: n/a (no GPU code)
AI-assisted: yes (AI-assisted run; output checked by hand)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a)Imported from ubiquitarianism/leonida. Originally posted by EdenBendheim on 2026-11-26T21:43:40Z.
Locally verified
d96bcbc37againstmainatfac8b4bb9on macOS 27.3 arm64 (Python 3.14.3). Claim confirmed in #1608; patch applies cleanly; no duplicate overlap with #1305 or #2392.main, the 27 existing TUI tests passed but leftsignal.SIGINTreplaced, and the new regression test failed.signal.SIGINTretained its original handler after the module finished.check_no_game_data.pyandcompileallboth passed.Windows signal/console-callback paths were reviewed by inspection only. Non-blocking note: the new test at
tests/test_leonida_tui.py:512exercisesrun_setup()directly (the post-suite check covered the board tests as well).Synthetic inputs only; no game data. GPUs tested: N/A (CPU-only). AI-assisted verification.
Imported from ubiquitarianism/leonida. Originally posted by tiguan26 on 2026-11-27T04:39:37Z.
Review: APPROVED
Approving
d96bcbc37.Patching
install_interrupt_handlersfor the module keeps the TUI'sos._exit(130)handler out of a shared test process, and the new test checks thatrun_setupleaves the process's SIGINT handler as it found it. One nit, not blocking: the new test'swithstatement sits on one very long line (the context managers look like they lost their line continuations); splitting it would read better.Merged onto
maind1dff7949together with #2403, #2410, #2299, #2297 and #2330 (no conflicts), on Linux with Python 3.13.tests/test_leonida_tui.py: 28 passed (main: 27). AI-assisted (Claude Code, Claude Opus 5.5).Imported from ubiquitarianism/leonida. Originally posted by DadaCap on 2026-11-28T08:04:58Z.
Merged into
main(merge commit8451e2dcc), approved by DadaCap (maintainer). Thanks!Checked before merging: Tested in our local release candidate (main + 41 PRs): translator suite 512 files / 6,442 tests clean, Python suite with no new failure versus main, and 360 s game runs on an RTX 5080 with no regression. The merge was pinned to the head commit that was tested (
d96bcbc37).AI-assisted (Claude Code), posted for DadaCap.