tooling: harden hardware_reports CLI guards and add CLI suite #2674

Merged
Ammmae0x merged 4 commits from upstream-pr/2682 into main 2026-11-26 04:05:12 +00:00
Ammmae0x commented 2026-11-26 01:49:01 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-26T01:49:01Z.


Change

Harden upfront CLI path/flag and comment-ID validation in tools/hardware_reports.py and add a pure-Python CLI suite (tests/hardware_reports_cli_check.py), registered in CMakeLists.txt as tooling_hardware_reports_cli_check.

  • Validate upfront in main(argv=None) -> int that --after >= 0 when provided and that every comments path and --readme is a regular file (not a directory or missing) before reading.
  • Reject bool, negative, and non-int comment IDs in load_comments() with ValueError (preserving exit code 2 and zero raw tracebacks).
  • Preserve existing Markdown and --json output, exit code 2, and all tests in tests/hardware_reports_check.py.

Verification

Verified on commit b3e1ec09 (based on upstream/main c99b7b89) on Windows using out/pe-env/Scripts/python.exe -B:

  • out\pe-env\Scripts\python.exe -B tests\hardware_reports_check.py -> exit 0 (16/16 OK).
  • out\pe-env\Scripts\python.exe -B tests\hardware_reports_cli_check.py -> exit 0 (5/5 tests OK, 0 skips: Markdown & --json output across UTF-8/UTF-16 paginated files including id=0, --after filtering, argv=None / __main__, upfront dir/missing comments and --readme rejection, bool/negative/non-int comment IDs, negative --after, malformed JSON/UTF-8/README, and Python 3.14-safe argparse checks).
  • out\pe-env\Scripts\python.exe -B tests\form_coverage_check.py, tests\docs_links_check.py, tests\bidi_controls_check.py -> all exit 0.
  • On-disk spot-mutation negative controls (3/3 killed by tests/hardware_reports_cli_check.py): allowing bool comment IDs, allowing negative --after, and disabling --readme directory guard.

Evidence and follow-up

  • Pure-Python synthetic GitHub comment JSON and README table fixtures generated at runtime in temporary directories (MIT License; no network calls, no external dumps).
  • No external tools or GPU hardware required.

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:6617679153 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2682). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-26T01:49:01Z. --- ## Change Harden upfront CLI path/flag and comment-ID validation in `tools/hardware_reports.py` and add a pure-Python CLI suite (`tests/hardware_reports_cli_check.py`), registered in `CMakeLists.txt` as `tooling_hardware_reports_cli_check`. - Validate upfront in `main(argv=None) -> int` that `--after >= 0` when provided and that every `comments` path and `--readme` is a regular file (not a directory or missing) before reading. - Reject `bool`, negative, and non-`int` comment IDs in `load_comments()` with `ValueError` (preserving exit code `2` and zero raw tracebacks). - Preserve existing Markdown and `--json` output, exit code `2`, and all tests in `tests/hardware_reports_check.py`. ## Verification Verified on commit `b3e1ec09` (based on `upstream/main` `c99b7b89`) on Windows using `out/pe-env/Scripts/python.exe -B`: - `out\pe-env\Scripts\python.exe -B tests\hardware_reports_check.py` -> exit 0 (16/16 OK). - `out\pe-env\Scripts\python.exe -B tests\hardware_reports_cli_check.py` -> exit 0 (5/5 tests OK, 0 skips: Markdown & `--json` output across UTF-8/UTF-16 paginated files including `id=0`, `--after` filtering, `argv=None` / `__main__`, upfront dir/missing `comments` and `--readme` rejection, bool/negative/non-int comment IDs, negative `--after`, malformed JSON/UTF-8/README, and Python 3.14-safe argparse checks). - `out\pe-env\Scripts\python.exe -B tests\form_coverage_check.py`, `tests\docs_links_check.py`, `tests\bidi_controls_check.py` -> all exit 0. - On-disk spot-mutation negative controls (3/3 killed by `tests/hardware_reports_cli_check.py`): allowing `bool` comment IDs, allowing negative `--after`, and disabling `--readme` directory guard. ## Evidence and follow-up - Pure-Python synthetic GitHub comment JSON and README table fixtures generated at runtime in temporary directories (MIT License; no network calls, no external dumps). - No external tools or GPU hardware required. ## 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-26 04:04:18 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T03:16:41Z.

Review: COMMENTED


Review of head 5e4a4421 (comment only).

What I checked:

  • The tool change is small and keeps the existing error path (ValueError/OSError -> exit 2). It rejects bool/negative ids, negative --after, and directory/missing comments or readme paths before reading.
  • The new CLI suite is registered as tooling_hardware_reports_cli_check next to the sibling hardware_reports test.
  • Mutation: restoring tools/hardware_reports.py from main makes the new suite fail (15 failures); with the PR version it passes.
  • No other PR covers this; not a startup or game change.

Commands executed locally (Linux):

  • python3 -B tests/hardware_reports_check.py OK
  • python3 -B tests/hardware_reports_cli_check.py OK (5 tests)
  • mutation (tool from main + new suite) FAILED as expected
  • python3 tests/docs_links_check.py, python3 tests/bidi_controls_check.py, git diff --check origin/main...HEAD clean

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6068084550 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2682#pullrequestreview-6068084550). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T03:16:41Z. **Review:** COMMENTED --- Review of head 5e4a4421 (comment only). What I checked: - The tool change is small and keeps the existing error path (`ValueError`/`OSError` -> exit 2). It rejects bool/negative ids, negative `--after`, and directory/missing comments or readme paths before reading. - The new CLI suite is registered as `tooling_hardware_reports_cli_check` next to the sibling `hardware_reports` test. - Mutation: restoring `tools/hardware_reports.py` from main makes the new suite fail (15 failures); with the PR version it passes. - No other PR covers this; not a startup or game change. Commands executed locally (Linux): - `python3 -B tests/hardware_reports_check.py` OK - `python3 -B tests/hardware_reports_cli_check.py` OK (5 tests) - mutation (tool from main + new suite) FAILED as expected - `python3 tests/docs_links_check.py`, `python3 tests/bidi_controls_check.py`, `git diff --check origin/main...HEAD` clean AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-26 04:04:18 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T03:45:06Z.

Review: COMMENTED


Review of head 5e4a4421 (comment only).

Result: not ready to merge. The new test fails on Windows, deterministically.

Finding (test bug, not tool bug):

  • tests/hardware_reports_cli_check.py:41-46 _run_subprocess uses subprocess.run(..., text=True) with no encoding. On Windows that decodes the child's stdout with the console code page, while tools/hardware_reports.py reconfigures stdout to UTF-8 (sys.stdout.reconfigure(encoding="utf-8")). The en dash in the report text (ge 32–32) is then misread, so json.loads(proc.stdout) == data_a202 at line 100 fails (test_markdown_json_after_filtering_and_boundary_id_zero). The earlier Win2025 run on this same head showed 4 of 5 subtests passing and this one failing.
  • Fix: pass encoding="utf-8" (and keep text=True or drop it) to subprocess.run, optionally also env={**os.environ, "PYTHONIOENCODING": "utf-8"}. The same applies to any other place the test decodes child output.

The rest looks sound: the upfront guards (--after >= 0, regular-file checks for comments and --readme, bool/negative/non-int comment IDs) match the description, and the CMake registration is a single add_test. Once the decoding is fixed, a Windows run of hardware_reports and tooling_hardware_reports_cli_check should confirm it.

@Ammmae0x, please push the fix and I will re-test.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6068268113 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2682#pullrequestreview-6068268113). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T03:45:06Z. **Review:** COMMENTED --- Review of head 5e4a4421 (comment only). Result: not ready to merge. The new test fails on Windows, deterministically. Finding (test bug, not tool bug): - `tests/hardware_reports_cli_check.py:41-46` `_run_subprocess` uses `subprocess.run(..., text=True)` with no `encoding`. On Windows that decodes the child's stdout with the console code page, while `tools/hardware_reports.py` reconfigures stdout to UTF-8 (`sys.stdout.reconfigure(encoding="utf-8")`). The en dash in the report text (`ge 32–32`) is then misread, so `json.loads(proc.stdout) == data_a202` at line 100 fails (`test_markdown_json_after_filtering_and_boundary_id_zero`). The earlier Win2025 run on this same head showed 4 of 5 subtests passing and this one failing. - Fix: pass `encoding="utf-8"` (and keep `text=True` or drop it) to `subprocess.run`, optionally also `env={**os.environ, "PYTHONIOENCODING": "utf-8"}`. The same applies to any other place the test decodes child output. The rest looks sound: the upfront guards (`--after >= 0`, regular-file checks for `comments` and `--readme`, bool/negative/non-int comment IDs) match the description, and the CMake registration is a single `add_test`. Once the decoding is fixed, a Windows run of `hardware_reports` and `tooling_hardware_reports_cli_check` should confirm it. @Ammmae0x, please push the fix and I will re-test. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-26 04:04:37 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T03:24:50Z.


Win2025 result for head 5e4a4421: hardware_reports passes, but the new tooling_hardware_reports_cli_check fails (4 of 5 subtests pass).

FAIL: test_markdown_json_after_filtering_and_boundary_id_zero
tests/hardware_reports_cli_check.py:100  assertEqual(json.loads(proc.stdout), data_a202)
'ge 32–32' (expected)  vs  'ge 32?32' (got from the subprocess)

The en dash in the report text does not survive the subprocess stdout on Windows (the console code page is not UTF-8, so it is replaced). Suggested fix: run the subprocess with PYTHONIOENCODING=utf-8 (or -X utf8) in the test environment, or decode with the same encoding the tool writes. The tool change itself looks fine; Linux passes.

Command: python3 x2w_pipe.py win2025 2682 --wait 7200 --keep-release --regex hardware_reports

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7181696819 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2682#issuecomment-7181696819). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T03:24:50Z. --- Win2025 result for head 5e4a4421: `hardware_reports` passes, but the new `tooling_hardware_reports_cli_check` fails (4 of 5 subtests pass). FAIL: test_markdown_json_after_filtering_and_boundary_id_zero tests/hardware_reports_cli_check.py:100 assertEqual(json.loads(proc.stdout), data_a202) 'ge 32–32' (expected) vs 'ge 32?32' (got from the subprocess) The en dash in the report text does not survive the subprocess stdout on Windows (the console code page is not UTF-8, so it is replaced). Suggested fix: run the subprocess with `PYTHONIOENCODING=utf-8` (or `-X utf8`) in the test environment, or decode with the same encoding the tool writes. The tool change itself looks fine; Linux passes. Command: `python3 x2w_pipe.py win2025 2682 --wait 7200 --keep-release --regex hardware_reports` AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-26 04:04:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T04:04:24Z.


Pushed 0e38e149: merge of main plus one small test fix. tests/hardware_reports_cli_check.py now runs the CLI subprocess with encoding="utf-8" and PYTHONIOENCODING=utf-8. This answers the earlier Win2025 failure, where the en dash in the report text came back as ? because the console code page was not UTF-8. The tool change itself is unchanged.

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

  • Debug (--preset dev): ctest --preset dev -R 'hardware_reports' --no-tests=error: 2/2 passed (hardware_reports, tooling_hardware_reports_cli_check)
  • Release /O2 (--preset release): ctest --preset release -R 'hardware_reports' --no-tests=error: 2/2 passed
  • Windows Python checks: tests/hardware_reports_check.py ok

Command: python3 x2w_pipe.py win2025 2682 --regex hardware_reports --wait 7200 --keep-release
Linux: python3 -B tests/hardware_reports_cli_check.py OK.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7182269749 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2682#issuecomment-7182269749). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T04:04:24Z. --- Pushed 0e38e149: merge of main plus one small test fix. `tests/hardware_reports_cli_check.py` now runs the CLI subprocess with `encoding="utf-8"` and `PYTHONIOENCODING=utf-8`. This answers the earlier Win2025 failure, where the en dash in the report text came back as `?` because the console code page was not UTF-8. The tool change itself is unchanged. Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `0e38e14927a49707c2b1c4b9b2ffa137f6a1f0aa`: - **Debug (`--preset dev`)**: `ctest --preset dev -R 'hardware_reports' --no-tests=error`: **2/2 passed** (`hardware_reports`, `tooling_hardware_reports_cli_check`) - **Release `/O2` (`--preset release`)**: `ctest --preset release -R 'hardware_reports' --no-tests=error`: **2/2 passed** - **Windows Python checks**: `tests/hardware_reports_check.py` ok Command: `python3 x2w_pipe.py win2025 2682 --regex hardware_reports --wait 7200 --keep-release` Linux: `python3 -B tests/hardware_reports_cli_check.py` OK. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-26 05:02:12 +00:00
tedin7 commented 2026-11-26 05:02:12 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T04:04:41Z.

Review: COMMENTED


Review of head 0e38e149 (previous head 5e4a4421 plus a merge of main and one test-only commit).

  • tools/hardware_reports.py: stricter guards (non-negative --after, bool and negative ids rejected, directory and missing-file paths reported as clean errors). Matches what the new CLI suite asserts. No sibling callsites left out.
  • tests/hardware_reports_cli_check.py: 5 tests cover positive output, each error path (exit code, empty stdout, no traceback) and the id guard. The subprocess helper now decodes as UTF-8, which fixes the Windows code page failure.
  • Commands run: python3 -B tests/hardware_reports_cli_check.py (OK), git diff --check origin/main...HEAD (clean), python3 tests/docs_links_check.py, python3 tests/bidi_controls_check.py. Win2025 dev and release: 2/2 passed (receipt above). CI green.
  • Tooling only. No startup or game claim.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6068399391 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2682#pullrequestreview-6068399391). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T04:04:41Z. **Review:** COMMENTED --- Review of head 0e38e149 (previous head 5e4a4421 plus a merge of main and one test-only commit). - `tools/hardware_reports.py`: stricter guards (non-negative `--after`, bool and negative ids rejected, directory and missing-file paths reported as clean errors). Matches what the new CLI suite asserts. No sibling callsites left out. - `tests/hardware_reports_cli_check.py`: 5 tests cover positive output, each error path (exit code, empty stdout, no traceback) and the id guard. The subprocess helper now decodes as UTF-8, which fixes the Windows code page failure. - Commands run: `python3 -B tests/hardware_reports_cli_check.py` (OK), `git diff --check origin/main...HEAD` (clean), `python3 tests/docs_links_check.py`, `python3 tests/bidi_controls_check.py`. Win2025 dev and release: 2/2 passed (receipt above). CI green. - Tooling only. No startup or game claim. 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!2674
No description provided.