tools/int_hw_probe: write --json atomically and reject trailing-separator paths #1852

Manually merged
github merged 1 commit from gh-pr/1852/head into gh-pr/1852/base 2026-11-26 10:08:38 +00:00
Owner

@⁠kirigayakazima on GitHub · 2026-11-25 13:08 UTC · original
kirigayakazima:fix/int-hw-probe-safety → main · +86 −7 · 2 files · 1 commits · merged 2026-11-25 17:32 UTC

Claimed in the coordination issue as: INT-HW-PROBE-ATOMIC-JSON-AND-PATH-SAFETY (#1608)

What and why

  • Reject trailing path separators (os.sep / os.altsep) in tools/int_hw_probe.py's _validate_json_out() before os.path.abspath() strips them, so directory-like --json paths fail upfront with exit 2.
  • Write --json output atomically in _write_json_atomic() (tempfile.mkstemp beside os.path.realpath(path), explicit newline="\n", trailing \n, os.fsync, published_mode, and replace_retry.replace), preserving any existing file and cleaning up staging files on write/replace failure.
  • Add regression tests in tests/test_int_hw_probe.py.

Tested

  • python -I tests/test_int_hw_probe.py -v -> Ran 13 tests in 2.008s, OK.
  • Detached upstream/main (98c2f777) baseline worktree with updated tests/test_int_hw_probe.py -> Ran 13 tests in 2.450s, FAILED (failures=3, errors=1).
  • python -I tests/test_ci_registration.py -> Ran 16 tests in 6.463s, OK.
  • python -I tests/test_text_write_line_endings.py -> Ran 3 tests in 14.893s, OK.
  • python -I scripts/check_no_game_data.py tools/int_hw_probe.py tests/test_int_hw_probe.py, python -I -m compileall -q tools/int_hw_probe.py tests/test_int_hw_probe.py, and git diff --check -> exit 0.

GPUs tested: n/a (CPU/stdlib Python tests on Windows 11 x64)

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)
**@⁠kirigayakazima** on GitHub · 2026-11-25 13:08 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1852) `kirigayakazima:fix/int-hw-probe-safety` → `main` · +86 −7 · 2 files · 1 commits · merged 2026-11-25 17:32 UTC Claimed in the coordination issue as: INT-HW-PROBE-ATOMIC-JSON-AND-PATH-SAFETY (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### What and why - Reject trailing path separators (`os.sep` / `os.altsep`) in `tools/int_hw_probe.py`'s `_validate_json_out()` before `os.path.abspath()` strips them, so directory-like `--json` paths fail upfront with exit `2`. - Write `--json` output atomically in `_write_json_atomic()` (`tempfile.mkstemp` beside `os.path.realpath(path)`, explicit `newline="\n"`, trailing `\n`, `os.fsync`, `published_mode`, and `replace_retry.replace`), preserving any existing file and cleaning up staging files on write/replace failure. - Add regression tests in `tests/test_int_hw_probe.py`. ### Tested - `python -I tests/test_int_hw_probe.py -v` -> `Ran 13 tests in 2.008s`, `OK`. - Detached `upstream/main` (`98c2f777`) baseline worktree with updated `tests/test_int_hw_probe.py` -> `Ran 13 tests in 2.450s`, `FAILED (failures=3, errors=1)`. - `python -I tests/test_ci_registration.py` -> `Ran 16 tests in 6.463s`, `OK`. - `python -I tests/test_text_write_line_endings.py` -> `Ran 3 tests in 14.893s`, `OK`. - `python -I scripts/check_no_game_data.py tools/int_hw_probe.py tests/test_int_hw_probe.py`, `python -I -m compileall -q tools/int_hw_probe.py tests/test_int_hw_probe.py`, and `git diff --check` -> exit `0`. GPUs tested: n/a (CPU/stdlib Python tests on Windows 11 x64) 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)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:08:37 +00:00
github manually merged commit 71c86830f5 into gh-pr/1852/base 2026-11-26 10:08:38 +00:00
Author
Owner

@⁠madvillain91 on GitHub · 2026-11-25 13:31 UTC · original · reviewed

Independent Windows 11 26H2 (26300.9711) check at 71c86830f against main 384abe5b0 (PR base 98c2f7777), using CPython 3.12.3 (python -I) and Git for Windows 2.56.0.windows.2. Passed test_int_hw_probe.py (13/13 in 3.705s) and test_text_write_line_endings.py (3/3 in 17.509s), with check_no_game_data.py and compileall clean. Verified trailing-separator --json rejection (both os.sep and os.altsep on Windows) before running translator/oracle cases, and atomic --json writes via replace_retry with trailing LF, existing-file preservation, and staging cleanup on failure. LGTM.

**@⁠madvillain91** on GitHub · 2026-11-25 13:31 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1852#pullrequestreview-6058523607) · **reviewed** Independent Windows 11 26H2 (26300.9711) check at 71c86830f against main 384abe5b0 (PR base 98c2f7777), using CPython 3.12.3 (python -I) and Git for Windows 2.56.0.windows.2. Passed test_int_hw_probe.py (13/13 in 3.705s) and test_text_write_line_endings.py (3/3 in 17.509s), with check_no_game_data.py and compileall clean. Verified trailing-separator --json rejection (both os.sep and os.altsep on Windows) before running translator/oracle cases, and atomic --json writes via replace_retry with trailing LF, existing-file preservation, and staging cleanup on failure. LGTM.
Author
Owner

@⁠GeorgiyDemo on GitHub · 2026-11-25 14:11 UTC · original

Tested 71c86830f on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against main 71a769d7d (Python GPU probe; hardware oracle not run):

  • pytest 9.2.0 on tests/test_int_hw_probe.py: 13 passed, 12 subtests passed at this head.
  • The same file on main: 4 failed, 11 passed, 10 subtests — the trailing-separator --json guard and the atomic write path are new.
  • Not run: the hardware oracle on a real AMD GPU; the tests mock the probe.

AI-assisted; synthetic fixtures only, no game data.

**@⁠GeorgiyDemo** on GitHub · 2026-11-25 14:11 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1852#issuecomment-7164903660) Tested `71c86830f` on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against `main` `71a769d7d` (Python GPU probe; hardware oracle not run): - pytest 9.2.0 on `tests/test_int_hw_probe.py`: **13 passed, 12 subtests passed** at this head. - The same file on `main`: **4 failed**, 11 passed, 10 subtests — the trailing-separator `--json` guard and the atomic write path are new. - Not run: the hardware oracle on a real AMD GPU; the tests mock the probe. AI-assisted; synthetic fixtures only, no game data.
Author
Owner

@⁠DeadlyChirp on GitHub · 2026-11-25 15:37 UTC · original

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

python -m pytest -q tests/test_int_hw_probe.py:

  • PR: 13 passed. main: 10 passed. The new tests pass on Windows.

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

**@⁠DeadlyChirp** on GitHub · 2026-11-25 15:37 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1852#issuecomment-7167134314) Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main. `python -m pytest -q tests/test_int_hw_probe.py`: - PR: 13 passed. main: 10 passed. The new tests pass on Windows. (AI-assisted test run; output checked by hand.)
Author
Owner

@⁠MSedgeMC on GitHub · 2026-11-25 17:19 UTC · original · approved these changes

Verified on the PR branch: python3 -m unittest tests.test_int_hw_probe -v -> 13 tests OK, including the new tests for trailing-separator paths, preserving an existing JSON file on write failure, and staging cleanup with replace_retry. The fix writes atomically via a staging file and os.replace, which is the right pattern for a tool that otherwise truncates a good report on disk-full. Python-only, no game data.

**@⁠MSedgeMC** on GitHub · 2026-11-25 17:19 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1852#pullrequestreview-6061946140) · **approved these changes** Verified on the PR branch: python3 -m unittest tests.test_int_hw_probe -v -> 13 tests OK, including the new tests for trailing-separator paths, preserving an existing JSON file on write failure, and staging cleanup with replace_retry. The fix writes atomically via a staging file and os.replace, which is the right pattern for a tool that otherwise truncates a good report on disk-full. Python-only, no game data.
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-25 17:32 UTC · original

Merged. Thank you, @⁠kirigayakazima. --json is written atomically, and paths with a trailing separator are rejected.

  • The new tests fail on main and pass here; the docs, line-ending and CI/ctest registration checks pass, and so does the game-data check.
  • Checked on main 082ebe440 + 71c86830f: the semantic suite passes (490 files, 6,292 tests, 0 files failed); test_int_hw_probe pass; the 15 docs and writer tests pass; check_no_game_data.py is clean on the 2 changed files.

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠aslan2142** on GitHub · 2026-11-25 17:32 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1852#issuecomment-7169657653) Merged. Thank you, @⁠kirigayakazima. `--json` is written atomically, and paths with a trailing separator are rejected. - The new tests fail on `main` and pass here; the docs, line-ending and CI/ctest registration checks pass, and so does the game-data check. - **Checked on `main` `082ebe440` + `71c86830f`:** the semantic suite passes (490 files, 6,292 tests, 0 files failed); `test_int_hw_probe` pass; the 15 docs and writer tests pass; `check_no_game_data.py` is clean on the 2 changed files. AI-assisted (Claude Code, Claude Opus 5.5).
This discussion has been locked. Commenting is limited to contributors.
No description provided.