ci: harden form_reference CLI with atomic writes and add CLI suite #2667

Merged
Ammmae0x merged 1 commit from upstream-pr/2675 into main 2026-11-26 02:05:25 +00:00
Ammmae0x commented 2026-11-26 01:45:23 +00:00 (Migrated from github.com)

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


Change

Extract an argparse CLI entrypoint main(argv=None) -> int with upfront input/output validation and atomic writes in tools/form_reference.py, and add a pure-Python synthetic .rst CLI test suite (tests/form_reference_cli_check.py), registered in CMakeLists.txt as ci_form_reference_cli_check.

  • Support positional llvm_docs_dir and optional --out-dir (defaulting to docs/coverage).
  • Validate upfront that llvm_docs_dir is a directory containing all four required AMDGPUAsmGFX{10,1011,1013,1030}.rst regular files and that --out-dir and each target .tsv path are not symlinks, directories, or under file parents before parsing inputs.
  • Replace direct write_text() in write() with sibling-temp _write_atomic() using os.replace() and temp unlink on all errors; catch (OSError, ValueError) in main() for clean stderr output and exit code 1 with zero raw tracebacks.

Verification

Verified on commit 01cab8bf (based on upstream/main 82c70807) on Windows using out/pe-env/Scripts/python.exe -B:

  • out\pe-env\Scripts\python.exe -B tests\form_reference_cli_check.py -> exit 0 (9/9 tests OK, 0 skips: synthetic AMDGPUAsmGFX*.rst generation into nested --out-dir, atomic overwrite with 0 .tmp, argv=None / __main__, missing/file docs dir, missing/dir .rst, output dir/symlink/file-parent guards, os.replace failure preserving existing TSVs, Python 3.14-safe argparse checks, and 4 fast temp mutations).
  • out\pe-env\Scripts\python.exe -B tests\form_coverage_check.py -> exit 0.
  • out\pe-env\Scripts\python.exe -B tests\docs_links_check.py -> exit 0.
  • out\pe-env\Scripts\python.exe -B tests\bidi_controls_check.py -> exit 0.
  • On-disk spot-mutation negative controls (3/3 killed by tests/form_reference_cli_check.py): disabling output symlink check, disabling required .rst regular-file check, and disabling .tmp cleanup on replace failure.

Evidence and follow-up

  • Pure-Python synthetic AMDGPUAsmGFX*.rst fixtures are generated at runtime in temporary directories (MIT License; does not modify docs/coverage/*.tsv or tools/form_coverage.py).
  • No external LLVM checkout 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:6617629404 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2675). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-26T01:45:23Z. --- ## Change Extract an `argparse` CLI entrypoint `main(argv=None) -> int` with upfront input/output validation and atomic writes in `tools/form_reference.py`, and add a pure-Python synthetic `.rst` CLI test suite (`tests/form_reference_cli_check.py`), registered in `CMakeLists.txt` as `ci_form_reference_cli_check`. - Support positional `llvm_docs_dir` and optional `--out-dir` (defaulting to `docs/coverage`). - Validate upfront that `llvm_docs_dir` is a directory containing all four required `AMDGPUAsmGFX{10,1011,1013,1030}.rst` regular files and that `--out-dir` and each target `.tsv` path are not symlinks, directories, or under file parents before parsing inputs. - Replace direct `write_text()` in `write()` with sibling-temp `_write_atomic()` using `os.replace()` and temp unlink on all errors; catch `(OSError, ValueError)` in `main()` for clean stderr output and exit code `1` with zero raw tracebacks. ## Verification Verified on commit `01cab8bf` (based on `upstream/main` `82c70807`) on Windows using `out/pe-env/Scripts/python.exe -B`: - `out\pe-env\Scripts\python.exe -B tests\form_reference_cli_check.py` -> exit 0 (9/9 tests OK, 0 skips: synthetic `AMDGPUAsmGFX*.rst` generation into nested `--out-dir`, atomic overwrite with 0 `.tmp`, `argv=None` / `__main__`, missing/file docs dir, missing/dir `.rst`, output dir/symlink/file-parent guards, `os.replace` failure preserving existing TSVs, Python 3.14-safe argparse checks, and 4 fast temp mutations). - `out\pe-env\Scripts\python.exe -B tests\form_coverage_check.py` -> exit 0. - `out\pe-env\Scripts\python.exe -B tests\docs_links_check.py` -> exit 0. - `out\pe-env\Scripts\python.exe -B tests\bidi_controls_check.py` -> exit 0. - On-disk spot-mutation negative controls (3/3 killed by `tests/form_reference_cli_check.py`): disabling output symlink check, disabling required `.rst` regular-file check, and disabling `.tmp` cleanup on replace failure. ## Evidence and follow-up - Pure-Python synthetic `AMDGPUAsmGFX*.rst` fixtures are generated at runtime in temporary directories (MIT License; does not modify `docs/coverage/*.tsv` or `tools/form_coverage.py`). - No external LLVM checkout 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.
upstream-sync closed this pull request 2026-11-26 03:03:09 +00:00
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!2667
No description provided.