conformance compare: harden crash and image input error handling #2205

Merged
leonida/mandy
whoalin1 merged 2 commits from compare-unexpected-exit2 into main 2026-11-29 14:13:32 +00:00

Pull request successfully merged and closed

whoalin1 commented 2026-11-26 05:45:13 +00:00

Summary

  • import traceback in tools/conformance/compare.py, so the existing catch-all can actually print the traceback and return EXIT_ERROR
  • add a regression test proving an unexpected handler crash returns/exits 2 rather than leaking as Python exit 1, the documented pixel-mismatch code

Item: TEST-CONFORMANCE-COMPARE-TRACEBACK

This carries forward the still-uncarried fix in old-pr/9848, originally written by David, reapplied and verified on current main.

Tests

Under the local machine coordination lock:

  • before the one-line fix, the new test fails with NameError: name 'traceback' is not defined and the script-level path exits 1
  • after the fix: python -I tests/test_conformance_compare_crash.py — 2 tests, OK
  • python -m compileall -q tools/conformance/compare.py tests/test_conformance_compare_crash.py — pass
  • git diff --check — pass

No game files, renderer or GPU.

AI-assisted with Devin.

Consolidated conformance hardening

This branch now also includes the two conformance-compare fixes formerly opened as #2212 and #2213:

  • expect returns input-error exit 2 for unreadable, missing, or corrupt images instead of reporting them as ordinary pixel mismatches;
  • PNG parsing rejects invalid critical chunk structure before scanning image data.

The consolidated branch is the original reviewed commit plus cherry-picks 8754c9b90 and dbfcd31ab; no additional code was written during consolidation. Independent reviewers had already verified the individual fixes and reported that the overlapping compare.py branches merge cleanly together.

## Summary - import `traceback` in `tools/conformance/compare.py`, so the existing catch-all can actually print the traceback and return `EXIT_ERROR` - add a regression test proving an unexpected handler crash returns/exits 2 rather than leaking as Python exit 1, the documented pixel-mismatch code Item: TEST-CONFORMANCE-COMPARE-TRACEBACK This carries forward the still-uncarried fix in old-pr/9848, originally written by David, reapplied and verified on current main. ## Tests Under the local machine coordination lock: - before the one-line fix, the new test fails with `NameError: name 'traceback' is not defined` and the script-level path exits 1 - after the fix: `python -I tests/test_conformance_compare_crash.py` — 2 tests, OK - `python -m compileall -q tools/conformance/compare.py tests/test_conformance_compare_crash.py` — pass - `git diff --check` — pass No game files, renderer or GPU. AI-assisted with Devin. ## Consolidated conformance hardening This branch now also includes the two conformance-compare fixes formerly opened as #2212 and #2213: - `expect` returns input-error exit 2 for unreadable, missing, or corrupt images instead of reporting them as ordinary pixel mismatches; - PNG parsing rejects invalid critical chunk structure before scanning image data. The consolidated branch is the original reviewed commit plus cherry-picks `8754c9b90` and `dbfcd31ab`; no additional code was written during consolidation. Independent reviewers had already verified the individual fixes and reported that the overlapping compare.py branches merge cleanly together.
DeadlyChirp commented 2026-11-26 10:50:18 +00:00

Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main.

  • tests/test_conformance_compare_crash.py: 2 passed.
  • The same tests against main code: 2 failed, so they catch the bug this PR fixes.

(AI-assisted test run; output checked by hand.)

Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main. - `tests/test_conformance_compare_crash.py`: 2 passed. - The same tests against main code: 2 failed, so they catch the bug this PR fixes. (AI-assisted test run; output checked by hand.)
real-rusher commented 2026-11-26 12:23:47 +00:00

Verified on main a73a57e1 (Ubuntu 24.04 x86-64, Python 3.13, no GPU). Merges cleanly. With this PR, python -I tests/test_conformance_compare_crash.py: 2 tests OK. The same file against main's compare.py: 1 failure and 1 error, so it fails on main and passes with the change. compileall clean.

Note for review: #114 and #1324 (both "conformance/compare.py: import traceback, so an unexpected crash exits 2 and not the mismatch code 1") make the same one-line import fix and are still open, so only one of the three should land; this one is the one with a test. It merges cleanly with #2212 and #2213, which also touch compare.py.

AI-assisted: yes (Claude Code)

Verified on main a73a57e1 (Ubuntu 24.04 x86-64, Python 3.13, no GPU). Merges cleanly. With this PR, python -I tests/test_conformance_compare_crash.py: 2 tests OK. The same file against main's compare.py: 1 failure and 1 error, so it fails on main and passes with the change. compileall clean. Note for review: #114 and #1324 (both "conformance/compare.py: import traceback, so an unexpected crash exits 2 and not the mismatch code 1") make the same one-line import fix and are still open, so only one of the three should land; this one is the one with a test. It merges cleanly with #2212 and #2213, which also touch compare.py. AI-assisted: yes (Claude Code)
whoalin1 commented 2026-11-26 13:05:41 +00:00

Thanks for the overlap check. I agree only one of these should land. This branch intentionally pairs the one-line unexpected-crash fix with regression coverage, and it merges cleanly with #2212/#2213. I am happy to close or reshape it if the maintainers prefer #114 or #1324, but it is open as the tested candidate. AI-assisted with Devin.

Thanks for the overlap check. I agree only one of these should land. This branch intentionally pairs the one-line unexpected-crash fix with regression coverage, and it merges cleanly with #2212/#2213. I am happy to close or reshape it if the maintainers prefer #114 or #1324, but it is open as the tested candidate. AI-assisted with Devin.
sodove commented 2026-11-28 09:15:08 +00:00

#2205 | head dbfcd31ab890482fb1f008aa9e362486a0424e63 | python3 -I tests/test_conformance_compare_crash.py -v, python3 -I tests/test_conformance_expect_status.py -v, python3 -I tests/test_conformance_png_transparency.py -v | red: 9 tests, 13 assertion failures, 1 error | green: 9 passed | Red → green

The baseline produced an incorrect exit status for a handler failure and for missing image input. PNG structure assertions also failed. Failure and error counts include subtest events.

Pinned main 4938673668d807bf365b61284bf22b1ff8d02cc4, merged into the PR head. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Full suite: not run. AI-assisted: OpenAI Codex. Batch claim.

#2205 | head `dbfcd31ab890482fb1f008aa9e362486a0424e63` | `python3 -I tests/test_conformance_compare_crash.py -v`, `python3 -I tests/test_conformance_expect_status.py -v`, `python3 -I tests/test_conformance_png_transparency.py -v` | red: 9 tests, 13 assertion failures, 1 error | green: 9 passed | **Red → green** The baseline produced an incorrect exit status for a handler failure and for missing image input. PNG structure assertions also failed. Failure and error counts include subtest events. Pinned main `4938673668d807bf365b61284bf22b1ff8d02cc4`, merged into the PR head. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Full suite: not run. AI-assisted: OpenAI Codex. [Batch claim](https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7236982945).
zmasi commented 2026-11-29 02:24:57 +00:00

Windows 11 Verification (dbfcd31ab8 merged with origin/main 02944d4ca1)

  • Environment: Windows 11 (10.0.26200) NTFS, Python 3.12.10 & Python 3.14.5 (-I -B), clean non-commit merge onto origin/main (0 conflicts).
  • Red -> Green:
    • Red (unpatched origin/main tools/conformance/compare.py): python -I -B tests/test_conformance_expect_status.py failed (rc=1, FAILED (failures=2) — AssertionError: 1 != 2 on both state='missing' and state='corrupt' when paired with a differing pixel scene, confirming expect masked unreadable-image errors behind exit code 1). (Note: import traceback and PNG chunk ordering checks already landed on origin/main, so test_conformance_compare_crash.py 2/2 and test_conformance_png_transparency.py 6/6 add dedicated standalone regression coverage while command_expect + step_expect_missing_and_invalid + COMPARE.md close the remaining exit-status gap.)
    • Green (origin/main + #2205):
      • python -I -B tests/test_conformance_compare_crash.py: 2/2 OK on Python 3.12.10 (0.30s) & Python 3.14.5 (0.27s).
      • python -I -B tests/test_conformance_expect_status.py: 1/1 (4/4 subtests: matching -> 0, different -> 1, missing -> 2, corrupt -> 2) OK on Python 3.12.10 & Python 3.14.5.
      • python -I -B tests/test_conformance_png_transparency.py: 6/6 OK on Python 3.12.10 (0.11s) & Python 3.14.5 (0.07s).
      • python -I -B tools/conformance/compare.py selftest: 22/22 checks selftest passed (rc=0, 0.20s, including UTF-8 BOM manifest loading and missing-image EXIT_ERROR = 2).

AI-assisted.

### Windows 11 Verification (`dbfcd31ab8` merged with `origin/main` `02944d4ca1`) - **Environment**: Windows 11 (`10.0.26200`) NTFS, `Python 3.12.10` & `Python 3.14.5` (`-I -B`), clean non-commit merge onto `origin/main` (`0` conflicts). - **Red -> Green**: - **Red (unpatched `origin/main` `tools/conformance/compare.py`)**: `python -I -B tests/test_conformance_expect_status.py` failed (`rc=1`, `FAILED (failures=2)` — `AssertionError: 1 != 2` on both `state='missing'` and `state='corrupt'` when paired with a differing pixel scene, confirming `expect` masked unreadable-image errors behind exit code `1`). *(Note: `import traceback` and PNG chunk ordering checks already landed on `origin/main`, so `test_conformance_compare_crash.py` `2/2` and `test_conformance_png_transparency.py` `6/6` add dedicated standalone regression coverage while `command_expect` + `step_expect_missing_and_invalid` + `COMPARE.md` close the remaining exit-status gap.)* - **Green (`origin/main + #2205`)**: - `python -I -B tests/test_conformance_compare_crash.py`: **`2/2` `OK`** on `Python 3.12.10` (`0.30s`) & `Python 3.14.5` (`0.27s`). - `python -I -B tests/test_conformance_expect_status.py`: **`1/1` (`4/4` subtests: `matching` -> `0`, `different` -> `1`, `missing` -> `2`, `corrupt` -> `2`) `OK`** on `Python 3.12.10` & `Python 3.14.5`. - `python -I -B tests/test_conformance_png_transparency.py`: **`6/6` `OK`** on `Python 3.12.10` (`0.11s`) & `Python 3.14.5` (`0.07s`). - `python -I -B tools/conformance/compare.py selftest`: **`22/22` checks `selftest passed`** (`rc=0`, `0.20s`, including UTF-8 BOM manifest loading and missing-image `EXIT_ERROR = 2`). AI-assisted.
timbot103 reviewed 2026-11-29 04:28:38 +00:00
timbot103 left a comment
No description provided.
Static audit of head `dbfcd31ab` against the PR base and current main. No builds, tests, or GPU runs were performed. - `tools/conformance/compare.py:760` — On POSIX with a UTF-8 filesystem encoding, a manifest PNG name containing a lone surrogate from `\ud800` raises `UnicodeEncodeError` when opened. `expect` exits 2 before printing any scene rows, including those for readable images. Convert path encoding failures to a scene-local `ToolError` with an escaped filename and cover this case alongside a readable scene. - `tools/conformance/compare.py:1891` — The restored traceback prints absolute checkout paths to stderr if the script is invoked by absolute path and a handler raises unexpectedly. Default to repo-relative frames and a sanitized exception summary, with the raw traceback available on request. - `tools/conformance/compare.py:1722` — If an unbuffered `selftest` writes to a stdout pipe whose reader has closed, `BrokenPipeError` leaves its scratch directory behind. Include the first print and fixture work in cleanup that runs on unexpected exceptions and preserves deliberate fixture retention for reported failures. This gap also exists on main. The crash regression tests cover Python handler exceptions and verify exit 2. Native process termination is outside that catch, so Windows access violation `0xC0000005` and POSIX signal statuses observed as negative return codes by `subprocess` remain distinct from exit 1. The PNG tests cover the new chunk checks, and the existing selftest covers truncated chunks, bad CRCs, short scanlines, and unequal image sizes. Input reads use context managers. Existing image diagnostics deliberately identify the input path. AI-assisted.
MoonEyes commented 2026-11-29 14:19:14 +00:00

Merged at head 85149ce. Python tool and its tests only. The red linux-gpu-tools step (CPU runtime tests) was red on main at the time of the run, so not from this PR. Gap: only the author's test run is posted (new test fails before the fix, passes after); could someone run python -I tests/test_conformance_compare_crash.py on current main and post the result? AI-assisted: yes.

Merged at head 85149ce. Python tool and its tests only. The red linux-gpu-tools step (CPU runtime tests) was red on main at the time of the run, so not from this PR. Gap: only the author's test run is posted (new test fails before the fix, passes after); could someone run `python -I tests/test_conformance_compare_crash.py` on current main and post the result? AI-assisted: yes.
TheGeogeo commented 2026-11-29 14:46:32 +00:00

Correction: passes on 5 of 6 of the PR's tests; 1 skipped here (test_unencodable_png_name_is_scene_local_and_other_scenes_still_report needs POSIX and a UTF-8 filesystem encoding), not covered.

AI-assisted (Claude Code).


Earlier comment, superseded by the correction above:

Re-checked after the merge, on main bd643e46e (Windows 11 10.0.26300, Python 3.12.4, CPU only): passes on main.

  • python -I tests/test_conformance_compare_crash.py: 4 tests OK.
  • python -I tests/test_conformance_expect_status.py: 2 tests OK, 1 of them skipped.

AI-assisted (Claude Code).

**Correction:** passes on 5 of 6 of the PR's tests; 1 skipped here (`test_unencodable_png_name_is_scene_local_and_other_scenes_still_report` needs POSIX and a UTF-8 filesystem encoding), not covered. AI-assisted (Claude Code). --- *Earlier comment, superseded by the correction above:* Re-checked after the merge, on `main` `bd643e46e` (Windows 11 10.0.26300, Python 3.12.4, CPU only): passes on main. - `python -I tests/test_conformance_compare_crash.py`: 4 tests OK. - `python -I tests/test_conformance_expect_status.py`: 2 tests OK, 1 of them skipped. AI-assisted (Claude Code).
OreoFR commented 2026-11-29 17:24:37 +00:00

Post-merge check by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS, UTF-8 file system, Python 3.12.16 — covers the test skipped on Windows. Base before merge 9bb67cb53, merge d3418c61d (main 4364a4fa6), PR head 85149ce1a.

  • Red (pre-merge base + this PR's test files, identical on PR and main): 4/6, 0 skipped. Failing: test_handler_crash_returns_exit_error_with_traceback and test_unencodable_png_name_is_scene_local_and_other_scenes_still_report (output empty, no bad\ud800.png).
  • Green (main with the merge): 6/6, 0 skipped. The POSIX + UTF-8 test (skipped on Windows) runs here and passes.
  • (MEASURED n=3) both red failures 3/3.
  • Neighbours (9 files importing tools/conformance/compare.py): identical before/after, 40 passed, 23 skipped (all Windows-only: PowerShell / cmd.exe / conform_native).
  • timbot103's point (surrogate PNG name → UnicodeEncodeError on POSIX, compare.py:760) is fixed in the final head and covered by that test.

No issue found after merge.

AI-assisted: Claude Code

Post-merge check by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS, UTF-8 file system, Python 3.12.16 — covers the test skipped on Windows. Base before merge 9bb67cb53, merge d3418c61d (main 4364a4fa6), PR head 85149ce1a. - **Red** (pre-merge base + this PR's test files, identical on PR and main): 4/6, 0 skipped. Failing: `test_handler_crash_returns_exit_error_with_traceback` and `test_unencodable_png_name_is_scene_local_and_other_scenes_still_report` (output empty, no `bad\ud800.png`). - **Green** (main with the merge): 6/6, 0 skipped. The POSIX + UTF-8 test (skipped on Windows) runs here and passes. - (MEASURED n=3) both red failures 3/3. - Neighbours (9 files importing `tools/conformance/compare.py`): identical before/after, 40 passed, 23 skipped (all Windows-only: PowerShell / cmd.exe / `conform_native`). - timbot103's point (surrogate PNG name → `UnicodeEncodeError` on POSIX, `compare.py:760`) is fixed in the final head and covered by that test. No issue found after merge. AI-assisted: Claude Code
Sign in to join this conversation.
No description provided.