tests: keep the TUI's os._exit(130) SIGINT handler out of the test process (TEST-LEONIDA-TUI-SIGINT-LEAK) #2286

Open
github-bot wants to merge 1 commit from github-bot/gh-2286 into main AGit
Owner

@⁠DeadlyChirp on GitHub · 2026-11-26 12:45 UTC · original
DeadlyChirp:fix/tui-tests-sigint-leak → main · +25 −0 · 1 files · 1 commits · open

Claimed in the coordination issue as: TEST-LEONIDA-TUI-SIGINT-LEAK (#1608)

What and why

pytest tests (one process for the whole top-level suite) stops at about 62% with exit code 130 and no summary, at
tests/test_run_semantic_tests.py::RunnerTest::test_parallel_interrupt_stops_active_processes_and_cancels_queued_jobs.

Cause: tests/test_leonida_tui.py calls the real leonida_tui.run_setup() and LeonidaBoard.__enter__, and both
call install_interrupt_handlers(). That replaces the process-wide SIGINT handler (and on Windows SIGBREAK and the
SetConsoleCtrlHandler handler) with one that calls os._exit(130), and nothing puts the old one back. Any later
test 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:

python -m pytest tests/test_leonida_tui.py "tests/test_run_semantic_tests.py::RunnerTest::test_parallel_interrupt_stops_active_processes_and_cancels_queued_jobs"

exits 130 after the TUI tests, with no result line.

The fix is in the test file only: setUpModule patches install_interrupt_handlers to a no-op for the module (no
test here checks the handlers themselves; force_exit_interrupt is still mocked where it was), and a new test checks
that the process SIGINT handler is unchanged after run_setup().

Tested

Windows 11, Python 3.12.10, branch based on main at a73a57e13:

  • python -m pytest tests/test_leonida_tui.py: 28 passed.
  • python -I tests/test_leonida_tui.py: OK.
  • The pair command above: 29 passed, exit 0 (on main: exit 130, no summary).
  • python -m pytest tests/test_leonida_tui.py tests/test_run_semantic_tests.py: 53 passed, 1 skipped.
  • The new test with the module patch turned off (what main does) 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 the fcntl import fixed by #1876): now runs to the end, 46 failed, 10068 passed, 265 skipped in 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). On main the 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

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a)
**@⁠DeadlyChirp** on GitHub · 2026-11-26 12:45 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2286) `DeadlyChirp:fix/tui-tests-sigint-leak` → `main` · +25 −0 · 1 files · 1 commits · open Claimed in the coordination issue as: TEST-LEONIDA-TUI-SIGINT-LEAK (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### What and why `pytest tests` (one process for the whole top-level suite) stops at about 62% with exit code 130 and no summary, at `tests/test_run_semantic_tests.py::RunnerTest::test_parallel_interrupt_stops_active_processes_and_cancels_queued_jobs`. Cause: `tests/test_leonida_tui.py` calls the real `leonida_tui.run_setup()` and `LeonidaBoard.__enter__`, and both call `install_interrupt_handlers()`. That replaces the process-wide SIGINT handler (and on Windows SIGBREAK and the `SetConsoleCtrlHandler` handler) with one that calls `os._exit(130)`, and nothing puts the old one back. Any later test 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`: ``` python -m pytest tests/test_leonida_tui.py "tests/test_run_semantic_tests.py::RunnerTest::test_parallel_interrupt_stops_active_processes_and_cancels_queued_jobs" ``` exits 130 after the TUI tests, with no result line. The fix is in the test file only: `setUpModule` patches `install_interrupt_handlers` to a no-op for the module (no test here checks the handlers themselves; `force_exit_interrupt` is still mocked where it was), and a new test checks that the process SIGINT handler is unchanged after `run_setup()`. ### Tested Windows 11, Python 3.12.10, branch based on `main` at a73a57e13: - `python -m pytest tests/test_leonida_tui.py`: 28 passed. - `python -I tests/test_leonida_tui.py`: OK. - The pair command above: 29 passed, exit 0 (on `main`: exit 130, no summary). - `python -m pytest tests/test_leonida_tui.py tests/test_run_semantic_tests.py`: 53 passed, 1 skipped. - The new test with the module patch turned off (what `main` does) 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 the `fcntl` import fixed by #1876): now runs to the end, `46 failed, 10068 passed, 265 skipped` in 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). On `main` the 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 - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a)
run_setup() and LeonidaBoard.__enter__ call install_interrupt_handlers(), which
replaces the process-wide SIGINT handler (and on Windows SIGBREAK and the console
control handler) with one that calls os._exit(130) and never restores the old one.
Under one shared runner (pytest tests) a later test that raises KeyboardInterrupt on
purpose, such as test_run_semantic_tests.py's interrupt tests, then ends the whole
test process with exit code 130 and no summary.

Patch install_interrupt_handlers to a no-op for the module and add a test that the
process SIGINT handler is unchanged after run_setup().
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 12:46:33 +00:00
Author
Owner

@⁠EdenBendheim on GitHub · 2026-11-26 21:43 UTC · original

Locally verified d96bcbc37 against main at fac8b4bb9 on macOS 27.3 arm64 (Python 3.14.3). Claim confirmed in #1608; patch applies cleanly; no duplicate overlap with #1305 or #2392.

  • On plain main, the 27 existing TUI tests passed but left signal.SIGINT replaced, and the new regression test failed.
  • With the patch, all 28 TUI tests passed and signal.SIGINT retained its original handler after the module finished.
  • check_no_game_data.py and compileall both passed.

Windows signal/console-callback paths were reviewed by inspection only. Non-blocking note: the new test at tests/test_leonida_tui.py:512 exercises run_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.

**@⁠EdenBendheim** on GitHub · 2026-11-26 21:43 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2286#issuecomment-7204002167) Locally verified `d96bcbc37` against `main` at `fac8b4bb9` on macOS 27.3 arm64 (Python 3.14.3). Claim confirmed in #1608; patch applies cleanly; no duplicate overlap with #1305 or #2392. - On plain `main`, the 27 existing TUI tests passed but left `signal.SIGINT` replaced, and the new regression test failed. - With the patch, all 28 TUI tests passed and `signal.SIGINT` retained its original handler after the module finished. - `check_no_game_data.py` and `compileall` both passed. Windows signal/console-callback paths were reviewed by inspection only. Non-blocking note: the new test at `tests/test_leonida_tui.py:512` exercises `run_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.
Author
Owner

@⁠tiguan26 on GitHub · 2026-11-27 04:39 UTC · original · approved these changes

Approving d96bcbc37.

Patching install_interrupt_handlers for the module keeps the TUI's os._exit(130) handler out of a shared test process, and the new test checks that run_setup leaves the process's SIGINT handler as it found it. One nit, not blocking: the new test's with statement sits on one very long line (the context managers look like they lost their line continuations); splitting it would read better.

Merged onto main d1dff7949 together 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).

**@⁠tiguan26** on GitHub · 2026-11-27 04:39 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2286#pullrequestreview-6083558194) · **approved these changes** Approving d96bcbc37. Patching `install_interrupt_handlers` for the module keeps the TUI's `os._exit(130)` handler out of a shared test process, and the new test checks that `run_setup` leaves the process's SIGINT handler as it found it. One nit, not blocking: the new test's `with` statement sits on one very long line (the context managers look like they lost their line continuations); splitting it would read better. Merged onto `main` `d1dff7949` together 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).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2286/head:github-bot/gh-2286'
git switch 'github-bot/gh-2286'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2286'
git switch 'github-bot/gh-2286'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2286'
git switch 'github-bot/gh-2286'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2286'
git switch 'main'
git merge --squash 'github-bot/gh-2286'
git switch 'main'
git merge --ff-only 'github-bot/gh-2286'
git switch 'main'
git merge 'github-bot/gh-2286'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.