bvh_gpu_smoke: clean temporary work dirs, guard inputs, and publish --json atomically (BVH-GPU-SMOKE-WORK-CLEANUP-AND-JSON-SAFETY) #1765

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

@⁠kirigayakazima on GitHub · 2026-11-25 11:39 UTC · original
kirigayakazima:fix/bvh-gpu-smoke-work-cleanup-and-json-safety → main · +205 −32 · 2 files · 1 commits · open

Claimed in the coordination issue as: BVH-GPU-SMOKE-WORK-CLEANUP-AND-JSON-SAFETY #1608

What and why

Hardens tools/bvh_gpu_smoke.py:

  1. Clean up temporary --game-dir translation work folder: Allocate auto-created bvh_gpu_work_* folders via contextlib.ExitStack + tempfile.TemporaryDirectory so extracted/disassembled shaders from XboxBvhBuilder.dll are always removed when the run finishes or aborts (leaving explicit --work intact).
  2. Validate --max-shared-memory > 0: Reject zero or negative values upfront alongside --timeout / --heap-bytes.
  3. Validate --json against directories and input paths upfront: Refuse a directory path or a path aliasing --game-dir, XboxBvhBuilder.dll, --spirv, or any *.spv input via same_report_path before translating or invoking vk_compute_test.
  4. Atomic JSON reporting with Windows read-only cleanup: Replace direct Path(a.json).write_text(...) (which crashed with an unhandled PermissionError traceback or risked partial writes) with _write_json_atomic (staging in destination directory, published_mode, replace_retry, and restoring 0o600 before unlinking on failure), returning exit code 2 cleanly on OSError.

Adds 4 unit tests in tests/test_bvh_gpu_smoke.py (Cli).

Tested

Windows 11 x64 (10.0.26100), Python 3.14.7, CPU only with mocked vk_compute_test / translation (no game files). Commit 7122cf6d451382be00c5a78e55c1578a4ebdc140.

  • python -I tests/test_bvh_gpu_smoke.py -v:
    • against main (bcaa13da) with all 17 tests: 4 failures, 1 error (leaked temp work dir, unvalidated --max-shared-memory / --json inputs, unhandled PermissionError on read-only --json);
    • with the fix: 17 tests, OK (0 skipped).
  • python -I tests/test_ci_registration.py: 16 tests, OK.
  • python -I tests/test_text_write_line_endings.py: 3 tests, OK.
  • python -I scripts/check_no_game_data.py tools/bvh_gpu_smoke.py tests/test_bvh_gpu_smoke.py, python -m compileall -q tools tests, git diff --check: exit 0.

GPUs tested: n/a

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • 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)
**@⁠kirigayakazima** on GitHub · 2026-11-25 11:39 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1765) `kirigayakazima:fix/bvh-gpu-smoke-work-cleanup-and-json-safety` → `main` · +205 −32 · 2 files · 1 commits · open Claimed in the coordination issue as: BVH-GPU-SMOKE-WORK-CLEANUP-AND-JSON-SAFETY https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608 ### What and why Hardens `tools/bvh_gpu_smoke.py`: 1. **Clean up temporary `--game-dir` translation work folder**: Allocate auto-created `bvh_gpu_work_*` folders via `contextlib.ExitStack` + `tempfile.TemporaryDirectory` so extracted/disassembled shaders from `XboxBvhBuilder.dll` are always removed when the run finishes or aborts (leaving explicit `--work` intact). 2. **Validate `--max-shared-memory` > 0**: Reject zero or negative values upfront alongside `--timeout` / `--heap-bytes`. 3. **Validate `--json` against directories and input paths upfront**: Refuse a directory path or a path aliasing `--game-dir`, `XboxBvhBuilder.dll`, `--spirv`, or any `*.spv` input via `same_report_path` before translating or invoking `vk_compute_test`. 4. **Atomic JSON reporting with Windows read-only cleanup**: Replace direct `Path(a.json).write_text(...)` (which crashed with an unhandled `PermissionError` traceback or risked partial writes) with `_write_json_atomic` (staging in destination directory, `published_mode`, `replace_retry`, and restoring `0o600` before unlinking on failure), returning exit code `2` cleanly on `OSError`. Adds 4 unit tests in `tests/test_bvh_gpu_smoke.py` (`Cli`). ### Tested Windows 11 x64 (`10.0.26100`), Python `3.14.7`, CPU only with mocked `vk_compute_test` / translation (no game files). Commit `7122cf6d451382be00c5a78e55c1578a4ebdc140`. - `python -I tests/test_bvh_gpu_smoke.py -v`: - against `main` (`bcaa13da`) with all 17 tests: **4 failures, 1 error** (leaked temp work dir, unvalidated `--max-shared-memory` / `--json` inputs, unhandled `PermissionError` on read-only `--json`); - with the fix: **17 tests, OK** (0 skipped). - `python -I tests/test_ci_registration.py`: **16 tests, OK**. - `python -I tests/test_text_write_line_endings.py`: **3 tests, OK**. - `python -I scripts/check_no_game_data.py tools/bvh_gpu_smoke.py tests/test_bvh_gpu_smoke.py`, `python -m compileall -q tools tests`, `git diff --check`: exit `0`. GPUs tested: n/a AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] 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)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:04:09 +00:00
Author
Owner

@⁠PierreEbele on GitHub · 2026-11-25 18:36 UTC · original

Reviewed 7122cf6: bvh_gpu_smoke now cleans its temporary work dir on success and on error, rejects --max-shared-memory <= 0, refuses a --json that names a directory or an input (game dir, DLL, --spirv or a .spv inside it), and publishes the report through a staging file with mode preservation and cleanup on failure (missing parent folders created; a write failure gives rc 2 with the previous report intact). Ran the test file: 17/17 OK on the PR, 13/13 on main, and with the PR's test file copied onto main exactly the four new tests fail, so they pin the fix. A mock-driven probe on both trees confirms each differential: main leaks bvh_gpu_work_ in $TMPDIR, overwrites an input .spv with the report while exiting 0, dies with IsADirectoryError/PermissionError/FileNotFoundError tracebacks on a directory, read-only report or missing folder, and forwards --max-shared-memory 0 to the translator - all fixed on the PR, which also keeps the old mode bits on replace and leaves no staging leftovers. Windows-only paths were not run. No finding. One suggestion: also guard --build/vk_compute_test (a --json naming it still clobbers the binary, as on main).

AI-assisted review.

Recommendation: Merge

**@⁠PierreEbele** on GitHub · 2026-11-25 18:36 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1765#issuecomment-7171144910) Reviewed 7122cf6: bvh_gpu_smoke now cleans its temporary work dir on success and on error, rejects `--max-shared-memory <= 0`, refuses a `--json` that names a directory or an input (game dir, DLL, --spirv or a *.spv inside it), and publishes the report through a staging file with mode preservation and cleanup on failure (missing parent folders created; a write failure gives rc 2 with the previous report intact). Ran the test file: 17/17 OK on the PR, 13/13 on main, and with the PR's test file copied onto main exactly the four new tests fail, so they pin the fix. A mock-driven probe on both trees confirms each differential: main leaks bvh_gpu_work_* in $TMPDIR, overwrites an input .spv with the report while exiting 0, dies with IsADirectoryError/PermissionError/FileNotFoundError tracebacks on a directory, read-only report or missing folder, and forwards --max-shared-memory 0 to the translator - all fixed on the PR, which also keeps the old mode bits on replace and leaves no staging leftovers. Windows-only paths were not run. No finding. One suggestion: also guard `--build`/vk_compute_test (a --json naming it still clobbers the binary, as on main). AI-assisted review. **Recommendation:** Merge
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/1765/head:github-bot/gh-1765'
git switch 'github-bot/gh-1765'

Merge

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