test(victory-formats): cover the WMA Pro XMA Huffman tables #28

Closed
github-bot wants to merge 1 commit from gh-pr/28/head into gh-pr/28/base
Owner

@⁠imShangLi on GitHub · 2026-12-02 11:11 UTC · original
imShangLi:feat/xma-table-tests → main · +70 −0 · 1 files · 1 commits · closed without merging

What

Adds a #[cfg(test)] module to crates/victory-formats/src/xma/tables.rs (currently the largest module in ictory-formats without unit tests), pinning invariants the XMA2 decoder relies on:

  • each of the seven Huffman tables (SCALE, SCALE_RL, COEF1, VEC2, VEC1, COEF0_LENS, VEC4_LENS) is a complete prefix code: sum(2^-len) == 1.0;
  • code lengths stay within 1..=22 (no zero-length code);
  • symbols are unique within every (symbol, length) table;
  • CRITICAL_FREQ is strictly increasing;
  • the coefficient/run tables (COEF0_LEVEL, COEF1_LEVEL, COEF0_RUN, COEF1_RUN, SCALE_RL_RUN, SCALE_RL_LEVEL) open with zero.

Why

These tables drive the WMA Pro bitstream decode; a malformed table (a non-canonical or incomplete code, a duplicate symbol, or an out-of-range code length) would corrupt every XMA2 frame. The Kraft-sum check is mathematically grounded: a canonical prefix code must satisfy sum(2^-len) <= 1, and a complete one sums to exactly 1.0 (verified: all seven tables do).

Verification

  • cargo test -p victory-formats xma::tables ? 5 passed / 0 failed.
  • cargo clippy -p victory-formats --all-targets --locked -- -D warnings ? clean (exit 0).
  • Pure data, no game assets, no external fixtures, no GPU/audio hardware needed. The suite requires no title.

Note on the BC7 oracle tests

cpack::tests::oracle_parity_all_formats_and_strip_boundaries, oracle_parity_all_bc7_modes_rotations_subsets, and oracle_parity_errors_and_noise fail on the current checkout with a locally newer toolchain (1.100.1) even on an unmodified main (confirmed by stashing this change); they are unrelated to this PR, which touches only xma/tables.rs. On the repo's pinned toolchain (1.98.1) they are expected to pass; the maintainer's CI will confirm.

Disclosure

Written by an AI agent (LobsterAI/DSH); the invariants, checks, and verification were run locally and are reproducible with the commands above. No game data, no proprietary assets, no third-party names.

**@⁠imShangLi** on GitHub · 2026-12-02 11:11 UTC · [original](https://github.com/ToLIManl/VIctory-Hydra/pull/28) `imShangLi:feat/xma-table-tests` → `main` · +70 −0 · 1 files · 1 commits · closed without merging ## What Adds a #[cfg(test)] module to crates/victory-formats/src/xma/tables.rs (currently the largest module in ictory-formats without unit tests), pinning invariants the XMA2 decoder relies on: - each of the seven Huffman tables (SCALE, SCALE_RL, COEF1, VEC2, VEC1, COEF0_LENS, VEC4_LENS) is a **complete prefix code**: sum(2^-len) == 1.0; - code lengths stay within 1..=22 (no zero-length code); - symbols are unique within every (symbol, length) table; - CRITICAL_FREQ is strictly increasing; - the coefficient/run tables (COEF0_LEVEL, COEF1_LEVEL, COEF0_RUN, COEF1_RUN, SCALE_RL_RUN, SCALE_RL_LEVEL) open with zero. ## Why These tables drive the WMA Pro bitstream decode; a malformed table (a non-canonical or incomplete code, a duplicate symbol, or an out-of-range code length) would corrupt every XMA2 frame. The Kraft-sum check is mathematically grounded: a canonical prefix code must satisfy sum(2^-len) <= 1, and a complete one sums to exactly 1.0 (verified: all seven tables do). ## Verification - cargo test -p victory-formats xma::tables ? **5 passed / 0 failed**. - cargo clippy -p victory-formats --all-targets --locked -- -D warnings ? **clean (exit 0)**. - Pure data, no game assets, no external fixtures, no GPU/audio hardware needed. The suite requires no title. ## Note on the BC7 oracle tests cpack::tests::oracle_parity_all_formats_and_strip_boundaries, oracle_parity_all_bc7_modes_rotations_subsets, and oracle_parity_errors_and_noise fail on the current checkout with a locally newer toolchain (1.100.1) even on an unmodified main (confirmed by stashing this change); they are unrelated to this PR, which touches only xma/tables.rs. On the repo's pinned toolchain (1.98.1) they are expected to pass; the maintainer's CI will confirm. ## Disclosure Written by an AI agent (LobsterAI/DSH); the invariants, checks, and verification were run locally and are reproducible with the commands above. No game data, no proprietary assets, no third-party names.
Add a #[cfg(test)] module to crates/victory-formats/src/xma/tables.rs
with invariants the decoder relies on:
- each of the seven Huffman tables (SCALE, SCALE_RL, COEF1, VEC2, VEC1,
  COEF0_LENS, VEC4_LENS) is a complete prefix code: Kraft sum == 1.0;
- code lengths stay within 1..=22;
- symbols are unique within every (symbol, length) table;
- CRITICAL_FREQ is strictly increasing;
- the coefficient/run tables open with zero.

Pure data, no game assets, no external data required.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 17:09:16 +00:00
github-bot closed this pull request 2026-12-02 17:09:16 +00:00
Author
Owner

@⁠ToLIManl on GitHub · 2026-12-02 12:54 UTC · original

Thank you @⁠imShangLi! Integrated onto main in commit 5d7f3ef with full Co-authored-by credit, and verified all 5 XMA2 Huffman & critical-band unit tests pass (cargo test -p victory-formats xma::tables — 5/5 passed). Closing since it was integrated directly onto the rebased v2.0 main branch.

**@⁠ToLIManl** on GitHub · 2026-12-02 12:54 UTC · [original](https://github.com/ToLIManl/VIctory-Hydra/pull/28#issuecomment-7346060246) Thank you @⁠imShangLi! Integrated onto `main` in commit `5d7f3ef` with full `Co-authored-by` credit, and verified all 5 XMA2 Huffman & critical-band unit tests pass (`cargo test -p victory-formats xma::tables` — 5/5 passed). Closing since it was integrated directly onto the rebased v2.0 `main` branch.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.