Files
claude a56ab7859d refactor: cut the engine's backtest-metrics edge via RunReport<M>
C28 phase 2 (Stratification); realizes item 1 of the deferred #147. The
engine's production surface no longer names a backtest-metric type:

- RunReport becomes generic over its metric payload M; sweep/mc/walkforward/
  blueprint thread the parameter (SweepPoint<M>, SweepFamily<M>, WindowRun<M>,
  WalkForwardResult<M>). RunManifest stays concrete and engine-owned (its
  selection: Option<FamilySelection> embeds the foundation-grade analysis type).
- summarize and the MC assembly (McDraw/McFamily/McAggregate/RBootstrap/
  r_bootstrap/monte_carlo) move to aura-backtest - McAggregate::from_draws reads
  RunMetrics fields by name, so generifying it is the phase-6 metric-vocabulary
  abstraction (#147 item 2), still deferred; wholesale relocation is the honest
  cut. The concrete instantiation lives in aura-backtest as
  `type RunReport = aura_engine::RunReport<RunMetrics>` + sibling aliases.
- the statistics kernel (MetricStats/quantile/resample_block/SplitMix64) moves
  to the aura-analysis foundation; the engine re-imports it (inner->foundation,
  legal) and re-exports it so existing consumers stay source-compatible.

Dependency inversion in one commit: aura-engine drops aura-backtest from
[dependencies] (back to dev-deps for its SimBroker/RunMetrics test fixtures);
aura-backtest gains aura-engine. Cycle-free for lib targets - the cycle closes
only through the engine's dev-dep edge, the pattern aura-vocabulary already
uses. aura-backtest reaches the kernel transitively through the engine
re-export, so no aura-backtest -> aura-analysis edge exists (the C28 ladder
permits backtest -> {core, engine} only). run_indexed / SplitMix64::next_f64
widened pub(crate) -> pub for cross-crate use.

Consumers (registry/campaign/cli/composites/ingest/bench) rewired by import
path only, no call-site logic changed. The c28_layering structural test extends
to the full ladder: aura-analysis (no aura-* deps), aura-engine ⊆ {core,
analysis}, aura-backtest ⊆ {core, engine}.

Behaviour-preserving: 1448/0 tests, clippy -D warnings clean, serde shapes
byte-identical (C18 - RunReport<M> keeps field order manifest,metrics; the
CLI pre-serialized-splice contract unchanged), moved code traceable via git
rename detection. Cycle-introduced broken intra-doc links fixed.

closes #292
2026-07-20 13:25:07 +02:00

91 lines
4.1 KiB
Rust

//! Gated integration test: the GER40 15m session-breakout strategy — the
//! Phase-1 `aura-std` node vocabulary wired VERBATIM from
//! `aura-engine/tests/ger40_breakout.rs` — driven over REAL GER40 M1 bars from
//! the local data-server archive (September 2024). Mirrors `real_bars.rs`:
//! skips with a note where the local Pepperstone archive is absent, so
//! `cargo test --workspace` stays green anywhere; exercises the real ingestion
//! path where the files exist.
//!
//! The breakout FlatGraph is built once in the shared module (`shared/
//! breakout_real.rs`) and reused by both this test and the runnable example, so
//! the 11-node wiring is never duplicated.
use std::sync::Arc;
use aura_core::Timestamp;
use aura_ingest::{default_data_server, open_ohlc, DataServer, DEFAULT_DATA_PATH};
#[path = "../examples/shared/breakout_real.rs"]
mod breakout_real;
use breakout_real::*;
// September 2024 (inclusive), the same window the example demonstrates.
const YEAR: i32 = 2024;
const MONTH: u32 = 9;
/// Build the real breakout harness, run it over the epoch-ns [`Timestamp`]
/// window `[from, to]`, and return the folded `RunReport` plus the drained
/// per-bar `(held, equity)` series. A fresh build per call keeps the two
/// determinism runs disjoint (C1).
fn run_real(
server: &Arc<DataServer>,
from: Timestamp,
to: Timestamp,
) -> (aura_backtest::RunReport, Vec<(f64, f64)>) {
let sources =
open_ohlc(server, SYMBOL, from, to).expect("GER40 has data in the Sept-2024 window");
let (mut h, taps) = build_harness();
h.run(sources);
// Drain the trace once; fold the report from the same trace via the shared
// helper so the mpsc channels are consumed exactly once and the report shape
// matches the example's byte-for-byte.
let trace = drain_trace(&taps);
let report = report_from_trace(&trace, from, to);
let series: Vec<(f64, f64)> = trace.iter().map(|b| (b.held, b.equity)).collect();
(report, series)
}
/// Property: the real-bar GER40 breakout harness runs end-to-end over a real
/// data-server month and is **deterministic** (C1) — two disjoint runs over the
/// byte-identical archive window produce bit-identical reports AND bit-identical
/// recorded series. Also pins two observable invariants of the composed
/// vocabulary on real data: the metrics are finite, and the Latch output
/// (`held`) is *exactly* 0.0 or 1.0 every bar (a binary exposure register, never
/// a fractional or NaN value). This protects the whole node composition —
/// Resample / Delay / Gt / Session / EqConst / And / Latch / SimBroker — against
/// any regression that would only surface on real (irregular, gap-laden) M1
/// data, which the synthetic single-session capstone cannot reach.
#[test]
fn ger40_breakout_real_bars_run_is_deterministic() {
let server = default_data_server();
if !server.has_symbol(SYMBOL) {
eprintln!("skip: no local data at {DEFAULT_DATA_PATH} (symbol {SYMBOL} absent)");
return; // hermetic elsewhere; exercises the real path where files exist
}
let (from, to) = utc_month_window(YEAR, MONTH);
let (r1, s1) = run_real(&server, from, to);
assert!(!s1.is_empty(), "window resolved to zero bars");
// Metrics are finite — a backtest actually ran over real bars.
assert!(r1.metrics.total_pips.is_finite(), "total_pips finite");
assert!(r1.metrics.max_drawdown.is_finite(), "max_drawdown finite");
// Latch output is a binary exposure register: every recorded `held` is
// exactly 0.0 or 1.0 — never fractional, never NaN.
for (held, _) in &s1 {
assert!(
*held == 0.0 || *held == 1.0,
"held must be exactly 0.0 or 1.0 (Latch register), got {held}"
);
}
// C1 determinism: a fresh disjoint run over the identical window is
// bit-identical in both the folded report and the raw recorded series.
let (r2, s2) = run_real(&server, from, to);
assert_eq!(r1.to_json(), r2.to_json(), "report bit-identical across runs (C1)");
assert_eq!(s1, s2, "recorded (held, equity) series bit-identical across runs (C1)");
}