pe: extract main(argv) and add path/struct.error guards in pe_run_package with CLI suite #2579

Merged
Ammmae0x merged 2 commits from upstream-pr/2587 into main 2026-11-25 22:20:23 +00:00
Ammmae0x commented 2026-11-25 22:05:47 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-25T22:05:47Z.


Summary

Extracts a testable main(argv=None) -> int entrypoint in tools/pe_run_package.py, adds upfront directory/regular-file path validation for package, mapper, and --shim arguments, and guards struct.error alongside (ValueError, OSError, pefile.PEFormatError) with zero raw tracebacks, backed by a standalone pure-Python CLI test suite registered in CTest.

Changes

  • tools/pe_run_package.py:
    • Extract main(argv=None) -> int forwarding argv to parser.parse_args(argv) and returning 0, invoking raise SystemExit(main()) under __main__.
    • Validate upfront that options.package is an existing directory, options.mapper is not an existing directory (preserving non-existent mapper placeholders in --preflight-only), and every --shim path resolves to an existing regular file.
    • Expand main() exception handling to (ValueError, OSError, pefile.PEFormatError, struct.error) via parser.exit(1, f"{exc}\n") with zero raw tracebacks, preserving exact JSON stdout and refusal exits tested by tests/pe_run_package_invalid_check.py, tests/pe_run_package_plan_check.py, and tests/host_commit_check.py.
  • tests/pe_run_package_cli_check.py:
    • Add standalone pure-Python CLI, path guard, exception handling, and subprocess smoke tests.
  • CMakeLists.txt:
    • Register pe_run_package_cli_check in CTest right after pe_run_package_plan_check.

Verification

All commands executed after rebasing onto upstream/main (fb2f86ac):

  • out/pe-env/Scripts/python.exe -B tests/pe_run_package_cli_check.py -v
    • Observed: Ran 3 tests in 0.351s / OK (exit 0)
  • out/pe-env/Scripts/python.exe -B tests/pe_run_package_invalid_check.py
    • Observed: Ran 3 tests in 0.520s / OK (exit 0)
  • out/pe-env/Scripts/python.exe -B tests/pe_run_package_plan_check.py
    • Observed: Ran 11 tests in 1.219s / OK (exit 0)
  • out/pe-env/Scripts/python.exe -B tests/host_commit_check.py
    • Observed: Ran 7 tests in 0.008s / OK (exit 0)
  • out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py
    • Observed: form coverage checks passed (exit 0)
  • out/pe-env/Scripts/python.exe -B tests/docs_links_check.py
    • Observed: Self-test passed. Checked 19 Markdown files and 495 links. (exit 0)
  • out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py
    • Observed: Self-test passed. Checked 1816 tracked source, script and build/CI files: no bidirectional controls. (exit 0)
  • Minimal temp-copy mutation testing (8 non-equivalent mutations across argv forwarding, root.is_dir(), mapper.is_dir(), --shim dir/file checks, struct.error/PEFormatError/OSError catches, and main() return code): 8/8 killed.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6614708685 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2587). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-25T22:05:47Z. --- ## Summary Extracts a testable `main(argv=None) -> int` entrypoint in `tools/pe_run_package.py`, adds upfront directory/regular-file path validation for `package`, `mapper`, and `--shim` arguments, and guards `struct.error` alongside `(ValueError, OSError, pefile.PEFormatError)` with zero raw tracebacks, backed by a standalone pure-Python CLI test suite registered in CTest. ### Changes - **`tools/pe_run_package.py`**: - Extract `main(argv=None) -> int` forwarding `argv` to `parser.parse_args(argv)` and returning `0`, invoking `raise SystemExit(main())` under `__main__`. - Validate upfront that `options.package` is an existing directory, `options.mapper` is not an existing directory (preserving non-existent mapper placeholders in `--preflight-only`), and every `--shim` path resolves to an existing regular file. - Expand `main()` exception handling to `(ValueError, OSError, pefile.PEFormatError, struct.error)` via `parser.exit(1, f"{exc}\n")` with zero raw tracebacks, preserving exact JSON stdout and refusal exits tested by `tests/pe_run_package_invalid_check.py`, `tests/pe_run_package_plan_check.py`, and `tests/host_commit_check.py`. - **`tests/pe_run_package_cli_check.py`**: - Add standalone pure-Python CLI, path guard, exception handling, and subprocess smoke tests. - **`CMakeLists.txt`**: - Register `pe_run_package_cli_check` in CTest right after `pe_run_package_plan_check`. ## Verification All commands executed after rebasing onto `upstream/main` (`fb2f86ac`): - `out/pe-env/Scripts/python.exe -B tests/pe_run_package_cli_check.py -v` - Observed: `Ran 3 tests in 0.351s` / `OK` (exit 0) - `out/pe-env/Scripts/python.exe -B tests/pe_run_package_invalid_check.py` - Observed: `Ran 3 tests in 0.520s` / `OK` (exit 0) - `out/pe-env/Scripts/python.exe -B tests/pe_run_package_plan_check.py` - Observed: `Ran 11 tests in 1.219s` / `OK` (exit 0) - `out/pe-env/Scripts/python.exe -B tests/host_commit_check.py` - Observed: `Ran 7 tests in 0.008s` / `OK` (exit 0) - `out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py` - Observed: `form coverage checks passed` (exit 0) - `out/pe-env/Scripts/python.exe -B tests/docs_links_check.py` - Observed: `Self-test passed. Checked 19 Markdown files and 495 links.` (exit 0) - `out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py` - Observed: `Self-test passed. Checked 1816 tracked source, script and build/CI files: no bidirectional controls.` (exit 0) - Minimal temp-copy mutation testing (8 non-equivalent mutations across `argv` forwarding, `root.is_dir()`, `mapper.is_dir()`, `--shim` dir/file checks, `struct.error`/`PEFormatError`/`OSError` catches, and `main()` return code): 8/8 killed. AI-assisted.
upstream-sync closed this pull request 2026-11-25 23:01:55 +00:00
tedin7 commented 2026-11-25 23:01:56 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T22:12:16Z.

Review: COMMENTED


Review of head 91d64011 (3 commits behind main, mergeable, CI green).

Scope: Python-only (tools/pe_run_package.py, new tests/pe_run_package_cli_check.py, CTest registration). It does not claim to advance game startup, so no game verification is needed.

Code: main(argv=None) -> int, upfront package/mapper/--shim path checks and struct.error in the handled exceptions all look correct. The non-existent mapper placeholder for --preflight-only is preserved. Sibling suites (pe_run_package_invalid_check, host_commit_check) still pass.

Mutations (each makes the new tests fail, restored afterwards):

  • drop struct.error from the except tuple: error
  • if not root.is_dir() -> if False: 1 failure
  • if mapper.is_dir() -> if False: 2 failures

Linux commands run (pefile in a throwaway venv):

  • pe_run_package_cli_check.py guard tests: OK; the positive preflight test errors only on ctypes.WINFUNCTYPE (Windows-only). pe_run_package_plan_check.py fails the same way on origin/main, so it is not caused by this PR.
  • pe_run_package_invalid_check.py: OK. host_commit_check.py: OK (1 skipped).
  • tests/docs_links_check.py, tests/bidi_controls_check.py, git diff --check origin/main...HEAD: clean.

Note: the positive test has no platform skip, like its sibling pe_run_package_plan_check. This is fine because CTest registers it only in the Windows intake block. The positive path needs a Windows run, which I am queuing next.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6065701351 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2587#pullrequestreview-6065701351). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T22:12:16Z. **Review:** COMMENTED --- Review of head 91d64011 (3 commits behind main, mergeable, CI green). Scope: Python-only (tools/pe_run_package.py, new tests/pe_run_package_cli_check.py, CTest registration). It does not claim to advance game startup, so no game verification is needed. Code: `main(argv=None) -> int`, upfront package/mapper/--shim path checks and `struct.error` in the handled exceptions all look correct. The non-existent mapper placeholder for `--preflight-only` is preserved. Sibling suites (`pe_run_package_invalid_check`, `host_commit_check`) still pass. Mutations (each makes the new tests fail, restored afterwards): - drop `struct.error` from the except tuple: error - `if not root.is_dir()` -> `if False`: 1 failure - `if mapper.is_dir()` -> `if False`: 2 failures Linux commands run (pefile in a throwaway venv): - `pe_run_package_cli_check.py` guard tests: OK; the positive preflight test errors only on `ctypes.WINFUNCTYPE` (Windows-only). `pe_run_package_plan_check.py` fails the same way on origin/main, so it is not caused by this PR. - `pe_run_package_invalid_check.py`: OK. `host_commit_check.py`: OK (1 skipped). - `tests/docs_links_check.py`, `tests/bidi_controls_check.py`, `git diff --check origin/main...HEAD`: clean. Note: the positive test has no platform skip, like its sibling `pe_run_package_plan_check`. This is fine because CTest registers it only in the Windows intake block. The positive path needs a Windows run, which I am queuing next. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-25 23:02:04 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T22:19:53Z.


Win2025 WARP receipt for head d2d75268 after updating with main.

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

  • Debug (--preset dev):
  • Build (cmake --build --preset dev --target trap_missing_data_exe trap_missing_exe -- -j 2): 0.19s (configure 0.00s)
  • Test (ctest --preset dev -R 'pe_run_package' --parallel 2 --no-tests=error --output-on-failure): 4/4 passed (7.96s: pe_run_package_invalid_pe 1.43s, pe_run_package_plan_check 3.02s, pe_run_package_cli_check 1.78s, pe_run_package_trap_missing 4.71s)
  • Release /O2 (--preset release):
  • Build (cmake --build --preset release --target trap_missing_data_exe trap_missing_exe -- -j 2): 7.98s (configure 0.00s)
  • Test (ctest --preset release -R 'pe_run_package' --parallel 2 --no-tests=error --output-on-failure): 4/4 passed (8.50s: pe_run_package_invalid_pe 1.40s, pe_run_package_cli_check 1.59s, pe_run_package_plan_check 3.00s, pe_run_package_trap_missing 5.30s)
  • Windows Python checks: tests/host_commit_check.py ok (0.8s), tests/intake/import_forms_check.py ok (0.4s), tests/pe_package_ordinal_plan_check.py ok (0.6s), tests/pe_package_preflight_check.py ok (1.6s)
  • sccache: 0/3 hits; wall 32.3s

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7176228424 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2587#issuecomment-7176228424). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T22:19:53Z. --- Win2025 WARP receipt for head d2d75268 after updating with main. Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `d2d752688507eb5fc8299946d976405eee6f59d2`: - **Debug (`--preset dev`)**: - Build (`cmake --build --preset dev --target trap_missing_data_exe trap_missing_exe -- -j 2`): `0.19s` (configure `0.00s`) - Test (`ctest --preset dev -R 'pe_run_package' --parallel 2 --no-tests=error --output-on-failure`): **4/4 passed** (`7.96s`: `pe_run_package_invalid_pe` `1.43s`, `pe_run_package_plan_check` `3.02s`, `pe_run_package_cli_check` `1.78s`, `pe_run_package_trap_missing` `4.71s`) - **Release `/O2` (`--preset release`)**: - Build (`cmake --build --preset release --target trap_missing_data_exe trap_missing_exe -- -j 2`): `7.98s` (configure `0.00s`) - Test (`ctest --preset release -R 'pe_run_package' --parallel 2 --no-tests=error --output-on-failure`): **4/4 passed** (`8.50s`: `pe_run_package_invalid_pe` `1.40s`, `pe_run_package_cli_check` `1.59s`, `pe_run_package_plan_check` `3.00s`, `pe_run_package_trap_missing` `5.30s`) - **Windows Python checks**: `tests/host_commit_check.py` ok (`0.8s`), `tests/intake/import_forms_check.py` ok (`0.4s`), `tests/pe_package_ordinal_plan_check.py` ok (`0.6s`), `tests/pe_package_preflight_check.py` ok (`1.6s`) - `sccache`: 0/3 hits; wall `32.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!2579
No description provided.