Files
foxhunt/crates/ml-backtesting/src
jgrusewski cc4c47f471 audit(rust-consts): catch literal-vs-const drift + cleanup BOOK_LEVELS=10
Audit script (audit-rust-consts.sh) scans Rust src/examples for numeric
literals mirroring structural kernel-side consts (N_ACTIONS, Q_N_ATOMS,
HIDDEN_DIM, MAX_UNITS, BOOK_LEVELS). Closes the layer-3 gap noted in
feedback_use_consts_not_literals_for_structural_dims:

  Layer 1: kernel `#define` allowlist  → audit-isv
  Layer 2: Rust `pub const` canonical  → exists (e.g. N_ACTIONS in rl/common.rs)
  Layer 3: Rust literals mirroring (2) → audit-rust-consts (this commit)

Honors `// audit-ignore: <SYMBOL>` per-line markers and skips `[u8; N]`
byte-buffer patterns (high false-positive class — almost always I/O
scratch, not structural dims).

Cleanup driven by first run (19 real flags, no grandfathering):
* New canonical: `BOOK_LEVELS` in `ml-alpha/src/cfc/snap_features.rs`
  (10 book levels = same place as `Mbp10RawInput` struct)
* `ml-backtesting/src/lob/mod.rs`: redefine as `pub use` re-export from
  ml-alpha (single source of truth; ml-backtesting depends on ml-alpha
  via `Mbp10RawInput` already)
* 19 sites switched literal `10` → `BOOK_LEVELS`:
  - snap_features.rs:44-47 (struct fields)
  - data/loader.rs:872-876, 960 (Mbp10Snapshot → Mbp10RawInput convert)
  - data/aggregation.rs:161 (level-wise aggregation loop)
  - trainer/perception.rs:2750-2756, 6272-6278, 6686-6690, 7247-7253
    (snapshot → batch staging loops)
  - tests/lob_sim_fuzz.rs:21, lob_sim_integrated_fuzz.rs:22 (duplicate
    const → use ml_backtesting::lob::BOOK_LEVELS)
* 5 sites marked `// audit-ignore: BOOK_LEVELS — <reason>`:
  - harness.rs:572,574,594 (conviction-bucket histograms, 10 ≠ depth)
  - multi_horizon_labels.rs:489,557,564 (10-element test price vecs)

Re-run after fixes: 0 suspect literals flagged. PASS.
2026-05-24 17:39:40 +02:00
..