tools/int_hw_probe: write --json atomically and reject trailing-separator paths #1852
No reviewers
No assignees
Labels
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
No project
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
No due date set.
Reference
leonida/mandy!1852
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/int-hw-probe-safety"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Pull request successfully merged and closed
Claimed in the coordination issue as: INT-HW-PROBE-ATOMIC-JSON-AND-PATH-SAFETY (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7163274170)
What and why
os.sep/os.altsep) intools/int_hw_probe.py's_validate_json_out()beforeos.path.abspath()strips them, so directory-like--jsonpaths fail upfront with exit2.--jsonoutput atomically in_write_json_atomic()(tempfile.mkstempbesideos.path.realpath(path), explicitnewline="\n", trailing\n,os.fsync,published_mode, andreplace_retry.replace), preserving any existing file and cleaning up staging files on write/replace failure.tests/test_int_hw_probe.py.Tested
python -I tests/test_int_hw_probe.py -v->Ran 13 tests in 2.008s,OK.upstream/main(98c2f777) baseline worktree with updatedtests/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, andgit diff --check-> exit0.GPUs tested: n/a (CPU/stdlib Python tests on Windows 11 x64)
AI-assisted: yes
Checklist
needs rebase).Tested
71c86830fon Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), againstmain71a769d7d(Python GPU probe; hardware oracle not run):tests/test_int_hw_probe.py: 13 passed, 12 subtests passed at this head.main: 4 failed, 11 passed, 10 subtests — the trailing-separator--jsonguard and the atomic write path are new.AI-assisted; synthetic fixtures only, no game data.
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:(AI-assisted test run; output checked by hand.)
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.
Merged. Thank you, @kirigayakazima.
--jsonis written atomically, and paths with a trailing separator are rejected.mainand pass here; the docs, line-ending and CI/ctest registration checks pass, and so does the game-data check.main082ebe440+71c86830f: the semantic suite passes (490 files, 6,292 tests, 0 files failed);test_int_hw_probepass; the 15 docs and writer tests pass;check_no_game_data.pyis clean on the 2 changed files.AI-assisted (Claude Code, Claude Opus 5.5).