tooling: harden hardware_reports CLI guards and add CLI suite #2674
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2682"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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.pyand add a pure-Python CLI suite (tests/hardware_reports_cli_check.py), registered inCMakeLists.txtastooling_hardware_reports_cli_check.main(argv=None) -> intthat--after >= 0when provided and that everycommentspath and--readmeis a regular file (not a directory or missing) before reading.bool, negative, and non-intcomment IDs inload_comments()withValueError(preserving exit code2and zero raw tracebacks).--jsonoutput, exit code2, and all tests intests/hardware_reports_check.py.Verification
Verified on commit
b3e1ec09(based onupstream/mainc99b7b89) on Windows usingout/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 &--jsonoutput across UTF-8/UTF-16 paginated files includingid=0,--afterfiltering,argv=None/__main__, upfront dir/missingcommentsand--readmerejection, 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.tests/hardware_reports_cli_check.py): allowingboolcomment IDs, allowing negative--after, and disabling--readmedirectory guard.Evidence and follow-up
Checklist
AI-assisted.
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:
ValueError/OSError-> exit 2). It rejects bool/negative ids, negative--after, and directory/missing comments or readme paths before reading.tooling_hardware_reports_cli_checknext to the siblinghardware_reportstest.tools/hardware_reports.pyfrom main makes the new suite fail (15 failures); with the PR version it passes.Commands executed locally (Linux):
python3 -B tests/hardware_reports_check.pyOKpython3 -B tests/hardware_reports_cli_check.pyOK (5 tests)python3 tests/docs_links_check.py,python3 tests/bidi_controls_check.py,git diff --check origin/main...HEADcleanAI-assisted; commands listed were executed locally.
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_subprocessusessubprocess.run(..., text=True)with noencoding. On Windows that decodes the child's stdout with the console code page, whiletools/hardware_reports.pyreconfigures stdout to UTF-8 (sys.stdout.reconfigure(encoding="utf-8")). The en dash in the report text (ge 32–32) is then misread, sojson.loads(proc.stdout) == data_a202at 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.encoding="utf-8"(and keeptext=Trueor drop it) tosubprocess.run, optionally alsoenv={**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 forcommentsand--readme, bool/negative/non-int comment IDs) match the description, and the CMake registration is a singleadd_test. Once the decoding is fixed, a Windows run ofhardware_reportsandtooling_hardware_reports_cli_checkshould confirm it.@Ammmae0x, please push the fix and I will re-test.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T03:24:50Z.
Win2025 result for head
5e4a4421:hardware_reportspasses, but the newtooling_hardware_reports_cli_checkfails (4 of 5 subtests pass).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_reportsAI-assisted; commands listed were executed locally.
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.pynow runs the CLI subprocess withencoding="utf-8"andPYTHONIOENCODING=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:--preset dev):ctest --preset dev -R 'hardware_reports' --no-tests=error: 2/2 passed (hardware_reports,tooling_hardware_reports_cli_check)/O2(--preset release):ctest --preset release -R 'hardware_reports' --no-tests=error: 2/2 passedtests/hardware_reports_check.pyokCommand:
python3 x2w_pipe.py win2025 2682 --regex hardware_reports --wait 7200 --keep-releaseLinux:
python3 -B tests/hardware_reports_cli_check.pyOK.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T04:04:41Z.
Review: COMMENTED
Review of head
0e38e149(previous head5e4a4421plus 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.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.AI-assisted; commands listed were executed locally.