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

Merged
IlyassRS3 merged 1 commit from upstream-pr/1550 into main 2026-11-28 10:45:54 +00:00
IlyassRS3 commented 2026-11-25 04:11:18 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by IlyassRS3 on 2026-11-25T04:11:18Z.


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)

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5485025594 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1550). Originally posted by [IlyassRS3](https://github.com/IlyassRS3) on 2026-11-25T04:11:18Z. --- ## 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)
copilot-pull-request-reviewer[bot] commented 2026-11-25 04:11:34 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T04:11:34Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6051748808 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1550#pullrequestreview-6051748808). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-25T04:11:34Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
MoonEyes commented 2026-11-28 10:45:50 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T10:45:50Z.


Red/green: the PR's tests fail on main and pass with this PR (Linux, Python 3.13.18).
Targeted batch of 19 PRs (their tests, the tests importing the changed modules, the docs tests) on main 3ca0707: no new failure, Linux / Python 3.13.
AI-assisted (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238106141 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1550#issuecomment-7238106141). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T10:45:50Z. --- Red/green: the PR's tests fail on main and pass with this PR (Linux, Python 3.13.18). Targeted batch of 19 PRs (their tests, the tests importing the changed modules, the docs tests) on main 3ca0707: no new failure, Linux / Python 3.13. AI-assisted (Claude Code, Claude Opus 5.5)
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!1550
No description provided.