[PR #2258] gamedata_blobs: fix unshipped count, index type checks, and atomic JSON #2263

Open
opened 2026-11-26 21:20:36 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2258
Author: @kirigayakazima
Created: 11/26/2026
Status: 🔄 Open

Base: main ← Head: fix/gamedata-blobs-safety


📝 Commits (1)

  • d1545df gamedata_blobs: fix unshipped count, index type checks, and atomic JSON

📊 Changes

2 files changed (+196 additions, -13 deletions)

View changed files

📝 tests/test_gamedata_blobs.py (+143 -0)
📝 tools/gamedata_blobs.py (+53 -13)

📄 Description

Claimed in the coordination issue as: GAMEDATA-BLOBS-UNSHIPPED-OVERLAP-INDEX-TYPES-AND-ATOMIC-JSON (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7189816855)

What and why

  • Fix unshipped overlap double-subtraction in cross_reference_sgd5() (tools/gamedata_blobs.py) so preload-list entries present in both db0 and db1 are counted accurately via sum(1 for s in stems if s not in db0_set and s not in db1_set) instead of p["entries"] - len(in_db0) - len(in_db1).
  • Tighten check_carve_index() to convert UnicodeDecodeError and RecursionError from json.load() into single-line ValueError diagnostics and require type(row.get("off")) is int and type(row.get("stored")) is int (non-bool, >= 0).
  • Avoid double-parsing index.json across main() and read_payloads(..., _checked_index=is_dir), reject trailing / or \ --json directory paths in check_report_path() and non-file --shaders upfront before read_payloads(), and catch RecursionError cleanly in main().
  • Write --json output atomically via _write_json_atomic() (staging next to os.path.realpath(out_path), trailing LF \n, os.fsync(), preserving permissions with published_mode(), publishing via replace_retry.replace(), and unlinking .blobs-*.tmp files on failure).
  • Add GamedataBlobsSafetyTests to tests/test_gamedata_blobs.py (without overlapping #1269's lines) covering overlap unshipped, bool/negative/str index types, RecursionError, single index.json parse, early CLI validation, and atomic JSON write/failure rollback.

Tested

  • Patched: python -I tests/test_gamedata_blobs.py -v -> Ran 14 tests in 1.178s (OK).
  • Baseline check (upstream/main a73a57e1 with updated tests/test_gamedata_blobs.py copied into detached worktree): Ran 14 tests in 1.119s (FAILED (failures=10)).
  • Repo gates: python -I tests/test_ci_registration.py (Ran 16 tests in 5.560s, OK), python -I tests/test_text_write_line_endings.py (Ran 3 tests in 13.499s, OK), python -I scripts/check_no_game_data.py (exit 0), python -I -m compileall -q tools/gamedata_blobs.py tests/test_gamedata_blobs.py (exit 0), git diff --check (exit 0).

GPUs tested: n/a (synthetic carve/RPF/SGD5 fixtures and atomic JSON output tests)

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.

🔄 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/2258 **Author:** [@kirigayakazima](https://github.com/kirigayakazima) **Created:** 11/26/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/gamedata-blobs-safety` --- ### 📝 Commits (1) - [`d1545df`](https://github.com/ubiquitarianism/leonida/commit/d1545dfdefee1dc2c213cf47a69d7143591d083a) gamedata_blobs: fix unshipped count, index type checks, and atomic JSON ### 📊 Changes **2 files changed** (+196 additions, -13 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_gamedata_blobs.py` (+143 -0) 📝 `tools/gamedata_blobs.py` (+53 -13) </details> ### 📄 Description Claimed in the coordination issue as: GAMEDATA-BLOBS-UNSHIPPED-OVERLAP-INDEX-TYPES-AND-ATOMIC-JSON (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7189816855) ### What and why - Fix `unshipped` overlap double-subtraction in `cross_reference_sgd5()` (`tools/gamedata_blobs.py`) so preload-list entries present in both `db0` and `db1` are counted accurately via `sum(1 for s in stems if s not in db0_set and s not in db1_set)` instead of `p["entries"] - len(in_db0) - len(in_db1)`. - Tighten `check_carve_index()` to convert `UnicodeDecodeError` and `RecursionError` from `json.load()` into single-line `ValueError` diagnostics and require `type(row.get("off")) is int` and `type(row.get("stored")) is int` (non-`bool`, `>= 0`). - Avoid double-parsing `index.json` across `main()` and `read_payloads(..., _checked_index=is_dir)`, reject trailing `/` or `\` `--json` directory paths in `check_report_path()` and non-file `--shaders` upfront before `read_payloads()`, and catch `RecursionError` cleanly in `main()`. - Write `--json` output atomically via `_write_json_atomic()` (staging next to `os.path.realpath(out_path)`, trailing LF `\n`, `os.fsync()`, preserving permissions with `published_mode()`, publishing via `replace_retry.replace()`, and unlinking `.blobs-*.tmp` files on failure). - Add `GamedataBlobsSafetyTests` to `tests/test_gamedata_blobs.py` (without overlapping `#1269`'s lines) covering overlap `unshipped`, `bool`/negative/`str` index types, `RecursionError`, single `index.json` parse, early CLI validation, and atomic JSON write/failure rollback. ### Tested - Patched: `python -I tests/test_gamedata_blobs.py -v` -> `Ran 14 tests in 1.178s` (`OK`). - Baseline check (`upstream/main` `a73a57e1` with updated `tests/test_gamedata_blobs.py` copied into detached worktree): `Ran 14 tests in 1.119s` (`FAILED (failures=10)`). - Repo gates: `python -I tests/test_ci_registration.py` (`Ran 16 tests in 5.560s`, `OK`), `python -I tests/test_text_write_line_endings.py` (`Ran 3 tests in 13.499s`, `OK`), `python -I scripts/check_no_game_data.py` (exit 0), `python -I -m compileall -q tools/gamedata_blobs.py tests/test_gamedata_blobs.py` (exit 0), `git diff --check` (exit 0). GPUs tested: n/a (synthetic carve/RPF/SGD5 fixtures and atomic JSON output tests) 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#2263
No description provided.