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

Open
opened 2026-11-26 21:18:55 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1765
Author: @kirigayakazima
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/bvh-gpu-smoke-work-cleanup-and-json-safety


📝 Commits (1)

  • 7122cf6 bvh_gpu_smoke: clean temporary work dirs, guard --max-shared-memory/--json inputs, and write JSON atomically

📊 Changes

2 files changed (+205 additions, -32 deletions)

View changed files

📝 tests/test_bvh_gpu_smoke.py (+110 -0)
📝 tools/bvh_gpu_smoke.py (+95 -32)

📄 Description

Claimed in the coordination issue as: BVH-GPU-SMOKE-WORK-CLEANUP-AND-JSON-SAFETY https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7161287514

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)

🔄 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/1765 **Author:** [@kirigayakazima](https://github.com/kirigayakazima) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/bvh-gpu-smoke-work-cleanup-and-json-safety` --- ### 📝 Commits (1) - [`7122cf6`](https://github.com/ubiquitarianism/leonida/commit/7122cf6d451382be00c5a78e55c1578a4ebdc140) bvh_gpu_smoke: clean temporary work dirs, guard --max-shared-memory/--json inputs, and write JSON atomically ### 📊 Changes **2 files changed** (+205 additions, -32 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_bvh_gpu_smoke.py` (+110 -0) 📝 `tools/bvh_gpu_smoke.py` (+95 -32) </details> ### 📄 Description Claimed in the coordination issue as: BVH-GPU-SMOKE-WORK-CLEANUP-AND-JSON-SAFETY https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7161287514 ### 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) --- <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#1777
No description provided.