tools: make script_qtable.py --json writes atomic and validate paths and hex stems #1815

Merged
kirigayakazima merged 1 commit from upstream-pr/1815 into main 2026-11-25 17:34:28 +00:00
kirigayakazima commented 2026-11-25 12:27:27 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-11-25T12:27:27Z.


Claimed in the coordination issue as: SCRIPT-QTABLE-ATOMIC-JSON-AND-EMPTY-PATH-GUARD (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7162357891)

What and why

  • Write tools/script_qtable.py --json reports atomically via _write_json_atomic() (tempfile.mkstemp beside os.path.realpath(path), explicit newline="\n", trailing \n, os.fsync, published_mode, and replace_retry), preserving any existing file and cleaning up staging files on write/replace failures.
  • Check if a.json is not None: instead of truthiness and reject empty, whitespace-only, or trailing-separator --json paths in check_report_path() with UsageError (exit 2).
  • Restrict hex-offset stem parsing in _BinFolderSource to unsigned hexadecimal stems so negative-prefixed .bin names are not mapped to negative offsets.
  • Add regression tests in tests/test_script_qtable.py.

Tested

  • python -I tests/test_script_qtable.py -v -> Ran 14 tests in 0.730s, OK (verified in a detached upstream/main worktree that all new regressions fail before the fix: FAILED (failures=3)).
  • python -I tests/test_ci_registration.py -> Ran 16 tests in 4.796s, OK.
  • python -I tests/test_text_write_line_endings.py -> Ran 3 tests in 13.173s, OK.
  • python -I scripts/check_no_game_data.py tools/script_qtable.py tests/test_script_qtable.py -> exit 0.
  • python -I -m compileall -q tools/script_qtable.py tests/test_script_qtable.py and git diff --check -> clean.

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)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5491309775 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1815). Originally posted by [kirigayakazima](https://github.com/kirigayakazima) on 2026-11-25T12:27:27Z. --- Claimed in the coordination issue as: SCRIPT-QTABLE-ATOMIC-JSON-AND-EMPTY-PATH-GUARD (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7162357891) ### What and why - Write `tools/script_qtable.py` `--json` reports atomically via `_write_json_atomic()` (`tempfile.mkstemp` beside `os.path.realpath(path)`, explicit `newline="\n"`, trailing `\n`, `os.fsync`, `published_mode`, and `replace_retry`), preserving any existing file and cleaning up staging files on write/replace failures. - Check `if a.json is not None:` instead of truthiness and reject empty, whitespace-only, or trailing-separator `--json` paths in `check_report_path()` with `UsageError` (exit `2`). - Restrict hex-offset stem parsing in `_BinFolderSource` to unsigned hexadecimal stems so negative-prefixed `.bin` names are not mapped to negative offsets. - Add regression tests in `tests/test_script_qtable.py`. ### Tested - `python -I tests/test_script_qtable.py -v` -> `Ran 14 tests in 0.730s`, `OK` (verified in a detached `upstream/main` worktree that all new regressions fail before the fix: `FAILED (failures=3)`). - `python -I tests/test_ci_registration.py` -> `Ran 16 tests in 4.796s`, `OK`. - `python -I tests/test_text_write_line_endings.py` -> `Ran 3 tests in 13.173s`, `OK`. - `python -I scripts/check_no_game_data.py tools/script_qtable.py tests/test_script_qtable.py` -> exit `0`. - `python -I -m compileall -q tools/script_qtable.py tests/test_script_qtable.py` and `git diff --check` -> clean. 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)
madvillain91 commented 2026-11-25 13:14:35 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by madvillain91 on 2026-11-25T13:14:35Z.

Review: COMMENTED


Independent Windows 11 26H2 (26300.9711) check at 59eadb0be against main 98c2f7777 (PR base 0d80bc5df), using CPython 3.12.3 (python -I) and Git for Windows 2.56.0.windows.2. Passed test_script_qtable.py (13 passed, 1 symlink test skipped on WinError 1314 without SeCreateSymbolicLinkPrivilege, 0.966s), test_ci_registration.py (16/16, 6.801s), and test_text_write_line_endings.py (3/3, 14.502s), with check_no_game_data.py and compileall clean. Verified atomic --json write via replace_retry with trailing LF and cleanup on failure, empty/whitespace/trailing-separator path rejection (including Windows backslash), and strict hex-digit stem parsing rejecting negative stems like -10.bin. LGTM.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6058273532 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1815#pullrequestreview-6058273532). Originally posted by [madvillain91](https://github.com/madvillain91) on 2026-11-25T13:14:35Z. **Review:** COMMENTED --- Independent Windows 11 26H2 (26300.9711) check at 59eadb0be against main 98c2f7777 (PR base 0d80bc5df), using CPython 3.12.3 (python -I) and Git for Windows 2.56.0.windows.2. Passed test_script_qtable.py (13 passed, 1 symlink test skipped on WinError 1314 without SeCreateSymbolicLinkPrivilege, 0.966s), test_ci_registration.py (16/16, 6.801s), and test_text_write_line_endings.py (3/3, 14.502s), with check_no_game_data.py and compileall clean. Verified atomic --json write via replace_retry with trailing LF and cleanup on failure, empty/whitespace/trailing-separator path rejection (including Windows backslash), and strict hex-digit stem parsing rejecting negative stems like -10.bin. LGTM.
DeadlyChirp commented 2026-11-25 15:48:40 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by DeadlyChirp on 2026-11-25T15:48:40Z.


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

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

  • PR: 13 passed, 1 skipped. main: 10 passed. The skip is the symlink case: [WinError 1314] A required privilege is not held by the client (no symlink privilege on this machine). The other new tests pass.

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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7167333834 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1815#issuecomment-7167333834). Originally posted by [DeadlyChirp](https://github.com/DeadlyChirp) on 2026-11-25T15:48:40Z. --- Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main. `python -m pytest -q tests/test_script_qtable.py`: - PR: 13 passed, 1 skipped. main: 10 passed. The skip is the symlink case: `[WinError 1314] A required privilege is not held by the client` (no symlink privilege on this machine). The other new tests pass. (AI-assisted test run; output checked by hand.)
aslan2142 commented 2026-11-25 17:34:31 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-11-25T17:34:31Z.


Merged. Thank you, @kirigayakazima. --json writes are atomic, and an empty path is refused.

  • 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 1f62a9c36 + 59eadb0be: the semantic suite passes (490 files, 6,292 tests, 0 files failed); test_script_qtable 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).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7169698936 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1815#issuecomment-7169698936). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-11-25T17:34:31Z. --- Merged. Thank you, @kirigayakazima. `--json` writes are atomic, and an empty path is refused. - 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` `1f62a9c36` + `59eadb0be`:** the semantic suite passes (490 files, 6,292 tests, 0 files failed); `test_script_qtable` 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).
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!1815
No description provided.