From bdc383eb8b689716b4c12ec3fe69e05964be9242 Mon Sep 17 00:00:00 2001 From: Brummel Date: Sun, 14 Jun 2026 23:21:21 +0200 Subject: [PATCH] =?UTF-8?q?test(aura-registry):=20RED=20executable-spec=20?= =?UTF-8?q?for=20optimize=20argmax=20=E2=80=94=20refs=20#67?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The RED half of a RED-first iteration for the optimize/argmax orchestration axis (C12 axis 2). Pins the headline behaviour before the feature exists: optimize(&SweepFamily, metric) returns the single winning SweepPoint — its params coordinate AND its RunReport — chosen by the metric's fixed per-metric sense of best (reusing rank_by's direction semantics), with ties resolving to the earliest enumeration-order point. No caller-supplied direction: that would contradict the shipped rank_by invariant that "best" is fixed by each metric's meaning, and would admit incoherent asks (e.g. the worst max_drawdown). One definition of best per metric. RED for the right reason — optimize is absent (E0425), the sole error; cargo build --workspace stays green (test-only module). GREEN lands in the following commit, which closes #67. --- crates/aura-registry/src/lib.rs | 39 +++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/crates/aura-registry/src/lib.rs b/crates/aura-registry/src/lib.rs index 5d812b6..f067806 100644 --- a/crates/aura-registry/src/lib.rs +++ b/crates/aura-registry/src/lib.rs @@ -118,8 +118,8 @@ impl From for RegistryError { #[cfg(test)] mod tests { use super::*; - use aura_core::Timestamp; - use aura_engine::{RunManifest, RunMetrics, RunReport}; + use aura_core::{Scalar, Timestamp}; + use aura_engine::{RunManifest, RunMetrics, RunReport, SweepFamily, SweepPoint}; fn report_with(total_pips: f64, max_drawdown: f64, flips: u64) -> RunReport { RunReport { @@ -199,4 +199,39 @@ mod tests { other => panic!("expected UnknownMetric, got {other:?}"), } } + + /// `optimize` is `rank_by`'s argmax: over a `SweepFamily` it returns the + /// single winning `SweepPoint` — its `params` coordinate AND its `RunReport` + /// — chosen by the metric's *fixed* sense of best (`total_pips` + /// higher-is-better), and a tie on that metric resolves to the **earliest + /// enumeration-order** point, never a later one. The point carried, not just + /// its metric, is the property: the caller needs the params that won. + #[test] + fn optimize_picks_the_max_metric_point_ties_to_earliest() { + // A hand-built family in odometer order. Two points tie at the maximal + // total_pips (3.0); the EARLIER of the two (index 1, params p=10) must + // win, not the later (index 3, params p=30) — that pins the tie rule. + let point = |p: f64, pips: f64| SweepPoint { + params: vec![Scalar::F64(p)], + report: report_with(pips, 0.5, 0), + }; + let family = SweepFamily { + points: vec![ + point(0.0, 1.0), // 0: also-ran + point(10.0, 3.0), // 1: tied max, earliest -> the winner + point(20.0, 2.0), // 2: also-ran + point(30.0, 3.0), // 3: tied max, but later -> must lose the tie + ], + }; + + let winner = super::optimize(&family, "total_pips").expect("optimize total_pips"); + + // the maximal-metric point wins... + assert_eq!(winner.report.metrics.total_pips, 3.0); + // ...and ties resolve to the earliest enumeration-order point: its params + // identify point 1, not point 3. + assert_eq!(winner.params, vec![Scalar::F64(10.0)]); + // the whole winning point is returned, params AND report together. + assert_eq!(winner, family.points[1]); + } }