tools/cf_diff: validate CLI args, isolate SPIRV_VAL state, and enforce UTF-8 subprocess decoding #1859

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

@⁠kirigayakazima on GitHub · 2026-11-25 13:20 UTC · original
kirigayakazima:fix/cf-diff-safety → main · +154 −44 · 2 files · 1 commits · open

Claimed in the coordination issue as: CF-DIFF-CLI-VALIDATION-STATE-ISOLATION-AND-ENCODING (#1608)

What and why

  • Reject --minimize without --program, negative --program, and negative --depth via ap.error(...) in tools/cf_diff.py:main().
  • Emit missing --spirv-val tool errors (spirv-as / spirv-val) to sys.stderr instead of stdout, returning 2 before mutating module-global SPIRV_VAL.
  • Isolate SPIRV_VAL updates inside try ... finally: SPIRV_VAL = prev_spirv_val in main() so in-process callers cannot leak SPIRV_VAL = True after normal return or exceptions.
  • Pass encoding="utf-8", errors="replace" to subprocess.run in _spirv_val() to avoid platform code-page decode failures on tool output.
  • Add stdlib unittest CLI and encoding regression coverage in tests/test_cf_diff_cli.py.

Tested

  • Patched: python -I tests/test_cf_diff_cli.py -v -> Ran 4 tests in 0.007s (OK).
  • Baseline check (upstream/main 98c2f777 with tests/test_cf_diff_cli.py copied into detached worktree): Ran 4 tests in 10.120s (FAILED (failures=6) across all subtests and cases).
  • Repo gates: python -I tests/test_ci_registration.py (Ran 16 tests in 5.521s, OK), python -I tests/test_text_write_line_endings.py (Ran 3 tests in 13.010s, OK), python -I scripts/check_no_game_data.py (exit 0), python -I -m compileall -q (exit 0), git diff --check (exit 0).

GPUs tested: n/a (CLI validation, state isolation, and mocked subprocess unittest suite)

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.
**@⁠kirigayakazima** on GitHub · 2026-11-25 13:20 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1859) `kirigayakazima:fix/cf-diff-safety` → `main` · +154 −44 · 2 files · 1 commits · open Claimed in the coordination issue as: CF-DIFF-CLI-VALIDATION-STATE-ISOLATION-AND-ENCODING (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### What and why - Reject `--minimize` without `--program`, negative `--program`, and negative `--depth` via `ap.error(...)` in `tools/cf_diff.py:main()`. - Emit missing `--spirv-val` tool errors (`spirv-as` / `spirv-val`) to `sys.stderr` instead of `stdout`, returning `2` before mutating module-global `SPIRV_VAL`. - Isolate `SPIRV_VAL` updates inside `try ... finally: SPIRV_VAL = prev_spirv_val` in `main()` so in-process callers cannot leak `SPIRV_VAL = True` after normal return or exceptions. - Pass `encoding="utf-8", errors="replace"` to `subprocess.run` in `_spirv_val()` to avoid platform code-page decode failures on tool output. - Add stdlib `unittest` CLI and encoding regression coverage in `tests/test_cf_diff_cli.py`. ### Tested - Patched: `python -I tests/test_cf_diff_cli.py -v` -> `Ran 4 tests in 0.007s` (`OK`). - Baseline check (`upstream/main` `98c2f777` with `tests/test_cf_diff_cli.py` copied into detached worktree): `Ran 4 tests in 10.120s` (`FAILED (failures=6)` across all subtests and cases). - Repo gates: `python -I tests/test_ci_registration.py` (`Ran 16 tests in 5.521s`, `OK`), `python -I tests/test_text_write_line_endings.py` (`Ran 3 tests in 13.010s`, `OK`), `python -I scripts/check_no_game_data.py` (exit 0), `python -I -m compileall -q` (exit 0), `git diff --check` (exit 0). GPUs tested: n/a (CLI validation, state isolation, and mocked subprocess unittest suite) AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:08:57 +00:00
Author
Owner

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

Tested 7fd52fa61 on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against main 71a769d7d (Python GPU diff tool; no campaign run):

  • pytest 9.2.0 on tests/test_cf_diff_cli.py: 4 passed, 3 subtests passed at this head.
  • The same file on main: 6 failed, 1 passed — the CLI argument guards, the SPIRV_VAL state isolation and the UTF-8 subprocess encoding are the new coverage.
  • Not run: an actual cf_diff campaign on the GPU; the tests mock the tools.

AI-assisted; synthetic fixtures only, no game data.

**@⁠GeorgiyDemo** on GitHub · 2026-11-25 14:03 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1859#issuecomment-7164695541) Tested `7fd52fa61` on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against `main` `71a769d7d` (Python GPU diff tool; no campaign run): - pytest 9.2.0 on `tests/test_cf_diff_cli.py`: **4 passed, 3 subtests passed** at this head. - The same file on `main`: **6 failed**, 1 passed — the CLI argument guards, the `SPIRV_VAL` state isolation and the UTF-8 subprocess encoding are the new coverage. - Not run: an actual `cf_diff` campaign on the GPU; the tests mock the tools. AI-assisted; synthetic fixtures only, no game data.
Author
Owner

@⁠DeadlyChirp on GitHub · 2026-11-25 15:32 UTC · original

Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main.

python -m pytest -q tests/test_cf_diff_cli.py:

  • PR: 4 passed, 3 subtests passed.
  • The new test file run against main's tools/cf_diff.py: 6 failed, 1 passed. So the tests catch the problem, and the tool change fixes it on Windows.

(AI-assisted test run; output checked by hand.)

**@⁠DeadlyChirp** on GitHub · 2026-11-25 15:32 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1859#issuecomment-7166996246) Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main. `python -m pytest -q tests/test_cf_diff_cli.py`: - PR: 4 passed, 3 subtests passed. - The new test file run against main's `tools/cf_diff.py`: 6 failed, 1 passed. So the tests catch the problem, and the tool change fixes it on Windows. (AI-assisted test run; output checked by hand.)
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/1859/head:github-bot/gh-1859'
git switch 'github-bot/gh-1859'

Merge

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