Skip to content

bvh_tri_probe: an unusable --write-kernels path is one error line and exit 2 - #6364

Open
josevictorp wants to merge 2 commits into
ItsNotRexed:mainfrom
josevictorp:josevictorp/leonida-bvh-tri-probe-write-kernels
Open

josevictorp wants to merge 2 commits into
ItsNotRexed:mainfrom
josevictorp:josevictorp/leonida-bvh-tri-probe-write-kernels

Conversation

@josevictorp

Copy link
Copy Markdown
Contributor

New BUILD item, claimed in #5934 (comment).

What was wrong. On main 561b65a8, write_kernels() in tools/bvh_tri_probe.py calls os.makedirs and two open() with no guard. --write-kernels pointing at an existing plain file ends in a FileExistsError traceback, and a path under a plain file in a NotADirectoryError traceback, both exit 1. The tool documents exit 2 for a CLI or harness error, and its --json writer already answers with one error line and exit 2.

What changed. The call in main() catches OSError and prints error: cannot write --write-kernels <dir>: <reason> on stderr, returning 2: the wording the --json handler uses.

Tested on Linux 6.8, Python 3.12.3, CPU only (no GPU, no driver, no game files):

  • python -I tests/test_bvh_tri_probe.py: OK, with the new CommandLine case (two subcases: an existing file, a folder under one; exit 2, one error line, no traceback).
  • Negative control: with tools/bvh_tri_probe.py from 561b65a8 the same file ends in FAILED (errors=2).
  • python -m compileall -q tools tests is clean.

AI-assisted: written by Qwen, checked by Claude Code.

… exit 2

os.makedirs(out_dir, exist_ok=True) and the two open() calls in
write_kernels() were not guarded, so --write-kernels pointing at an
existing plain file died in a FileExistsError traceback (a path under
one, in a NotADirectoryError) with exit 1, while the tool documents
"2 a CLI or harness error" and its --json writer already answers with
one error line and exit 2. The call in main() now catches OSError and
prints "error: cannot write --write-kernels <dir>: <reason>" on stderr,
the same wording its --json handler uses.

Tested: a new CommandLine case in tests/test_bvh_tri_probe.py (two
subCases: an existing file, a folder under one; each expects exit 2,
one error line, no traceback); it errors without the guard and the
file's 16 tests pass with it. tests/semantic (1010 tests) and
python -m compileall over tools and tests are green.

AI-assisted: written by Qwen (model qwen3.8-gx10-claude-compatible).
@Jadiac5

Jadiac5 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 4ed3246 on Windows 11, AMD Radeon RX 9070 XT (RDNA4), driver 32.0.32029.2010: pass

  • python -I tests/test_bvh_tri_probe.py: 16 tests OK. With tools/bvh_tri_probe.py from the merge base (561b65a): the new test errors in both subtests (existing file, path under a file), 15 others pass.
  • CLI --write-kernels --kernel tri_g4b, each exit 2 with one error: cannot write --write-kernels ... line and no traceback: an existing file; a path under a file; bad<name; bad|x; a 300-character name; Z:\nodrive\x (no such drive); nul; a name ending in ". ". A new folder with a space in its name -> exit 0, 32 cases written.
  • Not done: read-only folder (no way to make one without changing ACLs).

AI-assisted (Claude Code).

ItsNotRexed#6708 added two --json tests at the same spot in tests/test_bvh_tri_probe.py. Both blocks stay; 18 tests pass.
@josevictorp

Copy link
Copy Markdown
Contributor Author

Merged main (09a92ed) into the branch at dd0ba9f6: #6708 added two --json tests at the same spot in tests/test_bvh_tri_probe.py, so the branch conflicted. Both blocks are kept, tools/bvh_tri_probe.py merged cleanly.

  • python -I tests/test_bvh_tri_probe.py: 18 tests OK (Linux 6.8, Python 3.12.3, CPU only).
  • compileall and git diff --check clean.

AI-assisted.

@YordiLorenzo

Copy link
Copy Markdown

Tested dd0ba9f on Linux, Python 3.14.4: pass

python3 -I tests/test_bvh_tri_probe.py: 18 of 18 pass
same tests with main's bvh_tri_probe.py: both new subtests error (the old traceback), so they catch it
#9036 edits the same file; the two merge without a conflict

@Loggerten

Copy link
Copy Markdown

Tested dd0baaf68ae07b119c1d72623b0a828d6e4ac369 on Linux x86-64, Python 3.14.9 (no GPU; code read + unit tests only): pass.

  • Applied the diff onto main 867d922.
  • python -I tests/test_bvh_tri_probe.py: 18 tests OK with the change.
  • Reverted only tools/bvh_tri_probe.py (test kept): the new test fails with 2 errors — traceback + exit 1 — so it covers the bug.
  • python -m compileall -q make_game.py tools tests: clean.

Code read: matches the --json error path — one error: line on stderr, the path as typed, OSError only, exit 2. os.makedirs/NotADirectoryError (an OSError subclass) covers the path-under-a-file case. Review is AI-assisted (Hermes agent).

@shadshuvo shadshuvo left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code read (CPU) ?

Review

This PR correctly validates --write-kernels path before use, providing clean error messages.

Code Quality

? Early validation: Checks path is usable before proceeding
? Clean errors: One error line and exit 2 instead of traceback
? Test coverage: New test verifies both plain-file and missing-parent cases
? All 18 bvh_tri_probe tests pass (677 subtests)

Testing

npython -m pytest tests/test_bvh_tri_probe.py -xvs 18 passed, 677 subtests passed in 1.62s n
Ready to merge.


Reviewed on Windows 11, Python 3.14.2 (AI-assisted)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants