conformance/compare.py: import traceback, so an unexpected crash exits 2 and not the mismatch code 1 #114

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

@⁠Andretuta on GitHub · 2026-11-24 02:20 UTC · original
ubiquitarianism:old-pr/9848 → main · +59 −0 · 2 files · 1 commits · draft

Carried over from old PR 9848 by Bios2000 in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch old-pr/9848, exactly that PR's last commit. All carried-over PRs are listed in #17.
Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it.
Bios2000: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one.


Original description (mentions and #N references are disabled; the numbers refer to the old repository):

Claimed in the coordination issue as: https://github.com/ProjectLeonida/Leonida/issues/9677#issuecomment-7116701113 (new item)

What and why

main() in tools/conformance/compare.py catches any exception a handler did not anticipate and is meant to
turn it into exit 2 ("the tool could not run"), never 1 ("the run completed and found a mismatch"). Its except
block calls traceback.print_exc(), but the module never imports traceback. So the handler itself raises
NameError, which escapes main(), and Python exits 1. A calling script reads a crash in compare.py as
differing pixels.

  • tools/conformance/compare.py: import traceback.
  • tests/test_conformance_compare_crash.py (new, standard library only):
    • patches command_inspect to raise and checks that main() returns EXIT_ERROR;
    • checks that stderr has the traceback and the "bug in compare.py, not a pixel mismatch" line, and no NameError;
    • checks the exit status of the script as a subprocess (2).

#4713 made the same one-line change and was closed unmerged together with the rest of the backlog; this one
carries its own test.

Tested

Arch Linux, Python 3.14.10, Node 26.13.1, at 2d53a8055. Neither the change nor its test uses the GPU.

  • On main without the fix, the new test fails: NameError: name 'traceback' is not defined, and the script
    exits 1. With the fix it passes, and so do the other tests/test_conformance_*.py.
  • Whole suite, with this PR and the other one on top of main at once (tests/test_ttpf_assets.py only; the
    two touch different files), compared with main itself:
    • standard-library loop: 455 files, 24 failing, against 454 and 25 on main. The difference is this PR's new
      test passing and the test_ttpf_assets fix; every other failure is the same file on main.
    • pytest files: identical, 3 failed and 1855 passed.
    • scripts/run_semantic_tests.py: identical, 6046 tests, the same 2 files failing.
    • node --test: identical, 1 failing; #9823 fixes it.
    • compileall and make_game.py --help: OK.
    • The failures that main has were already there before this PR.
  • scripts/check_no_game_data.py and pyflakes on the changed files: clean.

AI-assisted: yes (Claude Code, Claude Opus 5.5)

Checklist

  • 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: no translator change)

🤖 Generated with Claude Code

**@⁠Andretuta** on GitHub · 2026-11-24 02:20 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/114) `ubiquitarianism:old-pr/9848` → `main` · +59 −0 · 2 files · 1 commits · draft > Carried over from **old PR 9848** by `Bios2000` in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch `old-pr/9848`, exactly that PR's last commit. All carried-over PRs are listed in #17. > Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it. > `Bios2000`: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one. --- Original description (mentions and `#N` references are disabled; the numbers refer to the old repository): Claimed in the coordination issue as: https://github.com/ProjectLeonida/Leonida/issues/9677#issuecomment-7116701113 (new item) ### What and why `main()` in `tools/conformance/compare.py` catches any exception a handler did not anticipate and is meant to turn it into exit 2 ("the tool could not run"), never 1 ("the run completed and found a mismatch"). Its except block calls `traceback.print_exc()`, but the module never imports `traceback`. So the handler itself raises `NameError`, which escapes `main()`, and Python exits 1. A calling script reads a crash in compare.py as differing pixels. - `tools/conformance/compare.py`: `import traceback`. - `tests/test_conformance_compare_crash.py` (new, standard library only): - patches `command_inspect` to raise and checks that `main()` returns `EXIT_ERROR`; - checks that stderr has the traceback and the "bug in compare.py, not a pixel mismatch" line, and no `NameError`; - checks the exit status of the script as a subprocess (2). `#4713` made the same one-line change and was closed unmerged together with the rest of the backlog; this one carries its own test. ### Tested Arch Linux, Python 3.14.10, Node 26.13.1, at `2d53a8055`. Neither the change nor its test uses the GPU. - On `main` without the fix, the new test fails: `NameError: name 'traceback' is not defined`, and the script exits 1. With the fix it passes, and so do the other `tests/test_conformance_*.py`. - Whole suite, with this PR and the other one on top of `main` at once (`tests/test_ttpf_assets.py` only; the two touch different files), compared with `main` itself: - standard-library loop: 455 files, 24 failing, against 454 and 25 on `main`. The difference is this PR's new test passing and the `test_ttpf_assets` fix; every other failure is the same file on `main`. - pytest files: identical, 3 failed and 1855 passed. - `scripts/run_semantic_tests.py`: identical, 6046 tests, the same 2 files failing. - `node --test`: identical, 1 failing; `#9823` fixes it. - `compileall` and `make_game.py --help`: OK. - The failures that `main` has were already there before this PR. - `scripts/check_no_game_data.py` and pyflakes on the changed files: clean. AI-assisted: yes (Claude Code, Claude Opus 5.5) ### Checklist - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator change) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
main()'s catch-all calls traceback.print_exc(), but the module never imported traceback. Any
exception a handler did not anticipate therefore raised NameError inside the except block, which
escaped main() and made Python exit 1: the code that means "the run completed and found a
mismatch". A calling script could not tell a crash from differing pixels.

tests/test_conformance_compare_crash.py makes a handler raise and checks both main()'s return
value and the exit status of the script (2, with the traceback and the "bug in compare.py" line,
and no NameError).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:44:57 +00:00
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/114/head:github-bot/gh-114'
git switch 'github-bot/gh-114'

Merge

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