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

Merged
leonida/mandy
kirigayakazima merged 2 commits from fix/corpus-watch-safety into main 2026-11-29 03:38:09 +00:00

Pull request successfully merged and closed

kirigayakazima commented 2026-11-26 10:43:07 +00:00

Claimed in the coordination issue as: CORPUS-WATCH-CLI-ENCODING-COLLISION-AND-BOM-SAFETY (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7189698488)

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.
Claimed in the coordination issue as: CORPUS-WATCH-CLI-ENCODING-COLLISION-AND-BOM-SAFETY (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7189698488) ### 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.
lixonik reviewed 2026-11-26 10:50:44 +00:00
lixonik left a comment
No description provided.
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.
tiguan26 approved these changes 2026-11-27 04:35:42 +00:00
tiguan26 left a comment

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).

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).
kirigayakazima reviewed 2026-11-27 12:07:12 +00:00
lixonik reviewed 2026-11-27 14:23:24 +00:00
lixonik left a comment
No description provided.
Re-checked at `199c8c17e` (merged onto `main` `ec91d695c`). Extending `outputs_collide()` to include `work`'s `shaders/{dxbc,spirv}/index.json` and legacy `{dxbc,spirv}/index.json` paths (with dedicated collision tests) cleanly covers the overlap with `--report`. Verified locally on Windows 11 (Python 3): - `tests/test_corpus_watch.py`: 8/8 passed - `scripts/check_no_game_data.py` and `git diff --check`: clean No remaining findings. AI-assisted.
sodove commented 2026-11-28 09:15:26 +00:00

#2256 | head 199c8c17e0e23ed4326c47404e66ad9d9e2f5821 | python3 -I tests/test_corpus_watch.py -v | red: 8 tests, 15 errors | green: 8 passed | Exceptions on main → pass

Baseline errors included BOM decoding and incompatible call signatures. The merged tests exercised those paths successfully. Failure and error counts include subtest events.

Pinned main 4938673668d807bf365b61284bf22b1ff8d02cc4, merged into the PR head. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Full suite: not run. AI-assisted: OpenAI Codex. Batch claim.

#2256 | head `199c8c17e0e23ed4326c47404e66ad9d9e2f5821` | `python3 -I tests/test_corpus_watch.py -v` | red: 8 tests, 15 errors | green: 8 passed | **Exceptions on main → pass** Baseline errors included BOM decoding and incompatible call signatures. The merged tests exercised those paths successfully. Failure and error counts include subtest events. Pinned main `4938673668d807bf365b61284bf22b1ff8d02cc4`, merged into the PR head. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Full suite: not run. AI-assisted: OpenAI Codex. [Batch claim](https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7236982945).
zmasi commented 2026-11-28 22:14:13 +00:00

Native Windows 11 NTFS Verification (199c8c17e0)

Verified 199c8c17e0e23ed4326c47404e66ad9d9e2f5821 merged cleanly onto origin/main (c7753ed98a56677f10e34078b37eab0540e190ec, git merge-tree --write-tree rc=0) on native Windows 11 (26200) + NTFS:

  • Red (origin/main c7753ed98a): python -I tests/test_corpus_watch.py failed (FAILED (errors=15) across 8 tests).
  • Green (origin/main + 199c8c17e0):
    • python -I tests/test_corpus_watch.py: 8/8 OK (utf-8-sig BOM handling on dxbc/spirv indexes and results, --out/--game/corpus-index collision guards, --interval finite/nonnegative and --jobs >= 1 CLI validation, parent folder creation, and explicit encoding="utf-8", errors="replace" subprocess calls).
    • Live Windows 11 NTFS hardlink probe: Created an NTFS hard link (os.link) to shaders\dxbc\index.json and confirmed corpus_watch.outputs_collide rejects it (True).

AI-assisted.

### Native Windows 11 NTFS Verification (`199c8c17e0`) Verified `199c8c17e0e23ed4326c47404e66ad9d9e2f5821` merged cleanly onto `origin/main` (`c7753ed98a56677f10e34078b37eab0540e190ec`, `git merge-tree --write-tree` `rc=0`) on native **Windows 11 (`26200`) + NTFS**: - **Red (`origin/main` `c7753ed98a`)**: `python -I tests/test_corpus_watch.py` failed (`FAILED (errors=15)` across `8` tests). - **Green (`origin/main + 199c8c17e0`)**: - `python -I tests/test_corpus_watch.py`: **`8/8 OK`** (`utf-8-sig` BOM handling on `dxbc`/`spirv` indexes and `results`, `--out`/`--game`/corpus-index collision guards, `--interval` finite/nonnegative and `--jobs >= 1` CLI validation, parent folder creation, and explicit `encoding="utf-8", errors="replace"` subprocess calls). - **Live Windows 11 NTFS hardlink probe**: Created an NTFS hard link (`os.link`) to `shaders\dxbc\index.json` and confirmed `corpus_watch.outputs_collide` rejects it (`True`). AI-assisted.
OreoFR commented 2026-11-29 03:19:47 +00:00

Verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS (case-insensitive), Python 3.12.16, main c8bf0e7b6, PR head 199c8c17e : red 15 errors / green 8 OK

python3.12 -I tests/test_corpus_watch.py (8 tests):

  • Merge: clean (git merge-tree).
  • Red (main + only this PR's test file): 15 errors (subtests included) in test_cli_validation_parent_creation_and_subprocess_encoding (interval nan / inf / -1, jobs 0 / -2, results/log pointing at a directory; main's main() takes no argv yet), test_outputs_collide_checks_out_and_game, test_outputs_collide_rejects_work_corpus_indexes (4 index.json paths), test_utf8_bom_indexes_and_malformed_root_types.
  • Green (main + git merge --no-ff): 8/8 OK, skipped 0.
  • (MEASURED n=3) red stable.
  • Neighbours: only this test imports the script; test_tool_startup same psin_dialogue failure on main and merge, unrelated.
  • Diff: BOM accepted and the JSON root must be a list/object; outputs_collide now also compares out vs game and the 4 work-dir index.json files (still plain path equality, so an output placed inside the work dir is not caught); interval finite and >= 0, jobs >= 1; parents of results/log created; subprocess output read as utf-8 with errors=replace. No game data.

Verdict: READY

AI-assisted: Claude Code

Verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS (case-insensitive), Python 3.12.16, main c8bf0e7b6, PR head 199c8c17e : red 15 errors / green 8 OK `python3.12 -I tests/test_corpus_watch.py` (8 tests): - Merge: clean (`git merge-tree`). - **Red** (main + only this PR's test file): 15 errors (subtests included) in `test_cli_validation_parent_creation_and_subprocess_encoding` (interval nan / inf / -1, jobs 0 / -2, results/log pointing at a directory; main's `main()` takes no argv yet), `test_outputs_collide_checks_out_and_game`, `test_outputs_collide_rejects_work_corpus_indexes` (4 index.json paths), `test_utf8_bom_indexes_and_malformed_root_types`. - **Green** (main + `git merge --no-ff`): 8/8 OK, skipped 0. - (MEASURED n=3) red stable. - Neighbours: only this test imports the script; `test_tool_startup` same `psin_dialogue` failure on main and merge, unrelated. - Diff: BOM accepted and the JSON root must be a list/object; `outputs_collide` now also compares out vs game and the 4 work-dir index.json files (still plain path equality, so an output placed inside the work dir is not caught); interval finite and >= 0, jobs >= 1; parents of results/log created; subprocess output read as utf-8 with `errors=replace`. No game data. **Verdict: READY** AI-assisted: Claude Code
DadaCap commented 2026-11-29 03:38:06 +00:00

Merging, thank you @kirigayakazima! OreoFR's agent verified this head merged with current main: the test fails on main and passes with the PR (https://github.com/ProjectLeonida/mandy/pull/2256#issuecomment-7249981480), and it still merges cleanly.

AI-assisted (Claude Code, Claude Opus 5.5), on behalf of DadaCap.

Merging, thank you @kirigayakazima! OreoFR's agent verified this head merged with current main: the test fails on main and passes with the PR (https://github.com/ProjectLeonida/mandy/pull/2256#issuecomment-7249981480), and it still merges cleanly. AI-assisted (Claude Code, Claude Opus 5.5), on behalf of DadaCap.
Sign in to join this conversation.
No description provided.