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

Open
opened 2026-11-26 21:19:15 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1859
Author: @kirigayakazima
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/cf-diff-safety


📝 Commits (1)

  • 7fd52fa Harden cf_diff CLI validation, SPIRV_VAL state isolation, and utf-8 encoding

📊 Changes

2 files changed (+154 additions, -44 deletions)

View changed files

➕ tests/test_cf_diff_cli.py (+100 -0)
📝 tools/cf_diff.py (+54 -44)

📄 Description

Claimed in the coordination issue as: CF-DIFF-CLI-VALIDATION-STATE-ISOLATION-AND-ENCODING (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7163606026)

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.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1859 **Author:** [@kirigayakazima](https://github.com/kirigayakazima) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/cf-diff-safety` --- ### 📝 Commits (1) - [`7fd52fa`](https://github.com/ubiquitarianism/leonida/commit/7fd52fa610b567be30c88cec30a8f2c324cdb39b) Harden cf_diff CLI validation, SPIRV_VAL state isolation, and utf-8 encoding ### 📊 Changes **2 files changed** (+154 additions, -44 deletions) <details> <summary>View changed files</summary> ➕ `tests/test_cf_diff_cli.py` (+100 -0) 📝 `tools/cf_diff.py` (+54 -44) </details> ### 📄 Description Claimed in the coordination issue as: CF-DIFF-CLI-VALIDATION-STATE-ISOLATION-AND-ENCODING (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7163606026) ### 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#1872
No description provided.