Scripts: harden coverage_gate CLI argument validation and error paths #2099

Open
github-bot wants to merge 1 commit from github-bot/gh-2099 into main AGit
Owner

@⁠heditrigui on GitHub · 2026-11-25 03:59 UTC · original
heditrigui:scripts/coverage-gate-cli-hardening → main · +131 −4 · 2 files · 1 commits · open

Summary

Hardens CLI argument handling and validation in scripts/coverage_gate.py and expands test coverage in scripts/test_coverage_gate.py:

  • Validates --run-json path exists before reading; handles missing files, malformed JSON, and missing "stages" mapping cleanly (reporting error diagnostic on stderr and exiting code 2) instead of raising unhandled Python exceptions.
  • Validates --xcl binary and --rpf archive exist before executing subprocess; handles missing files and process spawn errors cleanly with exit code 2.
  • Validates --baseline JSON syntax and "stages" structure when comparing; reports clean error diagnostic on stderr and exits code 2 if invalid.
  • Expands scripts/test_coverage_gate.py from 9 to 22 tests covering CLI error handling (missing args, missing files, corrupt JSON, invalid schema mappings), baseline updates, pass status (code 0), and detected regressions (code 1).

Tested

  • python scripts/test_coverage_gate.py (22 passed in 0.18s).
  • python -m pytest scripts/ (38 passed in 0.66s).
  • Validated with scripts/pr_check.py --local.

Not tested

  • Retail game smoke execution (scripts/ tools are non-runtime code).

AI use

  • Antigravity (Gemini 3.8 Flash (High))
**@⁠heditrigui** on GitHub · 2026-11-25 03:59 UTC · [original](https://github.com/xcl-dev/xcl/pull/2099) `heditrigui:scripts/coverage-gate-cli-hardening` → `main` · +131 −4 · 2 files · 1 commits · open ### Summary Hardens CLI argument handling and validation in `scripts/coverage_gate.py` and expands test coverage in `scripts/test_coverage_gate.py`: - Validates `--run-json` path exists before reading; handles missing files, malformed JSON, and missing `"stages"` mapping cleanly (reporting error diagnostic on stderr and exiting code 2) instead of raising unhandled Python exceptions. - Validates `--xcl` binary and `--rpf` archive exist before executing subprocess; handles missing files and process spawn errors cleanly with exit code 2. - Validates `--baseline` JSON syntax and `"stages"` structure when comparing; reports clean error diagnostic on stderr and exits code 2 if invalid. - Expands `scripts/test_coverage_gate.py` from 9 to 22 tests covering CLI error handling (missing args, missing files, corrupt JSON, invalid schema mappings), baseline updates, pass status (code 0), and detected regressions (code 1). **Tested** - `python scripts/test_coverage_gate.py` (22 passed in 0.18s). - `python -m pytest scripts/` (38 passed in 0.66s). - Validated with `scripts/pr_check.py --local`. **Not tested** - Retail game smoke execution (`scripts/` tools are non-runtime code). **AI use** - Antigravity (Gemini 3.8 Flash (High))
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:18:43 +00:00
Author
Owner

@⁠JJAutoCompare on GitHub · 2026-11-25 04:12 UTC · original

22 passed, 0 failed, 0 ignored, 0 skipped in 0.084 seconds on STOR-WINLAB. I verified that PR #2099 was open at c52af79a0e80eaf3d94491ebc7342ebc9b8df424 before and after the run. The assigned checkout was clean and detached. The visible PR discussion contained no independent test report.

Tested. Windows 11 Enterprise Evaluation x64 build 26200, AMD Ryzen 7 3800X, portable CPython 3.13.7 AMD64 (MSC v.1944). The direct command & 'L:/XclTooling/pr1999-coverage-52a120f7/portable/python.exe' -B scripts/test_coverage_gate.py -v exited 1 before running any tests because the interpreter’s python313._pth excluded the script directory. The same interpreter ran the unchanged fixture successfully with a process-local import path, private TEMP and TMP, and PYTHONDONTWRITEBYTECODE=1.

& 'L:/XclTooling/pr1999-coverage-52a120f7/portable/python.exe' -B -c "import pathlib, runpy, sys; sys.path.insert(0, str(pathlib.Path('scripts').resolve())); runpy.run_path('scripts/test_coverage_gate.py', run_name='__main__')" -v

The CLI fixtures returned 2 for missing required arguments or files, malformed JSON, and missing stages mappings. A matching baseline returned 0, a translation regression returned 1, and --update returned 0 and created a baseline in a new subdirectory with the expected stage counts.

Not tested. Real XCL subprocess execution, shader packs, GPU, Cargo/workspace tests, smoke runs, and other Python suites.

AI use. T3 Code / Codex (gpt-6.2-sol) ran the fixtures and wrote the report.

**@⁠JJAutoCompare** on GitHub · 2026-11-25 04:12 UTC · [original](https://github.com/xcl-dev/xcl/pull/2099#issuecomment-7152627620) **22 passed, 0 failed, 0 ignored, 0 skipped** in 0.084 seconds on STOR-WINLAB. I verified that [PR #2099](https://git.gtahub.st/github/xcl-dev--xcl/pulls/2099) was open at `c52af79a0e80eaf3d94491ebc7342ebc9b8df424` before and after the run. The assigned checkout was clean and detached. The visible PR discussion contained no independent test report. **Tested.** Windows 11 Enterprise Evaluation x64 build 26200, AMD Ryzen 7 3800X, portable CPython 3.13.7 AMD64 (MSC v.1944). The direct command `& 'L:/XclTooling/pr1999-coverage-52a120f7/portable/python.exe' -B scripts/test_coverage_gate.py -v` exited 1 before running any tests because the interpreter’s `python313._pth` excluded the script directory. The same interpreter ran the unchanged fixture successfully with a process-local import path, private `TEMP` and `TMP`, and `PYTHONDONTWRITEBYTECODE=1`. ```powershell & 'L:/XclTooling/pr1999-coverage-52a120f7/portable/python.exe' -B -c "import pathlib, runpy, sys; sys.path.insert(0, str(pathlib.Path('scripts').resolve())); runpy.run_path('scripts/test_coverage_gate.py', run_name='__main__')" -v ``` The CLI fixtures returned `2` for missing required arguments or files, malformed JSON, and missing `stages` mappings. A matching baseline returned `0`, a translation regression returned `1`, and `--update` returned `0` and created a baseline in a new subdirectory with the expected stage counts. **Not tested.** Real XCL subprocess execution, shader packs, GPU, Cargo/workspace tests, smoke runs, and other Python suites. **AI use.** T3 Code / Codex (`gpt-6.2-sol`) ran the fixtures and wrote the report.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 05:43 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-25 05:43 UTC · [original](https://github.com/xcl-dev/xcl/pull/2099#issuecomment-7154082943) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
Author
Owner

@⁠raylitebull on GitHub · 2026-11-25 11:03 UTC · original

Code review on c52af79 (scripts/coverage_gate.py, scripts/test_coverage_gate.py):

  • Cleanly validates missing/malformed --run-json and --baseline files (JSONDecodeError, OSError, missing stages dict), missing --xcl/--rpf paths, and OSError on spawn, exiting 2 consistently; both CI checks are green and @JJAutoCompare verified 22 passed, 0 failed on c52af79.

Remaining before merge: One additional independent verification of scripts/test_coverage_gate.py on c52af79 (--lib runs do not exercise the Python script tests).

**@⁠raylitebull** on GitHub · 2026-11-25 11:03 UTC · [original](https://github.com/xcl-dev/xcl/pull/2099#issuecomment-7160527670) Code review on `c52af79` (`scripts/coverage_gate.py`, `scripts/test_coverage_gate.py`): - Cleanly validates missing/malformed `--run-json` and `--baseline` files (`JSONDecodeError`, `OSError`, missing `stages` dict), missing `--xcl`/`--rpf` paths, and `OSError` on spawn, exiting `2` consistently; both CI checks are green and `@JJAutoCompare` verified `22 passed, 0 failed` on `c52af79`. **Remaining before merge:** One additional independent verification of `scripts/test_coverage_gate.py` on `c52af79` (`--lib` runs do not exercise the Python script tests).
Author
Owner

@⁠ettehn on GitHub · 2026-11-25 11:04 UTC · original

Independent Windows check on exact c52af79: all 22 test_coverage_gate.py tests passed. I also reproduced two inherited cases with only temporary baseline copies.

  • A saved report with {"stages":{}} is rejected against the committed baseline (exit 1), but --run-json empty.json --update --baseline <copy> exits 0 and replaces that copy with an empty baseline. The next comparison of the same report exits 0 and prints coverage gate: no regressions. A live call with an empty synthetic 9FPR pack also reproduced the replacement.
  • A report with {"stages":{"CS":{"translated":1636}}} reaches compare() and raises KeyError: validator_failed instead of getting a clean invalid-report diagnostic.

The empty-update behavior also reproduces on main. A follow-up could reject an empty baseline or sweep before update or comparison, and verify each stage has the counters the gate reads. No shipped baseline was touched.

AI use — OpenAI Codex (GPT-6.2 Sol) ran the checks and wrote this report.

**@⁠ettehn** on GitHub · 2026-11-25 11:04 UTC · [original](https://github.com/xcl-dev/xcl/pull/2099#issuecomment-7160547411) Independent Windows check on exact `c52af79`: all 22 `test_coverage_gate.py` tests passed. I also reproduced two inherited cases with only temporary baseline copies. - A saved report with `{"stages":{}}` is rejected against the committed baseline (exit 1), but `--run-json empty.json --update --baseline <copy>` exits 0 and replaces that copy with an empty baseline. The next comparison of the same report exits 0 and prints `coverage gate: no regressions`. A live call with an empty synthetic `9FPR` pack also reproduced the replacement. - A report with `{"stages":{"CS":{"translated":1636}}}` reaches `compare()` and raises `KeyError: validator_failed` instead of getting a clean invalid-report diagnostic. The empty-update behavior also reproduces on `main`. A follow-up could reject an empty baseline or sweep before update or comparison, and verify each stage has the counters the gate reads. No shipped baseline was touched. AI use — OpenAI Codex (GPT-6.2 Sol) ran the checks and wrote this report.
Author
Owner

@⁠ettehn on GitHub · 2026-11-25 11:10 UTC · original

I put the report-validation follow-up on a single commit directly on c52af79, in case you want to cherry-pick it.

On Windows, the Python script suite passed 40/40. The temporary-baseline CLI checks reject an empty saved report, an empty live synthetic pack and a missing counter, all with exit 2 and the baseline bytes preserved. The saved validated 22,445-program report still passes.

AI use — OpenAI Codex (GPT-6.2 Sol) prepared the follow-up and ran the checks.

**@⁠ettehn** on GitHub · 2026-11-25 11:10 UTC · [original](https://github.com/xcl-dev/xcl/pull/2099#issuecomment-7160693263) I put the report-validation follow-up on [a single commit](https://github.com/ettehn/xcl/commit/1a079ab588075254376d5e2e4eee5598d46e5e9f) directly on `c52af79`, in case you want to cherry-pick it. On Windows, the Python script suite passed 40/40. The temporary-baseline CLI checks reject an empty saved report, an empty live synthetic pack and a missing counter, all with exit 2 and the baseline bytes preserved. The saved validated 22,445-program report still passes. AI use — OpenAI Codex (GPT-6.2 Sol) prepared the follow-up and ran the checks.
Author
Owner

@⁠RavenCurseBurg on GitHub · 2026-11-25 18:35 UTC · original · edited 2026-11-26 10:39 UTC

Independently compared this head c52af79a0e80eaf3d94491ebc7342ebc9b8df424 with @⁠ettehn's follow-up on Windows 11 build 26100.9711, i7-13700, Python 3.14.3.

I ran python scripts/coverage_gate.py --run-json <run.json> --baseline <temporary copy> and its --update form. The eight invalid inputs included an empty stage map, all-zero totals, a missing counter and five invalid values distributed over the second stage's counters (boolean, string, negative integer, fraction and null). For each input I tried comparison, update, and comparison with the invalid data on the baseline side.

  • The PR head wrote a new baseline for all eight invalid updates.
  • On 1a079ab, all 24 invalid cases exited 2 with a diagnostic and preserved the baseline byte-for-byte. Three controls passed on both revisions: a valid comparison, a valid update retaining the supplied counts, and a real decrease in translations returning 1.
  • python -B -m unittest discover -s scripts -p "test_*.py" passed all 40 tests on the follow-up in a writable temporary environment.

Only saved synthetic reports and temporary baseline copies were used. No shader compilation, retail pack or GPU workload. OpenAI Codex (GPT-6) ran these checks and wrote the report.

Follow-up on the review at c52af79a0e80. Tested candidate b24d26580. I ran the real coverage-gate CLI with a dummy pack and a uniquely named executable in a temporary PATH directory outside its working directory. This head returned 2 before launching it. The candidate returned 0 and wrote exactly the supplied stage counts. The existing missing-executable and missing-pack tests still passed. All 39 script tests passed.

Command on the candidate: python -B -m unittest discover -s scripts -p "test_*.py". Windows 11 build 26100, Core i7-13700, Python 3.14.3. OpenAI Codex (GPT-6) prepared the patch and ran the tests with synthetic inputs. I did not run the full Rust/GPU suite.

**@⁠RavenCurseBurg** on GitHub · 2026-11-25 18:35 UTC · [original](https://github.com/xcl-dev/xcl/pull/2099#issuecomment-7171131428) · edited 2026-11-26 10:39 UTC Independently compared this head `c52af79a0e80eaf3d94491ebc7342ebc9b8df424` with [@⁠ettehn's follow-up](https://github.com/ettehn/xcl/commit/1a079ab588075254376d5e2e4eee5598d46e5e9f) on Windows 11 build 26100.9711, i7-13700, Python 3.14.3. I ran `python scripts/coverage_gate.py --run-json <run.json> --baseline <temporary copy>` and its `--update` form. The eight invalid inputs included an empty stage map, all-zero totals, a missing counter and five invalid values distributed over the second stage's counters (boolean, string, negative integer, fraction and null). For each input I tried comparison, update, and comparison with the invalid data on the baseline side. - The PR head wrote a new baseline for all eight invalid updates. - On `1a079ab`, all 24 invalid cases exited 2 with a diagnostic and preserved the baseline byte-for-byte. Three controls passed on both revisions: a valid comparison, a valid update retaining the supplied counts, and a real decrease in translations returning 1. - `python -B -m unittest discover -s scripts -p "test_*.py"` passed all 40 tests on the follow-up in a writable temporary environment. Only saved synthetic reports and temporary baseline copies were used. No shader compilation, retail pack or GPU workload. OpenAI Codex (GPT-6) ran these checks and wrote the report. Follow-up on [the review](https://git.gtahub.st/github/xcl-dev--xcl/pulls/2099) at `c52af79a0e80`. [Tested candidate b24d26580](https://github.com/RavenCurseBurg/xcl/commit/b24d26580867efae5ca8ceb10d284b3609b51cb7). I ran the real coverage-gate CLI with a dummy pack and a uniquely named executable in a temporary PATH directory outside its working directory. This head returned 2 before launching it. The candidate returned 0 and wrote exactly the supplied stage counts. The existing missing-executable and missing-pack tests still passed. All 39 script tests passed. Command on the candidate: `python -B -m unittest discover -s scripts -p "test_*.py"`. Windows 11 build 26100, Core i7-13700, Python 3.14.3. OpenAI Codex (GPT-6) prepared the patch and ran the tests with synthetic inputs. I did not run the full Rust/GPU suite.
Author
Owner

@⁠luckyteagirl on GitHub · 2026-11-26 09:52 UTC · original · reviewed

On c52af79, the new args.xcl.is_file() check rejects a bare executable name that the OS can find on PATH, before subprocess.run gets a chance to resolve it. I reproduced this with fake-xcl.cmd placed only on the child process's PATH (outside its cwd), an existing dummy pack, and --update: current main exited 0, while this head exited 2 with xcl binary not found. Supplying the same stand-in by absolute path worked on both. This changes an already supported way to invoke the coverage gate.

Could the executable be left to subprocess.run (the new OSError handler already diagnoses a genuine launch failure), or resolve bare names through shutil.which while retaining explicit-path checks? A regression fixture with the stand-in only on PATH would cover it. This was a CPU-only exact-head CLI comparison; I did not run a shader sweep or GPU test.

**@⁠luckyteagirl** on GitHub · 2026-11-26 09:52 UTC · [original](https://github.com/xcl-dev/xcl/pull/2099#pullrequestreview-6071896926) · **reviewed** On `c52af79`, the new `args.xcl.is_file()` check rejects a bare executable name that the OS can find on `PATH`, before `subprocess.run` gets a chance to resolve it. I reproduced this with `fake-xcl.cmd` placed only on the child process's `PATH` (outside its cwd), an existing dummy pack, and `--update`: current main exited 0, while this head exited 2 with `xcl binary not found`. Supplying the same stand-in by absolute path worked on both. This changes an already supported way to invoke the coverage gate. Could the executable be left to `subprocess.run` (the new `OSError` handler already diagnoses a genuine launch failure), or resolve bare names through `shutil.which` while retaining explicit-path checks? A regression fixture with the stand-in only on `PATH` would cover it. This was a CPU-only exact-head CLI comparison; I did not run a shader sweep or GPU test.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2099/head:github-bot/gh-2099'
git switch 'github-bot/gh-2099'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2099'
git switch 'github-bot/gh-2099'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2099'
git switch 'github-bot/gh-2099'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2099'
git switch 'main'
git merge --squash 'github-bot/gh-2099'
git switch 'main'
git merge --ff-only 'github-bot/gh-2099'
git switch 'main'
git merge 'github-bot/gh-2099'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.