[PR #1815] [MERGED] tools: make script_qtable.py --json writes atomic and validate paths and hex stems #1826

Closed
opened 2026-11-26 21:19:06 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1815
Author: @kirigayakazima
Created: 11/25/2026
Status: ✅ Merged
Merged: 11/25/2026
Merged by: @aslan2142

Base: main ← Head: fix/script-qtable-atomic-json


📝 Commits (1)

  • 59eadb0 tools: make script_qtable.py --json writes atomic and validate paths and hex stems

📊 Changes

2 files changed (+129 additions, -10 deletions)

View changed files

📝 tests/test_script_qtable.py (+85 -0)
📝 tools/script_qtable.py (+44 -10)

📄 Description

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)

🔄 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/1815 **Author:** [@kirigayakazima](https://github.com/kirigayakazima) **Created:** 11/25/2026 **Status:** ✅ Merged **Merged:** 11/25/2026 **Merged by:** [@aslan2142](https://github.com/aslan2142) **Base:** `main` ← **Head:** `fix/script-qtable-atomic-json` --- ### 📝 Commits (1) - [`59eadb0`](https://github.com/ubiquitarianism/leonida/commit/59eadb0be5ec32363711a447f305a35f36b0da34) tools: make script_qtable.py --json writes atomic and validate paths and hex stems ### 📊 Changes **2 files changed** (+129 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_script_qtable.py` (+85 -0) 📝 `tools/script_qtable.py` (+44 -10) </details> ### 📄 Description 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) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 21:19:06 +01:00
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#1826
No description provided.