shader: extract main(argv), atomic output writes, and error guards in mesh_entry_aot with CLI suite #2386

Merged
Ammmae0x merged 3 commits from upstream-pr/2394 into main 2026-11-25 18:50:36 +00:00
Ammmae0x commented 2026-11-25 15:08:20 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-25T15:08:20Z.


Change

Harden tools/mesh_entry_aot.py for programmatic and CLI execution while preserving its HLSL translation behavior and CLI arguments:

  • Extract the inline __main__ block into main(argv=None) -> int forwarding argv to p.parse_args(argv).
  • Reject --output being an existing directory, lacking a .hlsl suffix, or colliding with container or --geometry-words via _same_path() (Path.resolve() equality and Path.samefile() for hardlinks/aliases).
  • Create parent directories and stage translated HLSL inside tempfile.TemporaryDirectory(dir=a.output.parent) before committing with os.replace() so write/replace failures leave no partial files or temp directories.
  • Catch (OSError, ValueError, KeyError, json.JSONDecodeError, struct.error, zlib.error) cleanly via p.exit(1, ...) without raw Python tracebacks.
  • Add standalone pure-Python suite tests/mesh_entry_aot_cli_check.py and register mesh_entry_aot_cli_check in CMakeLists.txt.

Verification

Verified on commit 79851e14 (rebased on upstream/main 0b31989c):

  • out/pe-env/Scripts/python.exe -B tests/mesh_entry_aot_cli_check.py -v -> Ran 7 tests in 3.284s - OK (exit 0)
  • out/pe-env/Scripts/python.exe -B tests/mesh_clip_cull_check.py -> passed (40 refusal checks + 7 guard-removal controls; exit 0)
  • out/pe-env/Scripts/python.exe -B tests/mesh_amplification_refusal_check.py -> mesh stage accepted; amplification and compute stages refused by name (exit 0)
  • out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py -> form coverage checks passed (exit 0)
  • out/pe-env/Scripts/python.exe -B tests/docs_links_check.py -> Self-test passed. Checked 19 Markdown files and 464 links. (exit 0)
  • out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py -> Self-test passed. Checked 1719 tracked source, script and build/CI files: no bidirectional controls. (exit 0)

Spot mutation checks against tools/mesh_entry_aot.py (9/9 killed by tests/mesh_entry_aot_cli_check.py, restored cleanly):

  • Drop argv forwarding, bypass existing-directory check, bypass .hlsl suffix check, bypass resolve() collision check, bypass samefile() collision check, bypass TemporaryDirectory + os.replace() staging, and individually drop struct.error, KeyError, and zlib.error handlers (all returned exit 1).

Evidence and follow-up

  • Uses synthetic in-memory DXBC fixtures (amplification-stage refusal) and mocked translate (MIT, repo-authored; no game files, dumps, binaries, or GPU/LLVM prerequisite).
  • Negative controls cover existing-directory --output, non-.hlsl suffix, path collisions with container and --geometry-words via .. alias and hardlink, missing inputs, invalid JSON, ValueError/KeyError/struct.error/zlib.error handling, and os.replace() / staging write failures leaving zero temp directories.

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:6607564085 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2394). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-25T15:08:20Z. --- ## Change Harden `tools/mesh_entry_aot.py` for programmatic and CLI execution while preserving its HLSL translation behavior and CLI arguments: - Extract the inline `__main__` block into `main(argv=None) -> int` forwarding `argv` to `p.parse_args(argv)`. - Reject `--output` being an existing directory, lacking a `.hlsl` suffix, or colliding with `container` or `--geometry-words` via `_same_path()` (`Path.resolve()` equality and `Path.samefile()` for hardlinks/aliases). - Create parent directories and stage translated HLSL inside `tempfile.TemporaryDirectory(dir=a.output.parent)` before committing with `os.replace()` so write/replace failures leave no partial files or temp directories. - Catch `(OSError, ValueError, KeyError, json.JSONDecodeError, struct.error, zlib.error)` cleanly via `p.exit(1, ...)` without raw Python tracebacks. - Add standalone pure-Python suite `tests/mesh_entry_aot_cli_check.py` and register `mesh_entry_aot_cli_check` in `CMakeLists.txt`. ## Verification Verified on commit `79851e14` (rebased on `upstream/main` `0b31989c`): - `out/pe-env/Scripts/python.exe -B tests/mesh_entry_aot_cli_check.py -v` -> `Ran 7 tests in 3.284s - OK` (exit 0) - `out/pe-env/Scripts/python.exe -B tests/mesh_clip_cull_check.py` -> passed (40 refusal checks + 7 guard-removal controls; exit 0) - `out/pe-env/Scripts/python.exe -B tests/mesh_amplification_refusal_check.py` -> `mesh stage accepted; amplification and compute stages refused by name` (exit 0) - `out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py` -> `form coverage checks passed` (exit 0) - `out/pe-env/Scripts/python.exe -B tests/docs_links_check.py` -> `Self-test passed. Checked 19 Markdown files and 464 links.` (exit 0) - `out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py` -> `Self-test passed. Checked 1719 tracked source, script and build/CI files: no bidirectional controls.` (exit 0) Spot mutation checks against `tools/mesh_entry_aot.py` (9/9 killed by `tests/mesh_entry_aot_cli_check.py`, restored cleanly): - Drop `argv` forwarding, bypass existing-directory check, bypass `.hlsl` suffix check, bypass `resolve()` collision check, bypass `samefile()` collision check, bypass `TemporaryDirectory` + `os.replace()` staging, and individually drop `struct.error`, `KeyError`, and `zlib.error` handlers (all returned exit 1). ## Evidence and follow-up - Uses synthetic in-memory DXBC fixtures (amplification-stage refusal) and mocked `translate` (MIT, repo-authored; no game files, dumps, binaries, or GPU/LLVM prerequisite). - Negative controls cover existing-directory `--output`, non-`.hlsl` suffix, path collisions with `container` and `--geometry-words` via `..` alias and hardlink, missing inputs, invalid JSON, `ValueError`/`KeyError`/`struct.error`/`zlib.error` handling, and `os.replace()` / staging write failures leaving zero temp directories. ## 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.
Ammmae0x commented 2026-11-25 16:05:23 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-25T15:25:50Z.


Fixed in 369be3e5:

  • tools/mesh_entry_aot.py: main() now formats guarded exception exits as f"{type(exc).__name__}: {exc}\n" (zero raw traceback), restoring the ValueError: ... prefix expected by tests/mesh_multi_check.py.
  • tests/mesh_entry_aot_cli_check.py: asserted the ValueError: / <ExcType>: prefix in both subprocess and unit refusal tests.

Verified in liaison after 369be3e5:

  • Spot-mutation dropping {type(exc).__name__}: prefix caught (mesh_entry_aot_cli_check.py exit 1).
  • tests/mesh_entry_aot_cli_check.py (7/7 OK), tests/mesh_multi_check.py, tests/mesh_amplification_refusal_check.py, tests/form_coverage_check.py, tests/docs_links_check.py, and tests/bidi_controls_check.py: all exit 0.
  • ctest --preset dev -R "^mesh_entry_aot_cli_check$" and ctest --preset release -R "^mesh_entry_aot_cli_check$": 1/1 passed (7/7 OK) on both.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7166829602 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2394#issuecomment-7166829602). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-25T15:25:50Z. --- Fixed in `369be3e5`: - `tools/mesh_entry_aot.py`: `main()` now formats guarded exception exits as `f"{type(exc).__name__}: {exc}\n"` (zero raw traceback), restoring the `ValueError: ...` prefix expected by `tests/mesh_multi_check.py`. - `tests/mesh_entry_aot_cli_check.py`: asserted the `ValueError:` / `<ExcType>:` prefix in both subprocess and unit refusal tests. Verified in `liaison` after `369be3e5`: - Spot-mutation dropping `{type(exc).__name__}:` prefix caught (`mesh_entry_aot_cli_check.py` exit 1). - `tests/mesh_entry_aot_cli_check.py` (7/7 OK), `tests/mesh_multi_check.py`, `tests/mesh_amplification_refusal_check.py`, `tests/form_coverage_check.py`, `tests/docs_links_check.py`, and `tests/bidi_controls_check.py`: all exit 0. - `ctest --preset dev -R "^mesh_entry_aot_cli_check$"` and `ctest --preset release -R "^mesh_entry_aot_cli_check$"`: 1/1 passed (7/7 OK) on both. AI-assisted.
upstream-sync closed this pull request 2026-11-25 19:03:34 +00:00
tedin7 commented 2026-11-25 19:03:34 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T18:22:04Z.

Review: COMMENTED


Review of head 369be3e5 (Linux checks only; no Windows run by me, and I did not see author Windows results for this SHA).

Checked:

  • tools/mesh_entry_aot.py: main(argv) extraction, directory/suffix/same-path guards (_same_path also catches hardlinks), staged write + os.replace in the output directory, narrowed error handling that exits 1 with a one-line message. Logic reads correct.
  • Scope: 3 files, additive, no .github/launcher/hooks. No other open or merged PR touches this CLI wrapper (#2438 and #2444 change lowerers, not main).
  • CTest registration mesh_entry_aot_cli_check sits next to the sibling mesh checks.

Commands run:

  • python3 -B tests/mesh_entry_aot_cli_check.py -> 7 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: replaced os.replace(staged, a.output) with pass -> 3 failures
  • Mutation 2: disabled the same-path guard -> 2 failures, 2 errors
  • Both mutations reverted.

Minor, non-blocking notes:

  • Path-validation failures used to exit 2 via p.error; they now exit 1. Fine, just a behavior change for scripts that check the code.
  • CMakeLists.txt: the new add_test has no TIMEOUT property, unlike its neighbour mesh_amplification_refusal. Suggest adding one (e.g. 60).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6062805972 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2394#pullrequestreview-6062805972). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T18:22:04Z. **Review:** COMMENTED --- Review of head 369be3e5 (Linux checks only; no Windows run by me, and I did not see author Windows results for this SHA). Checked: - `tools/mesh_entry_aot.py`: `main(argv)` extraction, directory/suffix/same-path guards (`_same_path` also catches hardlinks), staged write + `os.replace` in the output directory, narrowed error handling that exits 1 with a one-line message. Logic reads correct. - Scope: 3 files, additive, no .github/launcher/hooks. No other open or merged PR touches this CLI wrapper (#2438 and #2444 change lowerers, not `main`). - CTest registration `mesh_entry_aot_cli_check` sits next to the sibling mesh checks. Commands run: - `python3 -B tests/mesh_entry_aot_cli_check.py` -> 7 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: replaced `os.replace(staged, a.output)` with `pass` -> 3 failures - Mutation 2: disabled the same-path guard -> 2 failures, 2 errors - Both mutations reverted. Minor, non-blocking notes: - Path-validation failures used to exit 2 via `p.error`; they now exit 1. Fine, just a behavior change for scripts that check the code. - `CMakeLists.txt`: the new `add_test` has no `TIMEOUT` property, unlike its neighbour `mesh_amplification_refusal`. Suggest adding one (e.g. 60). 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!2386
No description provided.