scripts/corpus_watch: strip BOM JSON, check --out/--game collisions, validate args, enforce UTF-8 #2256

Open
github-bot wants to merge 2 commits from github-bot/gh-2256 into main AGit
Owner

@⁠kirigayakazima on GitHub · 2026-11-26 10:43 UTC · original
kirigayakazima:fix/corpus-watch-safety → main · +175 −14 · 2 files · 2 commits · open

Claimed in the coordination issue as: CORPUS-WATCH-CLI-ENCODING-COLLISION-AND-BOM-SAFETY (#1608)

What and why

  • Read dxbc/index.json, spirv/index.json, and --results JSONL with encoding="utf-8-sig" in scripts/corpus_watch.py and validate parsed container root types (list/dict for carved index, dict for spirv/index.json).
  • Extend outputs_collide() (keeping 4-argument default compatibility) to check --out and --game alongside work, report, results, and log.
  • Update main(argv=None) to reject non-finite or negative --interval, non-positive --jobs, and directory/trailing-separator --results or --log paths via ap.error(...) before tool checks or running make_game.py.
  • Ensure parent directories for --results and --log are created once prerequisites pass, and pass encoding="utf-8", errors="replace" to both subprocess.run() invocations.
  • Expand tests/test_corpus_watch.py with tests covering BOM indexes, malformed roots, --out/--game collision checks, CLI argument validation, nested parent folder creation, and subprocess encoding.

Tested

  • Patched: python -I tests/test_corpus_watch.py -v -> Ran 7 tests in 0.149s (OK).
  • Baseline check (upstream/main a73a57e1 with updated tests/test_corpus_watch.py copied into detached worktree): Ran 7 tests in 0.101s (FAILED (errors=10)).
  • Repo gates: python -I tests/test_ci_registration.py (Ran 16 tests in 5.514s, OK), python -I tests/test_text_write_line_endings.py (Ran 3 tests in 13.118s, 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 (mocked subprocess calls and corpus-counting unit tests)

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-26 10:43 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2256) `kirigayakazima:fix/corpus-watch-safety` → `main` · +175 −14 · 2 files · 2 commits · open Claimed in the coordination issue as: CORPUS-WATCH-CLI-ENCODING-COLLISION-AND-BOM-SAFETY (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### What and why - Read `dxbc/index.json`, `spirv/index.json`, and `--results` JSONL with `encoding="utf-8-sig"` in `scripts/corpus_watch.py` and validate parsed container root types (`list`/`dict` for carved index, `dict` for `spirv/index.json`). - Extend `outputs_collide()` (keeping 4-argument default compatibility) to check `--out` and `--game` alongside `work`, `report`, `results`, and `log`. - Update `main(argv=None)` to reject non-finite or negative `--interval`, non-positive `--jobs`, and directory/trailing-separator `--results` or `--log` paths via `ap.error(...)` before tool checks or running `make_game.py`. - Ensure parent directories for `--results` and `--log` are created once prerequisites pass, and pass `encoding="utf-8", errors="replace"` to both `subprocess.run()` invocations. - Expand `tests/test_corpus_watch.py` with tests covering BOM indexes, malformed roots, `--out`/`--game` collision checks, CLI argument validation, nested parent folder creation, and subprocess encoding. ### Tested - Patched: `python -I tests/test_corpus_watch.py -v` -> `Ran 7 tests in 0.149s` (`OK`). - Baseline check (`upstream/main` `a73a57e1` with updated `tests/test_corpus_watch.py` copied into detached worktree): `Ran 7 tests in 0.101s` (`FAILED (errors=10)`). - Repo gates: `python -I tests/test_ci_registration.py` (`Ran 16 tests in 5.514s`, `OK`), `python -I tests/test_text_write_line_endings.py` (`Ran 3 tests in 13.118s`, `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 (mocked subprocess calls and corpus-counting unit tests) 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 11:24:38 +00:00
Author
Owner

@⁠lixonik on GitHub · 2026-11-26 10:50 UTC · original · reviewed

Windows 11: 7/7 Python tests passed. A synthetic end-to-end CLI check with child commands stubbed reproduced an input index being modified before the command fails. Details inline.

AI-assisted.

**@⁠lixonik** on GitHub · 2026-11-26 10:50 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2256#pullrequestreview-6072803842) · **reviewed** Windows 11: 7/7 Python tests passed. A synthetic end-to-end CLI check with child commands stubbed reproduced an input index being modified before the command fails. Details inline. AI-assisted.
@ -81,3 +86,1 @@
for out in outputs:
if same_report_path(out, work):
return True
inputs = [p for p in (work, game) if p]
Author
Owner

@⁠lixonik on GitHub · 2026-11-26 10:50 UTC · original

[P2] Include the corpus indexes consumed by the watcher in the output collision check.

For --once --results <work>/shaders/dxbc/index.json, this guard accepts the path. With a synthetic DXBC index containing [{"stage":"vs"}], the watcher counts the index and appends its JSONL result to the same file. A subsequent json.load() fails with Extra data, and the watcher itself fails while reading the original list as a results record. This also applies to the SPIR-V index and legacy index paths. Can the guard reject results/log aliases of the actual index files before it writes anything?

**@⁠lixonik** on GitHub · 2026-11-26 10:50 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2256#discussion_r4707283617) [P2] Include the corpus indexes consumed by the watcher in the output collision check. For `--once --results <work>/shaders/dxbc/index.json`, this guard accepts the path. With a synthetic DXBC index containing `[{"stage":"vs"}]`, the watcher counts the index and appends its JSONL result to the same file. A subsequent `json.load()` fails with `Extra data`, and the watcher itself fails while reading the original list as a results record. This also applies to the SPIR-V index and legacy index paths. Can the guard reject results/log aliases of the actual index files before it writes anything?
Author
Owner

@⁠tiguan26 on GitHub · 2026-11-27 04:35 UTC · original · approved these changes

Approving fa4d7ae12.

Outputs are now checked against the game folder as well as the work folder (and --out among them), --interval/--jobs/--results/--log are validated, the JSON inputs must be the expected shapes, and llvm-mc output is decoded as UTF-8.

Merged onto main d1dff7949 in one batch with 22 other tool PRs of this series (no conflicts), on Linux with Python 3.13. tests/test_corpus_watch.py: 7 passed (main: 4). AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠tiguan26** on GitHub · 2026-11-27 04:35 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2256#pullrequestreview-6083534505) · **approved these changes** Approving fa4d7ae12. Outputs are now checked against the game folder as well as the work folder (and `--out` among them), `--interval`/`--jobs`/`--results`/`--log` are validated, the JSON inputs must be the expected shapes, and llvm-mc output is decoded as UTF-8. Merged onto `main` `d1dff7949` in one batch with 22 other tool PRs of this series (no conflicts), on Linux with Python 3.13. `tests/test_corpus_watch.py`: 7 passed (main: 4). AI-assisted (Claude Code, Claude Opus 5.5).
@ -81,3 +86,1 @@
for out in outputs:
if same_report_path(out, work):
return True
inputs = [p for p in (work, game) if p]
Author
Owner

@⁠kirigayakazima on GitHub · 2026-11-27 12:07 UTC · original

Fixed: outputs_collide() now also guards work's corpus index paths (shaders/{dxbc,spirv}/index.json and legacy {dxbc,spirv}/index.json) so --results/--log cannot alias them. Added regression tests in tests/test_corpus_watch.py (8 passed + 5 repo checks).

**@⁠kirigayakazima** on GitHub · 2026-11-27 12:07 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2256#discussion_r4719170666) Fixed: `outputs_collide()` now also guards `work`'s corpus index paths (`shaders/{dxbc,spirv}/index.json` and legacy `{dxbc,spirv}/index.json`) so `--results`/`--log` cannot alias them. Added regression tests in `tests/test_corpus_watch.py` (8 passed + 5 repo checks).
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/2256/head:github-bot/gh-2256'
git switch 'github-bot/gh-2256'

Merge

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