div_fixup_diff: reject a zero or negative --max-ops and --programs #1625

Open
github-bot wants to merge 1 commit from github-bot/gh-1625 into main AGit
Owner

@⁠xel1uz on GitHub · 2026-11-25 06:14 UTC · original
xel1uz:fix/div-fixup-arg-guards → main · +46 −3 · 2 files · 1 commits · open

Item ID: DIV-FIXUP-ARG-GUARDS (new item; the coordination issue #14 is at GitHub's 2,500-comment cap, so the claim lives here)

Claimed as: DIV-FIXUP-ARG-GUARDS - --max-ops 0 dies in numpy's randint and --programs 0 exits 0 having run no random program. Reproduced on 42537e7b.

What and why

div_fixup_diff validated neither count option: --max-ops 0 ended in ValueError: empty range in randint(1, 0) and --programs 0 / --programs -2 exited 0 after printing only the sweep statistics, so a caller could not tell the random stage had been skipped entirely. Both are now rejected in main() right after parse_args, before the sweep and --self-test: --max-ops must be at least 1 and --programs must be at least 1, via ap.error (exit 2, usage line, no traceback), matching the sibling cf_diff.py. Valid runs are unchanged.

Tested

  • pytest tests/test_div_fixup_diff.py -q with the tool at 42537e7b: 5 failed, 28 passed, 171 subtests passed - only the new guard cases fail.
  • With this branch: 28 passed, 176 subtests passed.
  • git diff --check clean; python3 -I scripts/check_no_game_data.py clean on both files.

GPUs tested: n/a - CPU only, no Vulkan device involved.

AI-assisted: Yes.

Checklist

  • Based on current main (42537e7b) and merges cleanly.
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption; synthetic inputs only.
  • A new translator rule in the contract table of docs/design.md - not applicable, no translator change.
**@⁠xel1uz** on GitHub · 2026-11-25 06:14 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1625) `xel1uz:fix/div-fixup-arg-guards` → `main` · +46 −3 · 2 files · 1 commits · open Item ID: `DIV-FIXUP-ARG-GUARDS` (new item; the coordination issue #14 is at GitHub's 2,500-comment cap, so the claim lives here) Claimed as: `DIV-FIXUP-ARG-GUARDS` - `--max-ops 0` dies in numpy's randint and `--programs 0` exits 0 having run no random program. Reproduced on 42537e7b. ### What and why `div_fixup_diff` validated neither count option: `--max-ops 0` ended in `ValueError: empty range in randint(1, 0)` and `--programs 0` / `--programs -2` exited 0 after printing only the sweep statistics, so a caller could not tell the random stage had been skipped entirely. Both are now rejected in `main()` right after `parse_args`, before the sweep and `--self-test`: `--max-ops must be at least 1` and `--programs must be at least 1`, via `ap.error` (exit 2, usage line, no traceback), matching the sibling `cf_diff.py`. Valid runs are unchanged. ### Tested - `pytest tests/test_div_fixup_diff.py -q` with the tool at 42537e7b: **5 failed, 28 passed, 171 subtests passed** - only the new guard cases fail. - With this branch: **28 passed, 176 subtests passed**. - `git diff --check` clean; `python3 -I scripts/check_no_game_data.py` clean on both files. GPUs tested: n/a - CPU only, no Vulkan device involved. AI-assisted: Yes. ### Checklist - [x] Based on current `main` (42537e7b) and merges cleanly. - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption; synthetic inputs only. - [ ] A new translator rule in the contract table of `docs/design.md` - not applicable, no translator change.
`--max-ops 0` (or negative) got past argparse into `rng.randint(1, max_ops)` and died with

    ValueError: empty range in randint(1, 0)

a traceback and exit code 1 instead of a usage error. A `--programs 0` (or negative) dropped
the random stage and exited 0 with sweep statistics only, or with nothing at all under
--no-sweep.

Before: argparse's `type=int` accepted both; main() checked neither.

After: main() rejects both before any work starts, with ap.error: usage and the message on
stderr, nothing on stdout, exit code 2, shaped like tools/cf_diff.py, which guards --programs
the same way. main() takes an optional argv. tests/test_div_fixup_diff.py's Arguments class
runs the tool as a real `-I` command line and pins both guards at zero and negative values:
exit 2, empty stdout, the message and no traceback, while a valid run still exits 0.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:58:32 +00:00
Author
Owner

@⁠kaayzouee on GitHub · 2026-11-25 07:08 UTC · original

Duplicate of #1616?

**@⁠kaayzouee** on GitHub · 2026-11-25 07:08 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1625#issuecomment-7155537569) Duplicate of #1616?
Author
Owner

@⁠whoalin1 on GitHub · 2026-11-25 10:33 UTC · original

Independent verification (Windows, Python 3.11.9 -I -W error): same guard pattern + docstring exit-2 note; tests use real -I subprocess. test_div_fixup_diff.py 28 OK; all bad-value probes exit 2 before any stage (incl. --programs 0 without --no-sweep — proves rejection precedes sweep); --self-test/valid run ok; hygiene checks clean. AI-assisted verification.

**@⁠whoalin1** on GitHub · 2026-11-25 10:33 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1625#issuecomment-7159855350) Independent verification (Windows, Python 3.11.9 `-I -W error`): same guard pattern + docstring exit-2 note; tests use real `-I` subprocess. `test_div_fixup_diff.py` 28 OK; all bad-value probes exit 2 before any stage (incl. `--programs 0` without `--no-sweep` — proves rejection precedes sweep); `--self-test`/valid run ok; hygiene checks clean. AI-assisted verification.
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/1625/head:github-bot/gh-1625'
git switch 'github-bot/gh-1625'

Merge

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