tools/gamedata_sps1.py: check --json ancestors and input file kinds upfront #2291

Merged
leonida/mandy
kirigayakazima merged 1 commit from fix/gamedata-sps1-safety into main 2026-11-28 10:46:56 +00:00

Pull request successfully merged and closed

kirigayakazima commented 2026-11-26 12:51:19 +00:00

Claimed in the coordination issue as: GAMEDATA-SPS1-UPFRONT-JSON-ANCESTOR-AND-SHADERS-FILE-GUARD (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7192516333)

What and why

  • Walk existing ancestors of both os.path.abspath(out_path) and os.path.realpath(out_path) inside check_report_path() (tools/gamedata_sps1.py) so --json paths blocked by a regular-file or broken-symlink ancestor (or symlink-to-directory target) fail upfront before reading inputs while keeping the exit code 1 "error:" contract.
  • Validate upfront in main() that target is an existing regular file or directory and --shaders (when provided) is an existing regular file, returning exit code 2 with an ERROR: message before reading payloads.
  • Add unit tests in tests/test_gamedata_sps1_atomic.py.

Tested

  • python -I tests/test_gamedata_sps1_atomic.py -v: 7 passed, 0 failed (detached upstream/main baseline with only the updated test file fails with 3 failures).
  • python -I tests/test_gamedata_sps1.py -v: 7 passed, 0 failed.
  • python -I tests/test_ci_registration.py: 16 passed.
  • python -I tests/test_text_write_line_endings.py: 3 passed.
  • python -I scripts/check_no_game_data.py, python -I -m compileall -q tools/gamedata_sps1.py tests/test_gamedata_sps1_atomic.py, and git diff --cached --check: passed.

GPUs tested: n/a

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.
Claimed in the coordination issue as: GAMEDATA-SPS1-UPFRONT-JSON-ANCESTOR-AND-SHADERS-FILE-GUARD (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7192516333) ### What and why - Walk existing ancestors of both `os.path.abspath(out_path)` and `os.path.realpath(out_path)` inside `check_report_path()` (`tools/gamedata_sps1.py`) so `--json` paths blocked by a regular-file or broken-symlink ancestor (or symlink-to-directory target) fail upfront before reading inputs while keeping the exit code `1` `"error:"` contract. - Validate upfront in `main()` that `target` is an existing regular file or directory and `--shaders` (when provided) is an existing regular file, returning exit code `2` with an `ERROR:` message before reading payloads. - Add unit tests in `tests/test_gamedata_sps1_atomic.py`. ### Tested - `python -I tests/test_gamedata_sps1_atomic.py -v`: 7 passed, 0 failed (detached `upstream/main` baseline with only the updated test file fails with 3 failures). - `python -I tests/test_gamedata_sps1.py -v`: 7 passed, 0 failed. - `python -I tests/test_ci_registration.py`: 16 passed. - `python -I tests/test_text_write_line_endings.py`: 3 passed. - `python -I scripts/check_no_game_data.py`, `python -I -m compileall -q tools/gamedata_sps1.py tests/test_gamedata_sps1_atomic.py`, and `git diff --cached --check`: passed. GPUs tested: n/a 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.
tiguan26 approved these changes 2026-11-27 04:40:44 +00:00
tiguan26 left a comment

Approving 4f930f0df.

--json is refused when the path or its resolved destination is a directory or an ancestor is not one, and --target/--shaders of the wrong kind are usage errors (exit 2) as a missing one already was.

Merged onto main d1dff7949 in one batch with 15 other tool PRs of this series (no conflicts), on Linux with Python 3.13. tests/test_gamedata_sps1_atomic.py: 7 passed (main: 5). AI-assisted (Claude Code, Claude Opus 5.5).

Approving 4f930f0df. `--json` is refused when the path or its resolved destination is a directory or an ancestor is not one, and `--target`/`--shaders` of the wrong kind are usage errors (exit 2) as a missing one already was. Merged onto `main` `d1dff7949` in one batch with 15 other tool PRs of this series (no conflicts), on Linux with Python 3.13. `tests/test_gamedata_sps1_atomic.py`: 7 passed (main: 5). AI-assisted (Claude Code, Claude Opus 5.5).
MSedgeMC reviewed 2026-11-27 15:28:13 +00:00
MSedgeMC left a comment
No description provided.
Verified on the PR branch: both relevant test modules pass — test_gamedata_sps1.py 7 tests OK and test_gamedata_sps1_atomic.py 7 tests OK (the latter covers symlinked --json updates in place). Not approving yet: the branch is 446 commits behind current main, so a rebase is needed before the final diff can be reviewed.
sodove commented 2026-11-28 10:12:33 +00:00

#2291 | head 4f930f0dfa455f74b605275e31618c932ec0047d | python3 -I tests/test_gamedata_sps1_atomic.py -v | red: 7 run, 3 failures | green: 7 passed | Red → green

The baseline tried to read the input or proceed with output paths that the new assertions expect to reject upfront.

Pinned main 33db04a7010e81c40a7a6a15624525aa0c4a3a58, merged into this PR head. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Full suite: not run. AI-assisted: OpenAI Codex. Batch claim.

#2291 | head `4f930f0dfa455f74b605275e31618c932ec0047d` | `python3 -I tests/test_gamedata_sps1_atomic.py -v` | red: 7 run, 3 failures | green: 7 passed | **Red → green** The baseline tried to read the input or proceed with output paths that the new assertions expect to reject upfront. Pinned main `33db04a7010e81c40a7a6a15624525aa0c4a3a58`, merged into this PR head. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Full suite: not run. AI-assisted: OpenAI Codex. [Batch claim](https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7237628300).
DadaCap commented 2026-11-28 10:46:58 +00:00

Merged, thank you @kirigayakazima!

What it does: tools/gamedata_sps1.py: check --json ancestors and input file kinds upfront

How it was checked: sodove tested this PR at head 4f930f0df on main 33db04a70: the PR's own test fails on main and passes with this PR merged in (his result is linked from the batch summary in #1608). We then re-ran the same test locally on Windows 11 and got the same verdict: on main, red (3 failures); with the PR, green (7 OK, 1 skip).

CI: the red jobs on this PR fail the same way on main, or on the older main it was built on (the cs_dpp_cmp.asm translator fixture, since fixed on main, and the Windows runner's Visual Studio setup), so none comes from this change.

Merged one by one with 20 other PRs of the same reviewed batch, pinned to the tested head.

AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.

Merged, thank you @kirigayakazima! **What it does:** tools/gamedata_sps1.py: check --json ancestors and input file kinds upfront **How it was checked:** sodove tested this PR at head `4f930f0df` on main `33db04a70`: the PR's own test fails on main and passes with this PR merged in (his result is linked from the batch summary in #1608). We then re-ran the same test locally on Windows 11 and got the same verdict: on main, red (3 failures); with the PR, green (7 OK, 1 skip). **CI:** the red jobs on this PR fail the same way on main, or on the older main it was built on (the `cs_dpp_cmp.asm` translator fixture, since fixed on main, and the Windows runner's Visual Studio setup), so none comes from this change. Merged one by one with 20 other PRs of the same reviewed batch, pinned to the tested head. AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.
Sign in to join this conversation.
No description provided.