pe: add main(argv) and JSON/schema/IO error guards in dependency_paths with CLI suite #2428

Merged
Ammmae0x merged 2 commits from upstream-pr/2436 into main 2026-11-25 20:06:15 +00:00
Ammmae0x commented 2026-11-25 16:41:32 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-25T16:41:32Z.


Change

Add a testable main(argv=None) -> int entrypoint, upfront directory and JSON schema validation, and structured error handling to tools/dependency_paths.py, together with a standalone pure-Python CLI test suite registered in CMakeLists.txt (pe_dependency_paths_cli_check).

  • tools/dependency_paths.py:
    • Accept argv: list[str] | None = None in main, forward argv to parser.parse_args(argv), return 0 on success, and invoke raise SystemExit(main()) under __main__.
    • Reject directory inventory paths (args.inventory.is_dir()), validate that the inventory JSON root is an object with a mapping images and list imports, and check args.entry is not None and args.entry not in images via parser.error(...) (handling empty-string "" entry cleanly).
    • Guard (OSError, UnicodeDecodeError, ValueError, KeyError, TypeError) via parser.exit(1, f"{args.inventory}: {exc}\n") with zero raw tracebacks while preserving exact JSON stdout (including narrow cp1252 stdout encoding).
  • tests/dependency_paths_cli_check.py: standalone unittest suite using synthetic inventory JSON covering single-entry and all-entry JSON schema (inventory_sha256 + entries), non-ASCII survival on cp1252 stdout, main(None) / __main__ forwarding, and negative/mutation controls (missing/directory inventory, invalid UTF-8, invalid JSON, non-object root, missing/invalid images or imports, KeyError/TypeError during trace, and missing/empty entry exit 2).
  • CMakeLists.txt: register pe_dependency_paths_cli_check immediately after dependency_paths_controls (tests/dependency_paths_check.py left untouched).

Verification

Verified on commit 38990c71 (based on upstream/main b442b57f) using out/pe-env/Scripts/python.exe -B:

  • out/pe-env/Scripts/python.exe -B tests/dependency_paths_cli_check.py -v -> Ran 6 tests in 1.789s, OK (exit 0).
  • out/pe-env/Scripts/python.exe -B tests/dependency_paths_check.py -> dependency_paths: the pinned hash reaches the conditional target; a different hash reports unverified_loader_hash and no conditional edge (exit 0).
  • out/pe-env/Scripts/python.exe -B tests/intake/paths_check.py -> exit 0.
  • out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py -> form coverage checks passed (exit 0).
  • out/pe-env/Scripts/python.exe -B tests/docs_links_check.py -> Self-test passed. Checked 19 Markdown files and 465 links. (exit 0).
  • out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py -> Self-test passed. Checked 1726 tracked source, script and build/CI files: no bidirectional controls. (exit 0).
  • Spot mutation audit on tools/dependency_paths.py: 8/8 mutations killed (argv forwarding, is_dir(), root dict check, images dict check, imports list check, args.entry is not None, KeyError/TypeError guard, integer 0 return).

Evidence and follow-up

All fixtures in tests/dependency_paths_cli_check.py are synthetic minimal inventory dictionaries generated in-memory under the repository MIT license; no external binaries or game files are used. Contributors can run the suite directly via out/pe-env/Scripts/python.exe -B tests/dependency_paths_cli_check.py or through CTest (pe_dependency_paths_cli_check).

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6609166668 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2436). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-25T16:41:32Z. --- ## Change Add a testable `main(argv=None) -> int` entrypoint, upfront directory and JSON schema validation, and structured error handling to `tools/dependency_paths.py`, together with a standalone pure-Python CLI test suite registered in `CMakeLists.txt` (`pe_dependency_paths_cli_check`). - `tools/dependency_paths.py`: - Accept `argv: list[str] | None = None` in `main`, forward `argv` to `parser.parse_args(argv)`, return `0` on success, and invoke `raise SystemExit(main())` under `__main__`. - Reject directory inventory paths (`args.inventory.is_dir()`), validate that the inventory JSON root is an object with a mapping `images` and list `imports`, and check `args.entry is not None and args.entry not in images` via `parser.error(...)` (handling empty-string `""` entry cleanly). - Guard `(OSError, UnicodeDecodeError, ValueError, KeyError, TypeError)` via `parser.exit(1, f"{args.inventory}: {exc}\n")` with zero raw tracebacks while preserving exact JSON stdout (including narrow `cp1252` stdout encoding). - `tests/dependency_paths_cli_check.py`: standalone unittest suite using synthetic inventory JSON covering single-entry and all-entry JSON schema (`inventory_sha256` + `entries`), non-ASCII survival on `cp1252` stdout, `main(None)` / `__main__` forwarding, and negative/mutation controls (missing/directory inventory, invalid UTF-8, invalid JSON, non-object root, missing/invalid `images` or `imports`, `KeyError`/`TypeError` during `trace`, and missing/empty `entry` exit 2). - `CMakeLists.txt`: register `pe_dependency_paths_cli_check` immediately after `dependency_paths_controls` (`tests/dependency_paths_check.py` left untouched). ## Verification Verified on commit `38990c71` (based on `upstream/main` `b442b57f`) using `out/pe-env/Scripts/python.exe -B`: - `out/pe-env/Scripts/python.exe -B tests/dependency_paths_cli_check.py -v` -> `Ran 6 tests in 1.789s`, `OK` (exit 0). - `out/pe-env/Scripts/python.exe -B tests/dependency_paths_check.py` -> `dependency_paths: the pinned hash reaches the conditional target; a different hash reports unverified_loader_hash and no conditional edge` (exit 0). - `out/pe-env/Scripts/python.exe -B tests/intake/paths_check.py` -> exit 0. - `out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py` -> `form coverage checks passed` (exit 0). - `out/pe-env/Scripts/python.exe -B tests/docs_links_check.py` -> `Self-test passed. Checked 19 Markdown files and 465 links.` (exit 0). - `out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py` -> `Self-test passed. Checked 1726 tracked source, script and build/CI files: no bidirectional controls.` (exit 0). - Spot mutation audit on `tools/dependency_paths.py`: 8/8 mutations killed (`argv` forwarding, `is_dir()`, root `dict` check, `images` `dict` check, `imports` `list` check, `args.entry is not None`, `KeyError`/`TypeError` guard, integer `0` return). ## Evidence and follow-up All fixtures in `tests/dependency_paths_cli_check.py` are synthetic minimal inventory dictionaries generated in-memory under the repository MIT license; no external binaries or game files are used. Contributors can run the suite directly via `out/pe-env/Scripts/python.exe -B tests/dependency_paths_cli_check.py` or through CTest (`pe_dependency_paths_cli_check`). ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted.
tedin7 commented 2026-11-25 19:03:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T18:24:27Z.

Review: COMMENTED


Review of head 38990c71 (diff against origin/main, 3 files).

What I checked

  • Scope is small. main(argv=None) -> int with raise SystemExit(main()), input checks, and one new CTest entry next to dependency_paths_controls. The existing tests/dependency_paths_check.py is untouched.
  • Behavior looks right. parser.error raises SystemExit, so the new except tuple does not swallow the usage error (exit 2). I/O, JSON and schema problems exit 1 with one line and no traceback. The entry is not None check makes an empty-string entry a usage error instead of "all entries".
  • No duplicate. #635 (ASCII JSON) and #212 (loader hash) are merged and touch other behavior in this tool. No open PR covers the CLI entrypoint.
  • The PR body cites Windows runs on 38990c71. I did not run them.

Commands run locally (worktree at the PR head)

  • python3 -B tests/dependency_paths_cli_check.py: 6 tests, OK
  • python3 -B tests/dependency_paths_check.py: pass
  • python3 tests/docs_links_check.py: pass
  • python3 tests/bidi_controls_check.py: pass
  • git diff --check origin/main...HEAD: clean
  • Mutation 1: parser.exit(1, ...) changed to parser.exit(0, ...): the suite fails (9 failures).
  • Mutation 2: args.entry is not None changed to a truthiness test: the suite fails (1 failure).
  • Both mutations reverted.

Non-blocking note: the except tuple includes KeyError and TypeError. A real bug inside trace would be reported as an inventory error with exit 1, not a traceback. The suite pins this on purpose, so I am only flagging it.

No blocking findings. No Windows run on my side. This comment is not an approval.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6062835498 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2436#pullrequestreview-6062835498). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T18:24:27Z. **Review:** COMMENTED --- Review of head 38990c71 (diff against origin/main, 3 files). What I checked - Scope is small. `main(argv=None) -> int` with `raise SystemExit(main())`, input checks, and one new CTest entry next to `dependency_paths_controls`. The existing `tests/dependency_paths_check.py` is untouched. - Behavior looks right. `parser.error` raises SystemExit, so the new `except` tuple does not swallow the usage error (exit 2). I/O, JSON and schema problems exit 1 with one line and no traceback. The `entry is not None` check makes an empty-string entry a usage error instead of "all entries". - No duplicate. #635 (ASCII JSON) and #212 (loader hash) are merged and touch other behavior in this tool. No open PR covers the CLI entrypoint. - The PR body cites Windows runs on 38990c71. I did not run them. Commands run locally (worktree at the PR head) - `python3 -B tests/dependency_paths_cli_check.py`: 6 tests, OK - `python3 -B tests/dependency_paths_check.py`: pass - `python3 tests/docs_links_check.py`: pass - `python3 tests/bidi_controls_check.py`: pass - `git diff --check origin/main...HEAD`: clean - Mutation 1: `parser.exit(1, ...)` changed to `parser.exit(0, ...)`: the suite fails (9 failures). - Mutation 2: `args.entry is not None` changed to a truthiness test: the suite fails (1 failure). - Both mutations reverted. Non-blocking note: the `except` tuple includes `KeyError` and `TypeError`. A real bug inside `trace` would be reported as an inventory error with exit 1, not a traceback. The suite pins this on purpose, so I am only flagging it. No blocking findings. No Windows run on my side. This comment is not an approval. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-25 20:04:12 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T20:02:26Z.

Review: COMMENTED


Review of head 30d83e29 (tooling only: tools/dependency_paths.py, new CLI suite, CTest registration). No blocking findings.

What I checked:

  • main(argv) returns an int and the script exits through SystemExit(main()). parser.error for an unknown entry still exits 2, and I/O, decode, JSON and schema failures exit 1 with a one-line message.
  • Behavior on valid inventories is unchanged (same JSON document and hash).
  • pe_dependency_paths_cli_check is registered next to its siblings in CMakeLists.txt.
  • The new tests guard the behavior. Mutation 1: replacing the images object check with if False: makes 2 of 6 tests fail. Mutation 2: changing the error exit code from 1 to 0 makes the suite fail (9 failures).
  • No other open or merged PR covers this slice (searched dependency_paths; #635 and #212 touched other behavior).

Commands run locally on the exact head:

  • python3 tests/dependency_paths_cli_check.py -> 6 tests OK
  • python3 tests/docs_links_check.py -> OK
  • python3 tests/bidi_controls_check.py -> OK
  • git diff --check origin/main...HEAD -> clean
  • the two mutations above, reverted with git checkout -- .

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6064157734 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2436#pullrequestreview-6064157734). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T20:02:26Z. **Review:** COMMENTED --- Review of head 30d83e29 (tooling only: `tools/dependency_paths.py`, new CLI suite, CTest registration). No blocking findings. What I checked: - `main(argv)` returns an int and the script exits through `SystemExit(main())`. `parser.error` for an unknown entry still exits 2, and I/O, decode, JSON and schema failures exit 1 with a one-line message. - Behavior on valid inventories is unchanged (same JSON document and hash). - `pe_dependency_paths_cli_check` is registered next to its siblings in `CMakeLists.txt`. - The new tests guard the behavior. Mutation 1: replacing the `images` object check with `if False:` makes 2 of 6 tests fail. Mutation 2: changing the error exit code from 1 to 0 makes the suite fail (9 failures). - No other open or merged PR covers this slice (searched `dependency_paths`; #635 and #212 touched other behavior). Commands run locally on the exact head: - `python3 tests/dependency_paths_cli_check.py` -> 6 tests OK - `python3 tests/docs_links_check.py` -> OK - `python3 tests/bidi_controls_check.py` -> OK - `git diff --check origin/main...HEAD` -> clean - the two mutations above, reverted with `git checkout -- .` AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-25 21:00:56 +00:00
tedin7 commented 2026-11-25 21:01:28 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T20:06:08Z.


Win2025 WARP receipt for head 30d83e29 after updating with main.

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit 30d83e29a55624ac19f834be4355910b89e96e55:

  • Debug (--preset dev):
    • Build (cmake --build --preset dev -- -j 2): 2.96s (configure 2.58s)
    • Test (ctest --preset dev -R 'dependency_paths' --parallel 4 --no-tests=error --output-on-failure): 2/2 passed (2.61s: dependency_paths_controls 0.23s, pe_dependency_paths_cli_check 2.46s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release -- -j 2): 3.51s (configure 2.55s)
    • Test (ctest --preset release -R 'dependency_paths' --parallel 4 --no-tests=error --output-on-failure): 2/2 passed (2.31s: dependency_paths_controls 0.23s, pe_dependency_paths_cli_check 2.16s)
  • Windows Python checks: tests/dependency_paths_check.py ok (0.2s), tests/intake/paths_check.py ok (0.2s)
  • sccache: 25/40 hits; wall 22.3s

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7173192560 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2436#issuecomment-7173192560). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T20:06:08Z. --- Win2025 WARP receipt for head 30d83e29 after updating with main. Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `30d83e29a55624ac19f834be4355910b89e96e55`: - **Debug (`--preset dev`)**: - Build (`cmake --build --preset dev -- -j 2`): `2.96s` (configure `2.58s`) - Test (`ctest --preset dev -R 'dependency_paths' --parallel 4 --no-tests=error --output-on-failure`): **2/2 passed** (`2.61s`: `dependency_paths_controls` `0.23s`, `pe_dependency_paths_cli_check` `2.46s`) - **Release `/O2` (`--preset release`)**: - Build (`cmake --build --preset release -- -j 2`): `3.51s` (configure `2.55s`) - Test (`ctest --preset release -R 'dependency_paths' --parallel 4 --no-tests=error --output-on-failure`): **2/2 passed** (`2.31s`: `dependency_paths_controls` `0.23s`, `pe_dependency_paths_cli_check` `2.16s`) - **Windows Python checks**: `tests/dependency_paths_check.py` ok (`0.2s`), `tests/intake/paths_check.py` ok (`0.2s`) - `sccache`: 25/40 hits; wall `22.3s` AI-assisted; commands listed were executed locally.
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
R0Y00/Xbox2Windows!2428
No description provided.