tests: cover bcpack_recover_constants parsing, recovery, and SHA-256 refusal #3739

Manually merged
github merged 2 commits from github-bot/gh-3737 into main 2026-12-01 17:11:26 +00:00 AGit
Owner

@⁠Ammmae0x on GitHub · 2026-12-01 13:26 UTC · original
Ammmae0x:tests/bcpack-recover-constants → main · +1133 −0 · 5 files · 2 commits · merged 2026-12-01 17:06 UTC

Refs #1149

Portable unit, boundary, CLI/refusal and mutation tests for tools/bcpack_recover_constants.py with zero edits to existing files (5 new files only, from origin/main 5a1644ad).

Note on scope: the task text named parse_bytes/parse_ints, extract_array/extract_int_array and a 4096 frequency-sum recovery, but none of those exist in this script (extract_array lives in tests/bcpack_tables_check.py; the 4096 tables live in tools/_bcpack_rans/bcpack_tables.py). The suite covers the script as it actually stands instead: constants, interleave/split, colour/unpack6, the wire-descriptor parser with its pinned SHA-256 gate, initializer/write_tables, the oracle query() path, the real CLI, and a full main() pipeline run.

Loading the script directly would run its top level (argparse with four required arguments, two ctypes CDLL loads, wire_descriptors() against the pinned, unbundled BC6HBC7.cpp), so the check parses the real source with ast, executes only its imports, constants and function definitions, and injects fakes for the rest. The SHA-256 refusal is tested with the real hashlib against a synthetic reference; synthetic descriptor fragments cover every parser path; the positive parser cases stub only the digest past the gate the refusal case pins. No fake hash or DLL bytes are written into src/ or tools/. The full oracle pipeline still needs the installed oracle and the real reference and stays manual (see docs/experiments/bcpack-standalone.md).

What landed (commit 0a0aa818):

  • tests/bcpack_recover_constants_check.py: 15 cases (413 assertions), plus 7 single-fault mutations applied to real copies of the script and loaded the same way (SHA gate inverted, interleave lanes swapped, LINE order changed, unpack6 bias dropped, mode 13/14 sort dropped, BC6 wire field rescaled, query guard-byte assertion dropped), all killed. --mutate <id> exits non-zero when killed, matching the CTest WILL_FAIL TRUE convention.
  • tests/cmake/bcpack_recover_constants.cmake: CTest bcpack_recover_constants plus 7 bcpack_recover_constants_<mut>_mut WILL_FAIL TRUE controls, guarded by if(EXISTS "${INTAKE_PYTHON}").
  • tests/bcpack_recover_constants_meta_check.py: audits the contract and runs every case individually and all together, plus the exact 1:1 set of 7 CMake mutations against real mutated copies (zero model-only mutants).
  • tests/checks/python-linux/bcpack_recover_constants.txt: wires the meta check into Linux CI.
  • docs/experiments/bcpack-recover-constants.md: cases, mutations, and reproduction commands.

Fix (commit b96b3749, addressing the Windows verification failure on 0a0aa818):

  • The CLI case for a missing oracle DLL now accepts FileNotFoundError or OSError in stderr: Windows Python's ctypes.CDLL raises FileNotFoundError: Could not find module ... (an OSError subclass) rather than printing OSError:. Exit code 1 is still required.
  • run_mutations and --mutate mode now catch AssertionError only (all 7 controls fail via AssertionError); a broad except Exception risked counting an accidental NameError/TypeError as killed. The run_mutations docstring now says so.

Linux verification (this host, /tmp/pe-env Python 3.12):

  • python -B tests/bcpack_recover_constants_check.py — bcpack_recover_constants: 413 cases, 7/7 mutations killed PASS
  • python -B tests/bcpack_recover_constants_meta_check.py — PASS: bcpack_recover_constants: 15 cases, 7/7 mutations killed (subprocess --mutate)
  • Each --mutate <id> exits 1 (killed); each single case exits 0.
  • Scratch CMake configure + ctest -R '^bcpack_recover_constants' — 8/8 tests passed (1 check + 7 WILL_FAIL controls).
  • python -B tests/form_coverage_check.py, tests/docs_links_check.py (208 files, 802 links), tests/bidi_controls_check.py (2826 files) — all pass; git diff --check clean; git status shows only the 5 new files; zero personal paths.
  • Re-verified after the fix commit b96b3749: check 413 cases, 7/7 killed PASS; meta 15 cases, 7/7 killed PASS; each --mutate <id> exits 1 individually; form/docs (209 files, 806 links)/bidi (2829 files) pass; git diff --check clean; only the 5 branch files vs origin/main; zero personal paths.

No mingw on this host, so no Windows compile check; WIN-VERIFY run is the arbiter.

AI-assisted.

Windows Verification (b96b3749)

  • git merge-tree --write-tree upstream/main HEAD -> 047859fd (exit 0), git diff --check clean
  • Python checks: py_compile, bcpack_recover_constants_check.py, bcpack_recover_constants_meta_check.py, form_coverage_check.py, docs_links_check.py (209 files, 806 links), bidi_controls_check.py (2829 files) passed
  • Commands:
python -B tests/bcpack_recover_constants_meta_check.py
ctest --preset dev --no-tests=error -R "^bcpack_recover_constants" --output-on-failure
ctest --preset release --no-tests=error -R "^bcpack_recover_constants" --output-on-failure
  • Results: bcpack_recover_constants: 413 cases, 7/7 mutations killed PASS (15 meta cases, 7/7 --mutate killed); dev 8/8 passed (2.67s); release 8/8 passed (2.59s). AI-assisted.
**@⁠Ammmae0x** on GitHub · 2026-12-01 13:26 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3737) `Ammmae0x:tests/bcpack-recover-constants` → `main` · +1133 −0 · 5 files · 2 commits · merged 2026-12-01 17:06 UTC Refs #1149 Portable unit, boundary, CLI/refusal and mutation tests for `tools/bcpack_recover_constants.py` with zero edits to existing files (5 new files only, from `origin/main` `5a1644ad`). Note on scope: the task text named `parse_bytes`/`parse_ints`, `extract_array`/`extract_int_array` and a 4096 frequency-sum recovery, but none of those exist in this script (`extract_array` lives in `tests/bcpack_tables_check.py`; the 4096 tables live in `tools/_bcpack_rans/bcpack_tables.py`). The suite covers the script as it actually stands instead: constants, `interleave`/`split`, `colour`/`unpack6`, the wire-descriptor parser with its pinned SHA-256 gate, `initializer`/`write_tables`, the oracle `query()` path, the real CLI, and a full `main()` pipeline run. Loading the script directly would run its top level (argparse with four required arguments, two ctypes CDLL loads, `wire_descriptors()` against the pinned, unbundled `BC6HBC7.cpp`), so the check parses the real source with `ast`, executes only its imports, constants and function definitions, and injects fakes for the rest. The SHA-256 refusal is tested with the real hashlib against a synthetic reference; synthetic descriptor fragments cover every parser path; the positive parser cases stub only the digest past the gate the refusal case pins. No fake hash or DLL bytes are written into `src/` or `tools/`. The full oracle pipeline still needs the installed oracle and the real reference and stays manual (see `docs/experiments/bcpack-standalone.md`). What landed (commit `0a0aa818`): - `tests/bcpack_recover_constants_check.py`: 15 cases (413 assertions), plus 7 single-fault mutations applied to real copies of the script and loaded the same way (SHA gate inverted, interleave lanes swapped, LINE order changed, unpack6 bias dropped, mode 13/14 sort dropped, BC6 wire field rescaled, query guard-byte assertion dropped), all killed. `--mutate <id>` exits non-zero when killed, matching the CTest `WILL_FAIL TRUE` convention. - `tests/cmake/bcpack_recover_constants.cmake`: CTest `bcpack_recover_constants` plus 7 `bcpack_recover_constants_<mut>_mut` `WILL_FAIL TRUE` controls, guarded by `if(EXISTS "${INTAKE_PYTHON}")`. - `tests/bcpack_recover_constants_meta_check.py`: audits the contract and runs every case individually and all together, plus the exact 1:1 set of 7 CMake mutations against real mutated copies (zero model-only mutants). - `tests/checks/python-linux/bcpack_recover_constants.txt`: wires the meta check into Linux CI. - `docs/experiments/bcpack-recover-constants.md`: cases, mutations, and reproduction commands. Fix (commit `b96b3749`, addressing the Windows verification failure on `0a0aa818`): - The CLI case for a missing oracle DLL now accepts `FileNotFoundError` or `OSError` in stderr: Windows Python's `ctypes.CDLL` raises `FileNotFoundError: Could not find module ...` (an `OSError` subclass) rather than printing `OSError:`. Exit code 1 is still required. - `run_mutations` and `--mutate` mode now catch `AssertionError` only (all 7 controls fail via `AssertionError`); a broad `except Exception` risked counting an accidental `NameError`/`TypeError` as killed. The `run_mutations` docstring now says so. Linux verification (this host, `/tmp/pe-env` Python 3.12): - `python -B tests/bcpack_recover_constants_check.py` — `bcpack_recover_constants: 413 cases, 7/7 mutations killed PASS` - `python -B tests/bcpack_recover_constants_meta_check.py` — `PASS: bcpack_recover_constants: 15 cases, 7/7 mutations killed (subprocess --mutate)` - Each `--mutate <id>` exits 1 (killed); each single case exits 0. - Scratch CMake configure + `ctest -R '^bcpack_recover_constants'` — 8/8 tests passed (1 check + 7 `WILL_FAIL` controls). - `python -B tests/form_coverage_check.py`, `tests/docs_links_check.py` (208 files, 802 links), `tests/bidi_controls_check.py` (2826 files) — all pass; `git diff --check` clean; `git status` shows only the 5 new files; zero personal paths. - Re-verified after the fix commit `b96b3749`: check 413 cases, 7/7 killed PASS; meta 15 cases, 7/7 killed PASS; each `--mutate <id>` exits 1 individually; form/docs (209 files, 806 links)/bidi (2829 files) pass; `git diff --check` clean; only the 5 branch files vs `origin/main`; zero personal paths. No mingw on this host, so no Windows compile check; WIN-VERIFY run is the arbiter. AI-assisted. <!-- WIN-VERIFY: passed | sha=b96b3749622234a6642d5cc25e4d85c6b371a649 | targets=none | ctest=^bcpack_recover_constants | release=true --> ### Windows Verification (`b96b3749`) - `git merge-tree --write-tree upstream/main HEAD` -> `047859fd` (exit 0), `git diff --check` clean - Python checks: `py_compile`, `bcpack_recover_constants_check.py`, `bcpack_recover_constants_meta_check.py`, `form_coverage_check.py`, `docs_links_check.py` (209 files, 806 links), `bidi_controls_check.py` (2829 files) passed - Commands: ```text python -B tests/bcpack_recover_constants_meta_check.py ctest --preset dev --no-tests=error -R "^bcpack_recover_constants" --output-on-failure ctest --preset release --no-tests=error -R "^bcpack_recover_constants" --output-on-failure ``` - Results: `bcpack_recover_constants`: `413 cases, 7/7 mutations killed PASS` (`15` meta cases, `7/7` `--mutate` killed); `dev` 8/8 passed (2.67s); `release` 8/8 passed (2.59s). AI-assisted.
Refs #1149

Portable unit, boundary, CLI/refusal and mutation tests for tools/bcpack_recover_constants.py with zero edits to existing files: AST-isolated loading (the script top level parses arguments and loads oracle DLLs), synthetic fixtures for the wire-descriptor parser with its pinned SHA-256 gate, exact interleave/split, colour and unpack6 values, table emitters, fake-oracle query and full main() pipeline runs, and seven single-fault mutations against real copies of the script, all killed.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 13:31:39 +00:00
Windows Python raises FileNotFoundError (an OSError subclass) from
ctypes.CDLL on a missing DLL, so the CLI case now accepts either
spelling in stderr while still requiring exit code 1. Mutation
controls now catch AssertionError only, so an accidental NameError or
TypeError in a control fails loudly instead of counting as killed.
github manually merged commit 4469011ada into main 2026-12-01 17:11:26 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.