fix(cli): gate dissolved verbs on project presence, matching campaign run (#218)
A dissolved verb (sweep/generalize/walkforward/mc --real) run outside a project silently created a content-addressed runs/ store in the cwd and ran to completion — Env::runs_root falls back to a relative ./runs with no project, and the four dispatchers skipped the provenance gate that `campaign run` applies first (campaign_run.rs:322-333). It is now refused up front: one gate in the shared validate_and_register_axes chokepoint, after axis validation and before the first store touch (put_blueprint), via a new AxisRegisterError::NoProject mapped to exit 1 carrying "<verb> needs a project …". Placement is load-bearing: axis validation (an UnknownAxis usage error, exit 2) stays ahead of the project gate, so a malformed --axis still exits 2 regardless of project — a malformed command is malformed in any environment and already writes no store. Four per-verb pins assert the refusal (exit 1, "needs a project", no store); the six exit-2 usage-refusal tests stay green. Workspace suite green (62 groups / 0 failed), clippy -D warnings clean. closes #218
This commit is contained in:
@@ -2487,13 +2487,16 @@ fn parse_axes(
|
||||
Ok(axes)
|
||||
}
|
||||
|
||||
/// The two distinguishable ways `validate_and_register_axes` can fail, carrying
|
||||
/// the two distinct exit codes its four call sites (sweep/generalize/walkforward/mc)
|
||||
/// preserved before the dedup: an unknown axis name is a usage error (exit 2, echoed
|
||||
/// before the archive is touched); a registry write failure is a runtime error (exit 1).
|
||||
/// The three distinguishable ways `validate_and_register_axes` can fail: an
|
||||
/// unknown axis name is a usage error (exit 2, echoed before the archive is
|
||||
/// touched); a registry write failure is a runtime error (exit 1); running
|
||||
/// outside a project (no `Aura.toml` found up from cwd, #218's gate) is also
|
||||
/// a runtime error (exit 1) — the strategy document cannot resolve against a
|
||||
/// project store/vocabulary that doesn't exist.
|
||||
enum AxisRegisterError {
|
||||
UnknownAxis(String),
|
||||
Registry(String),
|
||||
NoProject(String),
|
||||
}
|
||||
|
||||
/// Validate every `--axis` name against the blueprint's WRAPPED probe namespace
|
||||
@@ -2507,6 +2510,7 @@ enum AxisRegisterError {
|
||||
/// same block", rule-of-three now exceeded 4x).
|
||||
#[allow(clippy::type_complexity)]
|
||||
fn validate_and_register_axes(
|
||||
verb: &str,
|
||||
doc: &str,
|
||||
axes: &[(String, Vec<Scalar>)],
|
||||
env: &project::Env,
|
||||
@@ -2521,6 +2525,15 @@ fn validate_and_register_axes(
|
||||
)));
|
||||
}
|
||||
}
|
||||
if env.provenance().is_none() {
|
||||
let cwd = std::env::current_dir()
|
||||
.map(|d| d.display().to_string())
|
||||
.unwrap_or_default();
|
||||
return Err(AxisRegisterError::NoProject(format!(
|
||||
"{verb} needs a project: strategies resolve against the project \
|
||||
store and vocabulary (no Aura.toml found up from {cwd})"
|
||||
)));
|
||||
}
|
||||
let blueprint = blueprint_from_json(doc, &|t| env.resolve(t))
|
||||
.expect("doc parse-validated at the dispatch boundary");
|
||||
let canonical = blueprint_to_json(&blueprint).expect("a loaded blueprint re-serializes");
|
||||
@@ -2538,7 +2551,8 @@ fn validate_and_register_axes(
|
||||
/// Exit-map for a `validate_and_register_axes` failure — the stderr line and
|
||||
/// exit code every campaign dispatcher (sweep/generalize/walkforward/mc)
|
||||
/// preserves: an unknown axis is a usage error (exit 2, echoed before the
|
||||
/// archive is touched), a registry write failure a runtime error (exit 1).
|
||||
/// archive is touched); a registry write failure or a missing project (no
|
||||
/// `Aura.toml` found up from cwd, #218's gate) is a runtime error (exit 1).
|
||||
fn exit_axis_register_error(e: AxisRegisterError) -> ! {
|
||||
match e {
|
||||
AxisRegisterError::UnknownAxis(m) => {
|
||||
@@ -2549,6 +2563,10 @@ fn exit_axis_register_error(e: AxisRegisterError) -> ! {
|
||||
eprintln!("aura: {m}");
|
||||
std::process::exit(1)
|
||||
}
|
||||
AxisRegisterError::NoProject(m) => {
|
||||
eprintln!("aura: {m}");
|
||||
std::process::exit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2702,7 +2720,7 @@ fn dispatch_generalize(a: GeneralizeCmd, env: &project::Env) {
|
||||
std::process::exit(2);
|
||||
}
|
||||
}
|
||||
let (canonical, raw_axes) = validate_and_register_axes(&doc, &axes, env)
|
||||
let (canonical, raw_axes) = validate_and_register_axes("generalize", &doc, &axes, env)
|
||||
.unwrap_or_else(|e| exit_axis_register_error(e));
|
||||
// Window: the explicit --from/--to when both present (byte-identical to the
|
||||
// retired welded path, verified by the exact-grade anchor); otherwise the
|
||||
@@ -2843,7 +2861,7 @@ fn dispatch_sweep(a: SweepCmd, env: &project::Env) {
|
||||
// Axis validation + canonicalize/register + the wrapped->raw
|
||||
// strip are single-sourced in `validate_and_register_axes`
|
||||
// (data-free, so this fires before the archive is touched).
|
||||
let (canonical, raw_axes) = validate_and_register_axes(&doc, &axes, env)
|
||||
let (canonical, raw_axes) = validate_and_register_axes("sweep", &doc, &axes, env)
|
||||
.unwrap_or_else(|e| exit_axis_register_error(e));
|
||||
let symbol = symbol.clone();
|
||||
// Archive-clipped Unix-ms window; the ns->ms seam-crossing
|
||||
@@ -2924,7 +2942,7 @@ fn dispatch_walkforward(a: WalkforwardCmd, env: &project::Env) {
|
||||
// Axis validation + canonicalize/register + the wrapped->raw
|
||||
// strip are single-sourced in `validate_and_register_axes`
|
||||
// (data-free, so this fires before the archive is touched).
|
||||
let (canonical, raw_axes) = validate_and_register_axes(&doc, &axes, env)
|
||||
let (canonical, raw_axes) = validate_and_register_axes("walkforward", &doc, &axes, env)
|
||||
.unwrap_or_else(|e| exit_axis_register_error(e));
|
||||
// Unlike `dispatch_generalize` (a single run per instrument, insensitive
|
||||
// to a day's edge shift), `blueprint_walkforward_family` sources its span
|
||||
@@ -3027,7 +3045,7 @@ fn dispatch_mc(a: McCmd, env: &project::Env) {
|
||||
// Axis validation + canonicalize/register + the wrapped->raw
|
||||
// strip are single-sourced in `validate_and_register_axes`
|
||||
// (data-free, so this fires before the archive is touched).
|
||||
let (canonical, raw_axes) = validate_and_register_axes(&doc, &axes, env)
|
||||
let (canonical, raw_axes) = validate_and_register_axes("mc", &doc, &axes, env)
|
||||
.unwrap_or_else(|e| exit_axis_register_error(e));
|
||||
// `blueprint_walkforward_family` sources its span from
|
||||
// `DataSource::wf_full_span`, which for Real ALWAYS clips `--from`/`--to`
|
||||
|
||||
Reference in New Issue
Block a user