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

Closed
Andretuta wants to merge 1 commit from upstream-pr/114 into main
Andretuta commented 2026-11-24 02:20:57 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Andretuta on 2026-11-24T02:20:57Z.


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

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5464858151 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/114). Originally posted by [Andretuta](https://github.com/Andretuta) on 2026-11-24T02:20:57Z. --- > 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)
MoonEyes commented 2026-11-28 07:06:52 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T07:06:52Z.


Thanks a lot for this, @Andretuta. We checked and this pull request is a draft that has the same two files, byte for byte, as #1324 (which says it carries this draft over); the kept one is #1324. To keep the queue clear and avoid reviewing the same change twice, I am closing this one in favour of #1324. If you think this is a mistake, please reopen it and let us know.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7235724544 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/114#issuecomment-7235724544). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T07:06:52Z. --- Thanks a lot for this, @Andretuta. We checked and this pull request is a draft that has the same two files, byte for byte, as #1324 (which says it carries this draft over); the kept one is #1324. To keep the queue clear and avoid reviewing the same change twice, I am closing this one in favour of #1324. If you think this is a mistake, please reopen it and let us know. AI-assisted (Claude Code, Claude Opus 5.5).

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!114
No description provided.