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

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

📋 Pull Request Information

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

Base: main ← Head: fix/corpus-watch-safety


📝 Commits (1)

  • fa4d7ae Harden corpus_watch BOM JSON, output collisions, CLI validation, and UTF-8 subprocesses

📊 Changes

2 files changed (+131 additions, -14 deletions)

View changed files

📝 scripts/corpus_watch.py (+34 -14)
📝 tests/test_corpus_watch.py (+97 -0)

📄 Description

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.

🔄 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/2256 **Author:** [@kirigayakazima](https://github.com/kirigayakazima) **Created:** 11/26/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/corpus-watch-safety` --- ### 📝 Commits (1) - [`fa4d7ae`](https://github.com/ubiquitarianism/leonida/commit/fa4d7ae126f30379557a8e75417c773b72ab67e6) Harden corpus_watch BOM JSON, output collisions, CLI validation, and UTF-8 subprocesses ### 📊 Changes **2 files changed** (+131 additions, -14 deletions) <details> <summary>View changed files</summary> 📝 `scripts/corpus_watch.py` (+34 -14) 📝 `tests/test_corpus_watch.py` (+97 -0) </details> ### 📄 Description 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. --- <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#2260
No description provided.