Scripts: harden pe_exports CLI argument handling, validation, and test coverage #1814

Open
github-bot wants to merge 1 commit from github-bot/gh-1814 into main AGit
Owner

@⁠heditrigui on GitHub · 2026-11-24 21:04 UTC · original
heditrigui:scripts/pe-exports-cli-hardening → main · +242 −49 · 2 files · 1 commits · open

Summary

Hardens CLI argument handling and validation in scripts/re/pe_exports.py and expands unit test coverage in scripts/test_pe_exports.py:

  • Adds -h and --help CLI option support with usage docstrings and clean exit code 0.
  • Rejects missing arguments with usage instructions and exit code 2.
  • Handles missing or unreadable files cleanly (reports error: file not found: '<path>' on stderr and exits code 1) instead of crashing with unhandled Python exceptions.
  • Validates PE signatures and header bounds, reporting descriptive errors on truncated or invalid headers.
  • Modularizes export extraction into reusable parse_exports(bytes) and dump_pe_exports(path) functions.
  • Expands scripts/test_pe_exports.py from 1 to 8 tests covering CLI argument flags, exit codes, missing files, invalid PE binaries, and direct Python API parsing across both 32-bit (PE32) and 64-bit (PE32+) binaries.

Tested

  • python -m unittest scripts/test_pe_exports.py (8 passed in 0.40s).
  • python -m pytest scripts/ (23 passed in 0.78s).
  • Validated with scripts/pr_check.py --local.

Not tested

  • Retail game smoke execution (scripts/ tools are non-runtime code).

AI use

  • Antigravity (Gemini 3.8 Flash (High))
**@⁠heditrigui** on GitHub · 2026-11-24 21:04 UTC · [original](https://github.com/xcl-dev/xcl/pull/1814) `heditrigui:scripts/pe-exports-cli-hardening` → `main` · +242 −49 · 2 files · 1 commits · open ### Summary Hardens CLI argument handling and validation in `scripts/re/pe_exports.py` and expands unit test coverage in `scripts/test_pe_exports.py`: - Adds `-h` and `--help` CLI option support with usage docstrings and clean exit code 0. - Rejects missing arguments with usage instructions and exit code 2. - Handles missing or unreadable files cleanly (reports `error: file not found: '<path>'` on stderr and exits code 1) instead of crashing with unhandled Python exceptions. - Validates PE signatures and header bounds, reporting descriptive errors on truncated or invalid headers. - Modularizes export extraction into reusable `parse_exports(bytes)` and `dump_pe_exports(path)` functions. - Expands `scripts/test_pe_exports.py` from 1 to 8 tests covering CLI argument flags, exit codes, missing files, invalid PE binaries, and direct Python API parsing across both 32-bit (PE32) and 64-bit (PE32+) binaries. **Tested** - `python -m unittest scripts/test_pe_exports.py` (8 passed in 0.40s). - `python -m pytest scripts/` (23 passed in 0.78s). - Validated with `scripts/pr_check.py --local`. **Not tested** - Retail game smoke execution (`scripts/` tools are non-runtime code). **AI use** - Antigravity (Gemini 3.8 Flash (High))
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:06:06 +00:00
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-24 21:14 UTC · original

Tested exact head 0180bf4, script tests only, since this PR has no test report yet.

Tested

  • Windows 11 Home 26300, Python 3.14.3 with pytest 9.0.3, Windows PowerShell 5.1.26100.9818 (no PowerShell 7 here).
  • python -m pytest scripts/test_pe_exports.py at the head: 8 passed, 2 subtests passed.
  • The PR's test file against current main's script (266b845): does not get to run: collection fails with FileNotFoundError: ... '-q', because main's pe_exports.py reads sys.argv[1:] at import time (which this PR changes).

Not tested

  • PowerShell 7, the CI workflow itself, a game (no runtime code changed).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
**@⁠futurepro62** on GitHub · 2026-11-24 21:14 UTC · [original](https://github.com/xcl-dev/xcl/pull/1814#issuecomment-7144671784) Tested exact head `0180bf4`, script tests only, since this PR has no test report yet. **Tested** - Windows 11 Home 26300, Python 3.14.3 with pytest 9.0.3, Windows PowerShell 5.1.26100.9818 (no PowerShell 7 here). - `python -m pytest scripts/test_pe_exports.py` at the head: 8 passed, 2 subtests passed. - The PR's test file against current main's script (`266b845`): does not get to run: collection fails with `FileNotFoundError: ... '-q'`, because main's `pe_exports.py` reads `sys.argv[1:]` at import time (which this PR changes). **Not tested** - PowerShell 7, the CI workflow itself, a game (no runtime code changed). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 00:28 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~23 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-25 00:28 UTC · [original](https://github.com/xcl-dev/xcl/pull/1814#issuecomment-7148541746) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~23 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1814/head:github-bot/gh-1814'
git switch 'github-bot/gh-1814'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1814'
git switch 'github-bot/gh-1814'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1814'
git switch 'github-bot/gh-1814'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1814'
git switch 'main'
git merge --squash 'github-bot/gh-1814'
git switch 'main'
git merge --ff-only 'github-bot/gh-1814'
git switch 'main'
git merge 'github-bot/gh-1814'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.