Files
wickra/crates
kingchenc b340ecd3d6 test(coppock): lock in warmup_period for every parameter set (refutes R12)
Audit finding R12 claimed `Coppock::warmup_period()` was off by one
because it returns `max(roc_long, roc_short) + wma`, while
`Roc::warmup_period() = period + 1`. After tracing the actual emission
sequence the existing formula is correct: when both ROCs reach `Some`
at 0-based index L (the slower of `roc_long_period` and
`roc_short_period`), the WMA receives its first input there and emits
its `wma_period`-th value at 0-based index `L + wma_period − 1`. The
`warmup_period()` is the 1-based count of inputs needed before the
first `Some`, i.e. `L + wma_period`. R12 was a misread by both Sonnet
audit agents and the Opus verifier — none of them traced the actual
emission timeline.

This commit:

- Expands the doc comment on `warmup_period` with the precise emission
  argument and a worked example for `Coppock::new(6, 4, 3)` (the
  existing test) so a future reader cannot mis-derive the formula.
- Adds `warmup_period_matches_first_some_for_every_parameter_set`,
  which asserts `out[warmup - 1].is_some()` for five parameter
  combinations — including the audit's smoking gun `(4, 2, 3)`. The
  audit's proposed `max + 1 + wma` formula would have predicted index
  7 (the 8th input) for that combination; the real first `Some` lands
  at index 6 (the 7th input), exactly what the current formula
  reports.

No behaviour change — the audit was wrong and the test makes the
contract regression-proof.
2026-05-23 10:38:24 +02:00
..