Files
Brummel 41cbb5506f feat(aura-engine): name the composite boundary — input roles + param aliases
Brings the other two composite-boundary edge-kinds to the named-projection
shape #40 gave outputs. input_roles changes from a bare Vec<Vec<Target>>
to Vec<Role { name, targets }> (rendered [in:<name>]); a composite gains
params: Vec<ParamAlias { name, node, slot }> that relabels an interior
leaf param slot's surface name in param_space() (rendered [param:<name>]).

Param aliasing is a PURE NAMING OVERLAY, not curation (the load-bearing
decision, per spec 0019): every interior param slot stays in param_space()
and sweepable; the alias only relabels in place, never reorders or hides.
Proven empirically — the MACD run is byte-identical (total_pips
0.1637945563898923, 3 sign flips), only the param labels improved:
param_space() now surfaces [macd.fast, macd.slow, macd.signal] instead of
three indistinguishable macd.length, and the manifest reads ema_fast/
ema_slow/ema_signal.

C23 honoured: role/param/output names are non-load-bearing debug symbols
dropped at lowering; identity is positional (role index, param slot,
output field). compiled_view_golden is byte-identical (verified: the
golden region is untouched in the diff). An out-of-range alias (missing/
non-leaf node or slot past the leaf's param count) is rejected at
compile_with_params as BadInteriorIndex, mirroring the output range-check
(no new variant). Orthogonal to #36 — purely additive at the composite
level.

Aliasing is demonstrated on the CLI MACD site only (the spec's worked
example + a new E2E test macd_param_space_surfaces_the_three_named_aliases);
sma_cross, the engine test fixtures, and the construction-layer fieldtests
get the forced role-name + empty params, so the param_space C23 anchor
goldens (param_space_mirrors_compiled_flat_node_param_order + siblings)
stay byte-identical.

Verification (orchestrator-run, not trusted from the agent report):
cargo build/test/clippy --workspace -D warnings all green (engine 66,
cli 12); the separate-workspace construction-layer fieldtest crate builds
(guards the #42 latent-drift recurrence); compiled_view_golden + MACD
determinism unchanged.

Two faithful repairs to the plan's literal test/code bodies, no semantic
change: the out-of-range test uses .err()/Some(BadInteriorIndex) (the Ok
arm Vec<Box<dyn Node>> is not Debug, so .unwrap_err() would not compile),
and the inline_composite destructure binds params as `param_aliases` to
avoid shadowing the injected `params: &[Scalar]` arg.

closes #41
2026-06-08 02:21:30 +02:00

124 lines
4.9 KiB
Rust

// Milestone fieldtest — axis (d): introspect a built Blueprint via the
// read-only graph-as-data accessors — can a consumer walk the graph as data
// WITHOUT reading engine internals?
//
// Accessors under test (all public, from rustdoc):
// Blueprint::nodes() / sources() / edges()
// Composite::name() / nodes() / edges() / input_roles() / output()
// BlueprintNode::{Leaf, Composite}; Node::label() on a boxed leaf
//
// Public interface only.
use aura_core::ScalarKind;
use aura_engine::{Blueprint, BlueprintNode, Composite, Edge, OutField, Role, SourceSpec, Target};
// NB (fieldtest finding): `aura_engine::ScalarKind` does NOT resolve — the
// construction surface (aura-engine) does not re-export the core scalar
// vocabulary (ScalarKind / Scalar / Firing) that a graph-builder needs. A
// downstream author building a Blueprint must reach into aura_core directly.
// Recorded as friction in the spec. `node.label()` below dispatches on the
// boxed leaf via the Node trait object without an explicit `use` of Node.
fn sma_cross() -> Composite {
Composite::new(
"sma_cross",
vec![
aura_std::Sma::factory().into(),
aura_std::Sma::factory().into(),
aura_std::Sub::factory().into(),
],
vec![
Edge { from: 0, to: 2, slot: 0, from_field: 0 },
Edge { from: 1, to: 2, slot: 1, from_field: 0 },
],
vec![Role {
name: "price".into(),
targets: vec![Target { node: 0, slot: 0 }, Target { node: 1, slot: 0 }],
}],
vec![],
vec![OutField { node: 2, field: 0, name: "out".into() }],
)
}
fn describe_node(prefix: &str, n: &BlueprintNode) {
match n {
BlueprintNode::Leaf(factory) => {
// A blueprint leaf is a value-empty LeafFactory (post cycle-0016): no
// built node, so no input/output schema yet — introspect its declared
// render label + tunable param count (inputs/outputs exist only after
// build, on the compiled flat node).
println!(
"{prefix}LEAF {:<14} params={}",
factory.label(),
factory.params().len()
);
}
BlueprintNode::Composite(c) => {
// output() is now a record (&[OutField]); render the whole field list
// (one entry today, but the type is the multi-field shape of #40).
let out_fields: Vec<(usize, usize)> =
c.output().iter().map(|f| (f.node, f.field)).collect();
println!(
"{prefix}COMPOSITE name={:?} interior_items={} roles={} out={:?}",
c.name(),
c.nodes().len(),
c.input_roles().len(),
out_fields,
);
for inner in c.nodes() {
describe_node(&format!("{prefix} "), inner);
}
for (r, role) in c.input_roles().iter().enumerate() {
println!("{prefix} role[{r}] {:?} fans into {:?}", role.name, role.targets);
}
for e in c.edges() {
println!("{prefix} interior edge {e:?}");
}
}
}
}
fn main() {
let bp = Blueprint::new(
vec![
BlueprintNode::Composite(sma_cross()),
aura_std::Exposure::factory().into(),
],
vec![SourceSpec {
kind: ScalarKind::F64,
targets: vec![Target { node: 0, slot: 0 }],
}],
vec![Edge { from: 0, to: 1, slot: 0, from_field: 0 }],
);
println!("== Blueprint graph-as-data walk ==");
println!("sources: {}", bp.sources().len());
for (i, s) in bp.sources().iter().enumerate() {
println!(" source[{i}] kind={:?} -> {:?}", s.kind, s.targets);
}
println!("top-level items: {}", bp.nodes().len());
for n in bp.nodes() {
describe_node(" ", n);
}
println!("top-level edges: {}", bp.edges().len());
for e in bp.edges() {
println!(" edge {e:?}");
}
// The walk must reach the interior of the composite purely through the
// public accessors — no engine internals.
let first = &bp.nodes()[0];
if let BlueprintNode::Composite(c) = first {
assert_eq!(c.name(), "sma_cross");
assert_eq!(c.nodes().len(), 3, "composite interior should have 3 items");
assert_eq!(c.input_roles().len(), 1, "one price role");
assert_eq!(c.input_roles()[0].name, "price", "the role carries its boundary name");
assert_eq!(c.input_roles()[0].targets.len(), 2, "price fans into both SMAs");
let out = c.output();
assert_eq!(out.len(), 1, "the cross re-exports one output field");
assert_eq!((out[0].node, out[0].field), (2, 0), "Sub output is the port");
println!("OK: walked the composite interior via public accessors only.");
} else {
panic!("expected composite as first item");
}
}