diff --git a/crates/aura-cli/src/binding.rs b/crates/aura-cli/src/binding.rs index ec24a28..88fb621 100644 --- a/crates/aura-cli/src/binding.rs +++ b/crates/aura-cli/src/binding.rs @@ -166,6 +166,17 @@ pub(crate) fn resolve_binding( \"price\" is the alias of \"close\", so the pair is ambiguous; rename one role" )); } + // Duplicate role names would lower to duplicate keyed feeds, which the by-name + // bind (`run_bound`) rejects as `DuplicateFeed`. The blueprint path does not + // enforce role-name uniqueness (only the construction op-script path does), so + // refuse here — a named refusal on every CLI run path, not a panic behind the + // `.expect()` the single-binding invariant relies on. + if let Some(dup) = first_duplicate_role(roles) { + return Err(format!( + "strategy \"{strategy}\" declares input role \"{dup}\" more than once — \ + input role names must be unique" + )); + } let mut entries: Vec = Vec::with_capacity(roles.len() + 1); for role in roles { let column = match overrides.get(&role.name) { @@ -200,6 +211,18 @@ pub(crate) fn resolve_binding( Ok(finish(entries)) } +/// The first role name that appears more than once in `roles`, in declaration +/// order, or `None` if every name is unique. +fn first_duplicate_role(roles: &[Role]) -> Option<&str> { + let mut seen = std::collections::BTreeSet::new(); + for r in roles { + if !seen.insert(r.name.as_str()) { + return Some(r.name.as_str()); + } + } + None +} + /// The lenient PROBE binding for the throwaway param-space wrap /// (`blueprint_axis_probe`): every unresolvable role falls back to the close /// column. The probe composite is built but never run over data — the @@ -358,6 +381,20 @@ mod tests { ); } + /// Two input roles with the same name would lower to a duplicate keyed feed; + /// `resolve_binding` refuses at the binding boundary (a named refusal, not a + /// `run_bound` `DuplicateFeed` panic behind the CLI's `.expect()`). + #[test] + fn duplicate_role_name_refuses() { + let err = + resolve_binding("x", &[role("high"), role("high")], &BTreeMap::new()).unwrap_err(); + assert_eq!( + err, + "strategy \"x\" declares input role \"high\" more than once — \ + input role names must be unique" + ); + } + /// A role literally named "close" overridden away from the close column /// would otherwise collide with `finish`'s synthesized close entry (two /// entries both named "close") — refused instead of double-naming. diff --git a/crates/aura-engine/src/harness.rs b/crates/aura-engine/src/harness.rs index 85b70d1..a40dbc1 100644 --- a/crates/aura-engine/src/harness.rs +++ b/crates/aura-engine/src/harness.rs @@ -758,6 +758,20 @@ mod tests { ); } + /// The named-error prose a keyed-supply caller renders (the by-name refusal + /// surface for decoupled-supply callers, #124/#275). + #[test] + fn source_bind_error_display_names_the_role() { + assert_eq!( + SourceBindError::MissingFeed { role: "close".into() }.to_string(), + "the graph declares source role \"close\" but the supply provides no such feed" + ); + assert_eq!( + SourceBindError::DuplicateFeed { role: "high".into() }.to_string(), + "the supply provides feed \"high\" more than once" + ); + } + #[test] fn window_of_folds_union_extent_across_sources() { let a: Box = Box::new(VecSource::new(f64_stream(&[(10, 1.0), (40, 2.0)])));