f16_trans_sweep: harden CLI tokens, atomic JSON writes, and oracle result count guards #1646

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

@⁠IlyassRS3 on GitHub · 2026-11-25 06:58 UTC · original
IlyassRS3:fix/f16-trans-sweep-json-and-guards → main · +152 −14 · 2 files · 1 commits · open

Item ID: F16-TRANS-SWEEP-JSON-AND-GUARDS
Claim: #1608

Summary

Harden CLI parsing, JSON report writing, and oracle result validation in tools/f16_trans_sweep.py:

  • --ops / --modes / --waves / --hw-arch guards: reject empty/trailing comma tokens (v_exp_f16,, keep16,,flush16, 32,), deduplicate repeated ops/modes/waves in first-seen order so 65,536-input sweeps aren't run redundantly, and reject empty/whitespace --hw-arch.
  • Upfront validate_json_path() & atomic write_json_report():
    • Resolve symlinks before validating or staging so symlinked directories/blockers are caught upfront and symlink targets are updated in place without replacing the symlink.
    • Check existing targets for writeability upfront (O_WRONLY), serialize with allow_nan=False and a trailing LF , write non-regular targets like /dev/null directly, and publish regular files atomically via tempfile.mkstemp + file_mode.published_mode + replace_retry.replace.
  • Oracle result guards:
    • Raise RuntimeError in check_modes() when len(got) != len(kernels) or a probe returns an empty word list (instead of crashing with IndexError).
    • Raise RuntimeError in sweep() when len(got) != len(kernels) (instead of returning a truncated array that crashes in classify()).
  • Tests (tests/test_f16_trans_sweep.py): added 3 test methods covering malformed/duplicate selections, empty --hw-arch, atomic/trailing-LF/NaN/symlink//dev/null writes, and short/empty oracle result handling.

Verification

  • AI-assisted: yes
  • GPUs tested: none (CPU synthetic unit tests + mocked oracle on macOS; no GPU, AMD clang, or game data present)
  • python3 -W error -I tests/test_f16_trans_sweep.py -v: 17 passed, 2 skipped (AMD clang / hardware absent)
  • Mutation check against unpatched main: ran=19 failures=2 errors=9 (skipped=2)
  • python3 -I tests/test_text_write_line_endings.py: 3/3 passed
  • python3 -I scripts/check_no_game_data.py tools/f16_trans_sweep.py tests/test_f16_trans_sweep.py: passed
  • python3 -m compileall -q tools/f16_trans_sweep.py tests/test_f16_trans_sweep.py: passed
**@⁠IlyassRS3** on GitHub · 2026-11-25 06:58 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1646) `IlyassRS3:fix/f16-trans-sweep-json-and-guards` → `main` · +152 −14 · 2 files · 1 commits · open Item ID: `F16-TRANS-SWEEP-JSON-AND-GUARDS` Claim: https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608 ### Summary Harden CLI parsing, JSON report writing, and oracle result validation in `tools/f16_trans_sweep.py`: - **`--ops` / `--modes` / `--waves` / `--hw-arch` guards**: reject empty/trailing comma tokens (`v_exp_f16,`, `keep16,,flush16`, `32,`), deduplicate repeated ops/modes/waves in first-seen order so 65,536-input sweeps aren't run redundantly, and reject empty/whitespace `--hw-arch`. - **Upfront `validate_json_path()` & atomic `write_json_report()`**: - Resolve symlinks before validating or staging so symlinked directories/blockers are caught upfront and symlink targets are updated in place without replacing the symlink. - Check existing targets for writeability upfront (`O_WRONLY`), serialize with `allow_nan=False` and a trailing LF ` `, write non-regular targets like `/dev/null` directly, and publish regular files atomically via `tempfile.mkstemp` + `file_mode.published_mode` + `replace_retry.replace`. - **Oracle result guards**: - Raise `RuntimeError` in `check_modes()` when `len(got) != len(kernels)` or a probe returns an empty word list (instead of crashing with `IndexError`). - Raise `RuntimeError` in `sweep()` when `len(got) != len(kernels)` (instead of returning a truncated array that crashes in `classify()`). - **Tests (`tests/test_f16_trans_sweep.py`)**: added 3 test methods covering malformed/duplicate selections, empty `--hw-arch`, atomic/trailing-LF/NaN/symlink/`/dev/null` writes, and short/empty oracle result handling. ### Verification - AI-assisted: yes - GPUs tested: none (CPU synthetic unit tests + mocked oracle on macOS; no GPU, AMD clang, or game data present) - `python3 -W error -I tests/test_f16_trans_sweep.py -v`: 17 passed, 2 skipped (AMD clang / hardware absent) - Mutation check against unpatched `main`: `ran=19 failures=2 errors=9 (skipped=2)` - `python3 -I tests/test_text_write_line_endings.py`: 3/3 passed - `python3 -I scripts/check_no_game_data.py tools/f16_trans_sweep.py tests/test_f16_trans_sweep.py`: passed - `python3 -m compileall -q tools/f16_trans_sweep.py tests/test_f16_trans_sweep.py`: passed
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:59:20 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 06:58 UTC · original · reviewed

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-25 06:58 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1646#pullrequestreview-6053157613) · **reviewed** Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
Author
Owner

@⁠whoalin1 on GitHub · 2026-11-25 08:16 UTC · original

Independent verification (Windows, Python 3.11.9 -I): diff vs merge-base reviewed — comma-token rejection + first-seen dedup for --ops/--modes/--waves, empty --hw-arch guard, symlink-aware validate_json_path/write_json_report (O_WRONLY probe, allow_nan=False, trailing LF, mkstemp+published_mode+replace_retry), RuntimeError guards on short oracle results — all present. test_f16_trans_sweep.py 19 tests OK (2 skips, matches body), --self-test ok, CLI probes reject --ops "v_exp_f16," and --hw-arch " ", compileall + line-endings + check_no_game_data clean. AI-assisted verification.

**@⁠whoalin1** on GitHub · 2026-11-25 08:16 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1646#issuecomment-7156823156) Independent verification (Windows, Python 3.11.9 `-I`): diff vs merge-base reviewed — comma-token rejection + first-seen dedup for `--ops/--modes/--waves`, empty `--hw-arch` guard, symlink-aware `validate_json_path`/`write_json_report` (O_WRONLY probe, `allow_nan=False`, trailing LF, mkstemp+`published_mode`+`replace_retry`), `RuntimeError` guards on short oracle results — all present. `test_f16_trans_sweep.py` 19 tests OK (2 skips, matches body), `--self-test` ok, CLI probes reject `--ops "v_exp_f16,"` and `--hw-arch " "`, compileall + line-endings + `check_no_game_data` 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/1646/head:github-bot/gh-1646'
git switch 'github-bot/gh-1646'

Merge

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