lds_fuzz: guard --model-only/--keep/--only flags and enforce UTF-8 subprocess I/O #2269

Merged
kirigayakazima merged 1 commit from upstream-pr/2269 into main 2026-11-28 23:47:57 +00:00
kirigayakazima commented 2026-11-26 11:53:12 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-11-26T11:53:12Z.


Claimed in the coordination issue as: LDS-FUZZ-CLI-KEEP-MODEL-ONLY-AND-ENCODING-SAFETY (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7191235314)

What and why

tools/lds_fuzz.py previously:

  • Defined main() with no argv parameter and skipped validating --keep / --perturb / --negative-control / --minimize whenever --model-only was also passed.
  • Accepted empty --keep "" or a regular file path for --keep, and ignored negative indices mixed into --only (such as 0,-1).
  • Invoked subprocess.run(..., text=True) in translate() and run_gpu() without encoding="utf-8", errors="replace" and read index.json without "utf-8-sig".

This adds argv=None to main(), enforces --oracle hw (without --model-only) and directory/non-empty validation for --keep, rejects negative --only indices, sets UTF-8 encoding/BOM handling in translate() and run_gpu(), and adds unit coverage in tests/test_lds_fuzz.py.

Tested

  • python -I tests/test_lds_fuzz.py -v (40 passed)
  • Detached upstream/main baseline negative control: failed with the new CLI tests before the fix
  • python -I tests/test_ci_registration.py, python -I tests/test_text_write_line_endings.py, python -I scripts/check_no_game_data.py, python -I -m compileall -q, and git diff --cached --check

GPUs tested: n/a

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.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5509536019 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2269). Originally posted by [kirigayakazima](https://github.com/kirigayakazima) on 2026-11-26T11:53:12Z. --- Claimed in the coordination issue as: LDS-FUZZ-CLI-KEEP-MODEL-ONLY-AND-ENCODING-SAFETY (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7191235314) ### What and why `tools/lds_fuzz.py` previously: - Defined `main()` with no `argv` parameter and skipped validating `--keep` / `--perturb` / `--negative-control` / `--minimize` whenever `--model-only` was also passed. - Accepted empty `--keep ""` or a regular file path for `--keep`, and ignored negative indices mixed into `--only` (such as `0,-1`). - Invoked `subprocess.run(..., text=True)` in `translate()` and `run_gpu()` without `encoding="utf-8", errors="replace"` and read `index.json` without `"utf-8-sig"`. This adds `argv=None` to `main()`, enforces `--oracle hw` (without `--model-only`) and directory/non-empty validation for `--keep`, rejects negative `--only` indices, sets UTF-8 encoding/BOM handling in `translate()` and `run_gpu()`, and adds unit coverage in `tests/test_lds_fuzz.py`. ### Tested - `python -I tests/test_lds_fuzz.py -v` (40 passed) - Detached `upstream/main` baseline negative control: failed with the new CLI tests before the fix - `python -I tests/test_ci_registration.py`, `python -I tests/test_text_write_line_endings.py`, `python -I scripts/check_no_game_data.py`, `python -I -m compileall -q`, and `git diff --cached --check` GPUs tested: n/a 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.
real-rusher commented 2026-11-26 12:23:28 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by real-rusher on 2026-11-26T12:23:28Z.


Verified on main a73a57e1 (Ubuntu 24.04 x86-64, Python 3.13, no GPU). Merges cleanly. With this PR, python -I tests/test_lds_fuzz.py: 40 tests OK. The PR's test file against main's tool: 3 errors, so the new tests fail on main and pass with the change. compileall clean.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7191939942 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2269#issuecomment-7191939942). Originally posted by [real-rusher](https://github.com/real-rusher) on 2026-11-26T12:23:28Z. --- Verified on main a73a57e1 (Ubuntu 24.04 x86-64, Python 3.13, no GPU). Merges cleanly. With this PR, python -I tests/test_lds_fuzz.py: 40 tests OK. The PR's test file against main's tool: 3 errors, so the new tests fail on main and pass with the change. compileall clean. AI-assisted: yes (Claude Code)
DeadlyChirp commented 2026-11-26 12:52:20 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by DeadlyChirp on 2026-11-26T12:52:20Z.


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

  • tests/test_lds_fuzz.py: 40 passed (main: 37 passed).

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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7192571110 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2269#issuecomment-7192571110). Originally posted by [DeadlyChirp](https://github.com/DeadlyChirp) on 2026-11-26T12:52:20Z. --- Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main. - `tests/test_lds_fuzz.py`: 40 passed (main: 37 passed). (AI-assisted test run; output checked by hand.)
tiguan26 commented 2026-11-27 04:37:37 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by tiguan26 on 2026-11-27T04:37:37Z.

Review: APPROVED


Approving 9a678ef40.

--keep and the other hardware-only flags are refused with --model-only too (an empty --keep counted as unset before), --only rejects empty and negative indexes, and subprocess output is decoded as UTF-8 with the index read BOM-tolerant.

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_lds_fuzz.py: 40 passed (main: 37). AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6083544876 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2269#pullrequestreview-6083544876). Originally posted by [tiguan26](https://github.com/tiguan26) on 2026-11-27T04:37:37Z. **Review:** APPROVED --- Approving 9a678ef40. `--keep` and the other hardware-only flags are refused with `--model-only` too (an empty `--keep` counted as unset before), `--only` rejects empty and negative indexes, and subprocess output is decoded as UTF-8 with the index read BOM-tolerant. 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_lds_fuzz.py`: 40 passed (main: 37). AI-assisted (Claude Code, Claude Opus 5.5).
TheGeogeo commented 2026-11-28 23:38:08 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-28T23:38:08Z.


Tested 9a678ef40 merged (no commit) with main aa918e5d9: Python 3.12.4, Windows 11 10.0.26300, CPU only. check_no_game_data.py is clean.

  • Green: tests/test_lds_fuzz.py, 40 tests pass.
  • Red: with tools/lds_fuzz.py back to main, 3 tests error (Unexpected UTF-8 BOM).

No blocker from my side.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7247562209 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2269#issuecomment-7247562209). Originally posted by [TheGeogeo](https://github.com/TheGeogeo) on 2026-11-28T23:38:08Z. --- Tested `9a678ef40` merged (no commit) with `main` `aa918e5d9`: Python 3.12.4, Windows 11 10.0.26300, CPU only. `check_no_game_data.py` is clean. - Green: `tests/test_lds_fuzz.py`, 40 tests pass. - Red: with `tools/lds_fuzz.py` back to `main`, 3 tests error (`Unexpected UTF-8 BOM`). No blocker from my side. AI-assisted (Claude Code).
MoonEyes commented 2026-11-28 23:47:59 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T23:47:59Z.


Merged after TheGeogeo's red/green check (check) (Windows, Python tests, no GPU needed) and a local re-check here. Merged after local re-verification: this PR merged onto main 02a69e602 without conflict, and its test file(s) (tests/test_lds_fuzz.py) pass there. Earlier today the same tests failed on main without the PR (red/green) and a bundle with other open PRs showed no new failures. check_no_game_data.py is clean. Windows 11, Python 3.14; no GPU needed for these tests.

AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7247671191 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2269#issuecomment-7247671191). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T23:47:59Z. --- Merged after **TheGeogeo**'s red/green check ([check](https://github.com/ProjectLeonida/mandy/pull/2269#issuecomment-7247562209)) (Windows, Python tests, no GPU needed) and a local re-check here. Merged after local re-verification: this PR merged onto `main` 02a69e602 without conflict, and its test file(s) (`tests/test_lds_fuzz.py`) pass there. Earlier today the same tests failed on `main` without the PR (red/green) and a bundle with other open PRs showed no new failures. `check_no_game_data.py` is clean. Windows 11, Python 3.14; no GPU needed for these tests. _AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes._
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!2269
No description provided.