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

Merged
leonida/mandy
quietfold merged 1 commit from fix/gamedata-graph-counts-and-cli into main 2026-11-28 10:45:54 +00:00

Pull request successfully merged and closed

quietfold commented 2026-11-25 04:11:18 +00:00

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)

## 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] reviewed 2026-11-25 04:11:34 +00:00
copilot-pull-request-reviewer[bot] left a comment
No description provided.
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

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)

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 description provided.