tools: make gamedata_sps1.py --json writes atomic, validate paths and avoid duplicate index read #1817

Manually merged
github merged 1 commit from gh-pr/1817/head into gh-pr/1817/base 2026-11-26 10:06:56 +00:00
Owner

@⁠kirigayakazima on GitHub · 2026-11-25 12:29 UTC · original
kirigayakazima:fix/gamedata-sps1-atomic-json → main · +176 −6 · 2 files · 1 commits · merged 2026-11-25 17:33 UTC

Claimed in the coordination issue as: GAMEDATA-SPS1-ATOMIC-JSON-AND-PATH-SAFETY (#1608)

What and why

  • Write tools/gamedata_sps1.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 failure.
  • Reject empty, whitespace-only, or trailing-separator --json paths upfront via ap.error(...) (exit 2).
  • Accept optional rows in read_payloads(target, rows=None) so directory CLI runs reuse the already-parsed index.json rows instead of reading and parsing index.json twice.
  • Add isolated tests in tests/test_gamedata_sps1_atomic.py (leaving tests/test_gamedata_sps1.py untouched).

Tested

  • python -I tests/test_gamedata_sps1.py -v -> Ran 7 tests in 0.884s, OK.
  • python -I tests/test_gamedata_sps1_atomic.py -v -> Ran 5 tests in 0.048s, OK (verified in a detached upstream/main worktree that the new regression suite fails before the fix: FAILED (failures=7)).
  • python -I tests/test_ci_registration.py -> Ran 16 tests in 4.722s, OK.
  • python -I tests/test_text_write_line_endings.py -> Ran 3 tests in 12.631s, OK.
  • python -I scripts/check_no_game_data.py tools/gamedata_sps1.py tests/test_gamedata_sps1_atomic.py -> exit 0.
  • python -I -m compileall -q tools/gamedata_sps1.py tests/test_gamedata_sps1_atomic.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)
**@⁠kirigayakazima** on GitHub · 2026-11-25 12:29 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1817) `kirigayakazima:fix/gamedata-sps1-atomic-json` → `main` · +176 −6 · 2 files · 1 commits · merged 2026-11-25 17:33 UTC Claimed in the coordination issue as: GAMEDATA-SPS1-ATOMIC-JSON-AND-PATH-SAFETY (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### What and why - Write `tools/gamedata_sps1.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 failure. - Reject empty, whitespace-only, or trailing-separator `--json` paths upfront via `ap.error(...)` (exit `2`). - Accept optional `rows` in `read_payloads(target, rows=None)` so directory CLI runs reuse the already-parsed `index.json` rows instead of reading and parsing `index.json` twice. - Add isolated tests in `tests/test_gamedata_sps1_atomic.py` (leaving `tests/test_gamedata_sps1.py` untouched). ### Tested - `python -I tests/test_gamedata_sps1.py -v` -> `Ran 7 tests in 0.884s`, `OK`. - `python -I tests/test_gamedata_sps1_atomic.py -v` -> `Ran 5 tests in 0.048s`, `OK` (verified in a detached `upstream/main` worktree that the new regression suite fails before the fix: `FAILED (failures=7)`). - `python -I tests/test_ci_registration.py` -> `Ran 16 tests in 4.722s`, `OK`. - `python -I tests/test_text_write_line_endings.py` -> `Ran 3 tests in 12.631s`, `OK`. - `python -I scripts/check_no_game_data.py tools/gamedata_sps1.py tests/test_gamedata_sps1_atomic.py` -> exit `0`. - `python -I -m compileall -q tools/gamedata_sps1.py tests/test_gamedata_sps1_atomic.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)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:06:54 +00:00
github manually merged commit def89c3aa5 into gh-pr/1817/base 2026-11-26 10:06:56 +00:00
Author
Owner

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

Independent Windows 11 26H2 (26300.9711) check at def89c3aa against main 98c2f7777 (PR base 0d80bc5df), using CPython 3.12.3 (python -I) and Git for Windows 2.56.0.windows.2. Passed test_gamedata_sps1.py (7/7, 1.454s), test_gamedata_sps1_atomic.py (4 passed, 1 symlink test skipped on WinError 1314 without SeCreateSymbolicLinkPrivilege, 0.061s), test_ci_registration.py (16/16, 7.547s), and test_text_write_line_endings.py (3/3, 13.605s), with check_no_game_data.py and compileall clean. Verified single index.json read when targeting a directory, atomic --json write via replace_retry with LF trailing newline and staging cleanup on failure, and empty/whitespace/trailing-separator --json path validation. LGTM.

**@⁠madvillain91** on GitHub · 2026-11-25 13:14 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1817#pullrequestreview-6058273835) · **reviewed** Independent Windows 11 26H2 (26300.9711) check at def89c3aa against main 98c2f7777 (PR base 0d80bc5df), using CPython 3.12.3 (python -I) and Git for Windows 2.56.0.windows.2. Passed test_gamedata_sps1.py (7/7, 1.454s), test_gamedata_sps1_atomic.py (4 passed, 1 symlink test skipped on WinError 1314 without SeCreateSymbolicLinkPrivilege, 0.061s), test_ci_registration.py (16/16, 7.547s), and test_text_write_line_endings.py (3/3, 13.605s), with check_no_game_data.py and compileall clean. Verified single index.json read when targeting a directory, atomic --json write via replace_retry with LF trailing newline and staging cleanup on failure, and empty/whitespace/trailing-separator --json path validation. LGTM.
Author
Owner

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

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

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

  • PR: 4 passed, 1 skipped. The skip is the symlink case: [WinError 1314] A required privilege is not held by the client (no symlink privilege on this machine).
  • The new test file run against main's tool: 7 failed, 2 passed. So the tests catch the problem, and the change fixes it on Windows.

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

**@⁠DeadlyChirp** on GitHub · 2026-11-25 15:51 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1817#issuecomment-7167377619) Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main. `python -m pytest -q tests/test_gamedata_sps1_atomic.py`: - PR: 4 passed, 1 skipped. The skip is the symlink case: `[WinError 1314] A required privilege is not held by the client` (no symlink privilege on this machine). - The new test file run against main's tool: 7 failed, 2 passed. So the tests catch the problem, and the change fixes it on Windows. (AI-assisted test run; output checked by hand.)
Author
Owner

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

Merged. Thank you, @⁠kirigayakazima. --json writes are atomic, and paths are validated.

  • 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 a8266e3f8 + def89c3aa: the semantic suite passes (490 files, 6,292 tests, 0 files failed); test_gamedata_sps1_atomic 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:33 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1817#issuecomment-7169679589) Merged. Thank you, @⁠kirigayakazima. `--json` writes are atomic, and paths are validated. - 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` `a8266e3f8` + `def89c3aa`:** the semantic suite passes (490 files, 6,292 tests, 0 files failed); `test_gamedata_sps1_atomic` 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.