[PR #1550] gamedata_graph: fix manifest/root summary invariants and --json path guards (GAMEDATA-GRAPH-COUNTS-AND-CLI-GUARDS) #1575

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1550
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/gamedata-graph-counts-and-cli


📝 Commits (1)

  • d4dcde4 gamedata_graph: fix manifest/root summary invariants and --json path guards

📊 Changes

2 files changed (+64 additions, -9 deletions)

View changed files

📝 tests/test_gamedata_graph.py (+51 -0)
📝 tools/gamedata_graph.py (+13 -9)

📄 Description

What

Fix four summary-accounting and CLI path-guard bugs in tools/gamedata_graph.py:

  1. Unparsed manifest payloads inflated per-category/per-root manifest_documents (build_graph):
    • Top-level summary["manifest_documents"] counts only parsed manifest documents (report["parsed"] and report["root"] in MANIFEST_ROOT_SET), whereas category_stats and root_stats omitted report["parsed"]. Require report["parsed"] in both so per-category and per-root totals match summary["manifest_documents"].
  2. Rootless payloads ("") counted as a named root in categories["uncatalogued"]["roots"] (build_graph):
    • summary["root_count"] excludes "" (empty/rootless payloads are counted under summary["rootless"]), yet the category root count included "", making sum(c["roots"]) exceed summary["root_count"] by 1 whenever any rootless payload exists. Skip empty root names when counting named roots per category.
  3. Well-formed parsed documents could be marked complete=False (scan_document):
    • Once ET.fromstring(data) succeeds, mark report["complete"] = True (matching gamedata_xml.py:file_row) instead of keeping doc.get("complete", True), so summary["parsed"] can never exceed summary["documents"].
  4. Empty/whitespace --json and directory-mode .bin guard (main):
    • Check args.json is not None and reject empty/whitespace --json values with parser.error(...) instead of silently ignoring --json "" or writing a whitespace filename.
    • Gate the carve-stream .bin/.bk2 overwrite guard on is_carve (directory containing index.json) using realpath and case-insensitive suffix matching, so directory mode does not reject unrelated .bin outputs while carve mode protects both .bin and .bk2 streams.

Claimed in the coordination issue as

GAMEDATA-GRAPH-COUNTS-AND-CLI-GUARDS — verified 0 open PRs and 0 prior claims; unable to post a comment on #14 because GitHub disabled commenting once #14 reached its 2,500-comment cap (and no successor "Coordinating who works on what" issue is open yet).

Testing

  • python3 -I -W error tests/test_gamedata_graph.py -v: 24/24 OK (including 3 new regression tests).

  • python3 -I -W error tests/test_gamedata_graph_bad_index.py -v: 5/5 OK.

  • python3 -I tests/test_text_write_line_endings.py: 3/3 OK.

  • python3 -I scripts/check_no_game_data.py tools/gamedata_graph.py tests/test_gamedata_graph.py: clean.

  • python3 -m compileall -q tools/gamedata_graph.py tests/test_gamedata_graph.py: clean.

  • Mutation check against unpatched main:tools/gamedata_graph.py: all 3 new tests (4 assertions/subtests) fail on main (FAILED (failures=4)).

  • AI-assisted: yes

  • GPUs tested: none (CPU-only XML graph tool tests on macOS; no GPU or game files needed)


🔄 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/1550 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/gamedata-graph-counts-and-cli` --- ### 📝 Commits (1) - [`d4dcde4`](https://github.com/ubiquitarianism/leonida/commit/d4dcde4cc105142bede17caed71cd360a641c1e9) gamedata_graph: fix manifest/root summary invariants and --json path guards ### 📊 Changes **2 files changed** (+64 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_gamedata_graph.py` (+51 -0) 📝 `tools/gamedata_graph.py` (+13 -9) </details> ### 📄 Description ## What Fix four summary-accounting and CLI path-guard bugs in `tools/gamedata_graph.py`: 1. **Unparsed manifest payloads inflated per-category/per-root `manifest_documents`** (`build_graph`): - Top-level `summary["manifest_documents"]` counts only parsed manifest documents (`report["parsed"] and report["root"] in MANIFEST_ROOT_SET`), whereas `category_stats` and `root_stats` omitted `report["parsed"]`. Require `report["parsed"]` in both so per-category and per-root totals match `summary["manifest_documents"]`. 2. **Rootless payloads (`""`) counted as a named root in `categories["uncatalogued"]["roots"]`** (`build_graph`): - `summary["root_count"]` excludes `""` (empty/rootless payloads are counted under `summary["rootless"]`), yet the category root count included `""`, making `sum(c["roots"])` exceed `summary["root_count"]` by 1 whenever any rootless payload exists. Skip empty root names when counting named roots per category. 3. **Well-formed parsed documents could be marked `complete=False`** (`scan_document`): - Once `ET.fromstring(data)` succeeds, mark `report["complete"] = True` (matching `gamedata_xml.py:file_row`) instead of keeping `doc.get("complete", True)`, so `summary["parsed"]` can never exceed `summary["documents"]`. 4. **Empty/whitespace `--json` and directory-mode `.bin` guard** (`main`): - Check `args.json is not None` and reject empty/whitespace `--json` values with `parser.error(...)` instead of silently ignoring `--json ""` or writing a whitespace filename. - Gate the carve-stream `.bin`/`.bk2` overwrite guard on `is_carve` (directory containing `index.json`) using `realpath` and case-insensitive suffix matching, so directory mode does not reject unrelated `.bin` outputs while carve mode protects both `.bin` and `.bk2` streams. ## Claimed in the coordination issue as `GAMEDATA-GRAPH-COUNTS-AND-CLI-GUARDS` — verified 0 open PRs and 0 prior claims; unable to post a comment on `#14` because GitHub disabled commenting once `#14` reached its 2,500-comment cap (and no successor `"Coordinating who works on what"` issue is open yet). ## Testing - `python3 -I -W error tests/test_gamedata_graph.py -v`: **24/24 OK** (including 3 new regression tests). - `python3 -I -W error tests/test_gamedata_graph_bad_index.py -v`: **5/5 OK**. - `python3 -I tests/test_text_write_line_endings.py`: **3/3 OK**. - `python3 -I scripts/check_no_game_data.py tools/gamedata_graph.py tests/test_gamedata_graph.py`: clean. - `python3 -m compileall -q tools/gamedata_graph.py tests/test_gamedata_graph.py`: clean. - Mutation check against unpatched `main:tools/gamedata_graph.py`: all 3 new tests (4 assertions/subtests) fail on `main` (`FAILED (failures=4)`). - AI-assisted: yes - GPUs tested: none (CPU-only XML graph tool tests on macOS; no GPU or game files needed) --- <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#1575
No description provided.