shader: harden rdna_cvt_pk_u8 CLI validation and atomic writes with CLI suite #2611

Merged
Ammmae0x merged 1 commit from upstream-pr/2619 into main 2026-11-25 23:34:50 +00:00
Ammmae0x commented 2026-11-25 23:28:17 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-25T23:28:17Z.


Change

Harden CLI argument/path validation, atomic output writes, and temporary workdir cleanup in tools/rdna_cvt_pk_u8.py, and add a pure-Python CLI test suite in tests/rdna_cvt_pk_u8_cli_check.py registered in CMakeLists.txt (shader_rdna_cvt_pk_u8_cli_check, TIMEOUT 60).

  • Change main() to main(argv=None) -> int using ap.parse_args(argv) and replace sys.exit('error: --asm-only needs --arch') with stderr + return 2.
  • Validate upfront in _validate_args() and _validate_output_path(): --show >= 0, --keep non-empty and not an existing non-directory/broken symlink/file-parent, --compare not a directory, --out/--json non-empty and not a trailing-slash path/symlink/directory/non-regular file/file-parent, and reject path collisions (exact, resolved alias, or hardlink samefile()) across --out, --json, --compare, and --keep.
  • Replace direct file writes for --out and --json with sibling-temp _write_atomic() leaving zero .tmp leftovers on failure, clean up auto-created temporary workdirs in finally, and catch (OSError, ValueError, json.JSONDecodeError) with clean stderr + exit 1 and zero tracebacks.

Verification

Commit: 483897b0 (rebased on upstream/main 66026a39) on Windows with out\pe-env\Scripts\python.exe -B:

  • out\pe-env\Scripts\python.exe -B tools\rdna_cvt_pk_u8.py --self-test -> exit 0 (self-test OK)
  • out\pe-env\Scripts\python.exe -B -m unittest -v tests\rdna_cvt_pk_u8_cli_check.py -> exit 0 (Ran 9 tests ... OK)
  • out\pe-env\Scripts\python.exe -B tests\startup_gfx2hlsl_cvt_pk_u8_check.py -> exit 0 (all measured/model/translation/refusal controls OK)
  • out\pe-env\Scripts\python.exe -B tests\form_coverage_check.py -> exit 0 (form coverage checks passed)
  • out\pe-env\Scripts\python.exe -B tests\docs_links_check.py -> exit 0 (Checked 19 Markdown files and 506 links.)
  • out\pe-env\Scripts\python.exe -B tests\bidi_controls_check.py -> exit 0 (Checked 1851 tracked source, script and build/CI files: no bidirectional controls.)
  • Spot-mutation check on tools/rdna_cvt_pk_u8.py (--show < 0, output symlink guard, samefile guard, --out/--compare collision guard, temp cleanup in _write_atomic): 5/5 killed by tests/rdna_cvt_pk_u8_cli_check.py.

Evidence and follow-up

tests/rdna_cvt_pk_u8_cli_check.py is pure-Python (MIT License), mocking Hip and build against the existing public fixture tests/data/rdna_cvt_pk_u8_measured.tsv (5432 rows) without requiring a GPU or ROCm toolchain.

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:6615891951 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2619). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-25T23:28:17Z. --- ## Change Harden CLI argument/path validation, atomic output writes, and temporary workdir cleanup in `tools/rdna_cvt_pk_u8.py`, and add a pure-Python CLI test suite in `tests/rdna_cvt_pk_u8_cli_check.py` registered in `CMakeLists.txt` (`shader_rdna_cvt_pk_u8_cli_check`, `TIMEOUT 60`). - Change `main()` to `main(argv=None) -> int` using `ap.parse_args(argv)` and replace `sys.exit('error: --asm-only needs --arch')` with stderr + `return 2`. - Validate upfront in `_validate_args()` and `_validate_output_path()`: `--show >= 0`, `--keep` non-empty and not an existing non-directory/broken symlink/file-parent, `--compare` not a directory, `--out`/`--json` non-empty and not a trailing-slash path/symlink/directory/non-regular file/file-parent, and reject path collisions (exact, resolved alias, or hardlink `samefile()`) across `--out`, `--json`, `--compare`, and `--keep`. - Replace direct file writes for `--out` and `--json` with sibling-temp `_write_atomic()` leaving zero `.tmp` leftovers on failure, clean up auto-created temporary workdirs in `finally`, and catch `(OSError, ValueError, json.JSONDecodeError)` with clean stderr + exit 1 and zero tracebacks. ## Verification Commit: `483897b0` (rebased on `upstream/main` `66026a39`) on Windows with `out\pe-env\Scripts\python.exe -B`: - `out\pe-env\Scripts\python.exe -B tools\rdna_cvt_pk_u8.py --self-test` -> exit 0 (`self-test OK`) - `out\pe-env\Scripts\python.exe -B -m unittest -v tests\rdna_cvt_pk_u8_cli_check.py` -> exit 0 (`Ran 9 tests ... OK`) - `out\pe-env\Scripts\python.exe -B tests\startup_gfx2hlsl_cvt_pk_u8_check.py` -> exit 0 (all measured/model/translation/refusal controls OK) - `out\pe-env\Scripts\python.exe -B tests\form_coverage_check.py` -> exit 0 (`form coverage checks passed`) - `out\pe-env\Scripts\python.exe -B tests\docs_links_check.py` -> exit 0 (`Checked 19 Markdown files and 506 links.`) - `out\pe-env\Scripts\python.exe -B tests\bidi_controls_check.py` -> exit 0 (`Checked 1851 tracked source, script and build/CI files: no bidirectional controls.`) - Spot-mutation check on `tools/rdna_cvt_pk_u8.py` (`--show < 0`, output symlink guard, `samefile` guard, `--out`/`--compare` collision guard, temp cleanup in `_write_atomic`): 5/5 killed by `tests/rdna_cvt_pk_u8_cli_check.py`. ## Evidence and follow-up `tests/rdna_cvt_pk_u8_cli_check.py` is pure-Python (MIT License), mocking `Hip` and `build` against the existing public fixture `tests/data/rdna_cvt_pk_u8_measured.tsv` (5432 rows) without requiring a GPU or ROCm toolchain. ## 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 00:01:01 +00:00
tedin7 commented 2026-11-26 00:01:01 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T23:32:18Z.

Review: COMMENTED


Review of head 483897b0 (comment only, no approval).

Scope: tools/rdna_cvt_pk_u8.py CLI validation, atomic writes, temp workdir cleanup; new tests/rdna_cvt_pk_u8_cli_check.py (9 cases) registered in CMakeLists.txt. No other open or merged PR covers this slice (#2467 changed the lowering, not this CLI).

Findings: none blocking. The path collision check (exact, resolved alias, hardlink), the symlink/directory guards and the sibling-temp write all have a test that fails when they are broken.

Commands run locally on this head:

  • python3 tests/rdna_cvt_pk_u8_cli_check.py -> 9 tests OK
  • python3 tests/docs_links_check.py -> OK
  • python3 tests/bidi_controls_check.py -> OK
  • git diff --check origin/main...HEAD -> clean
  • Mutation 1: _same_path returns False instead of the samefile check -> 3 failures (test caught it)
  • Mutation 2: _write_atomic no longer removes its temp file on failure -> 1 failure, 2 errors (test caught it)

Not covered by this review: a Windows run (a Win2025 receipt follows separately).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6066453033 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2619#pullrequestreview-6066453033). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T23:32:18Z. **Review:** COMMENTED --- Review of head 483897b0 (comment only, no approval). Scope: tools/rdna_cvt_pk_u8.py CLI validation, atomic writes, temp workdir cleanup; new tests/rdna_cvt_pk_u8_cli_check.py (9 cases) registered in CMakeLists.txt. No other open or merged PR covers this slice (#2467 changed the lowering, not this CLI). Findings: none blocking. The path collision check (exact, resolved alias, hardlink), the symlink/directory guards and the sibling-temp write all have a test that fails when they are broken. Commands run locally on this head: - python3 tests/rdna_cvt_pk_u8_cli_check.py -> 9 tests OK - python3 tests/docs_links_check.py -> OK - python3 tests/bidi_controls_check.py -> OK - git diff --check origin/main...HEAD -> clean - Mutation 1: _same_path returns False instead of the samefile check -> 3 failures (test caught it) - Mutation 2: _write_atomic no longer removes its temp file on failure -> 1 failure, 2 errors (test caught it) Not covered by this review: a Windows run (a Win2025 receipt follows separately). AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-26 00:01:12 +00:00 (Migrated from github.com)

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


Win2025 WARP receipt for head 483897b0 (regex forced to the PR's new test).

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

  • Debug (--preset dev):
    • Build (cmake --build --preset dev -- -j 2): 17.65s (configure 3.70s)
    • Test (ctest --preset dev -R 'shader_rdna_cvt_pk_u8_cli_check' --parallel 2 --no-tests=error --output-on-failure): 1/1 passed (7.88s: shader_rdna_cvt_pk_u8_cli_check 7.63s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release -- -j 2): 41.70s (configure 4.62s)
    • Test (ctest --preset release -R 'shader_rdna_cvt_pk_u8_cli_check' --parallel 2 --no-tests=error --output-on-failure): 1/1 passed (7.55s: shader_rdna_cvt_pk_u8_cli_check 7.32s)
  • sccache: 24/42 hits; wall 87.1s

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7177745282 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2619#issuecomment-7177745282). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T23:34:12Z. --- Win2025 WARP receipt for head 483897b0 (regex forced to the PR's new test). Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `483897b0cb8937b50fa7dee27089c912eaa6a59d`: - **Debug (`--preset dev`)**: - Build (`cmake --build --preset dev -- -j 2`): `17.65s` (configure `3.70s`) - Test (`ctest --preset dev -R 'shader_rdna_cvt_pk_u8_cli_check' --parallel 2 --no-tests=error --output-on-failure`): **1/1 passed** (`7.88s`: `shader_rdna_cvt_pk_u8_cli_check` `7.63s`) - **Release `/O2` (`--preset release`)**: - Build (`cmake --build --preset release -- -j 2`): `41.70s` (configure `4.62s`) - Test (`ctest --preset release -R 'shader_rdna_cvt_pk_u8_cli_check' --parallel 2 --no-tests=error --output-on-failure`): **1/1 passed** (`7.55s`: `shader_rdna_cvt_pk_u8_cli_check` `7.32s`) - `sccache`: 24/42 hits; wall `87.1s` 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!2611
No description provided.