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

Open
opened 2026-11-26 20:17:00 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/114
Author: @Andretuta
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: old-pr/9848


📝 Commits (1)

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

📊 Changes

2 files changed (+59 additions, -0 deletions)

View changed files

➕ tests/test_conformance_compare_crash.py (+58 -0)
📝 tools/conformance/compare.py (+1 -0)

📄 Description

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


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/114 **Author:** [@Andretuta](https://github.com/Andretuta) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `old-pr/9848` --- ### 📝 Commits (1) - [`9aece26`](https://github.com/ubiquitarianism/leonida/commit/9aece26a3eb14f08d1ae2b863c3f232cf8d8f2f8) conformance/compare.py: import traceback, so an unexpected crash exits 2 and not the mismatch code 1 ### 📊 Changes **2 files changed** (+59 additions, -0 deletions) <details> <summary>View changed files</summary> ➕ `tests/test_conformance_compare_crash.py` (+58 -0) 📝 `tools/conformance/compare.py` (+1 -0) </details> ### 📄 Description > 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) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#165
No description provided.