fix: register outside a project refuses instead of creating a stray store (closes #305)
register_process and register_campaign now carry the same env.provenance() no-project guard as their show/runs siblings, refusing with exit 1 and the missing-Aura.toml prose instead of letting Env::runs_root()'s relative fallback materialise ./runs/ in an innocent cwd. Five pre-existing register tests ran from a bare temp cwd and were reaching their asserted behaviour only through this bug; they now run inside the fresh_project() fixture, preserving their original property (content addressing, intrinsic-validation refusals) in a real project. Verified: the RED E2E test (register_outside_a_project_refuses_and_ leaves_no_store, both verbs, refusal + no side-effect store) observed GREEN by the loop's independent verify alongside the full suite.
This commit is contained in:
@@ -250,6 +250,15 @@ fn validate_process_file(file: &PathBuf) -> Result<(), String> {
|
||||
}
|
||||
|
||||
fn register_process(file: &PathBuf, env: &Env) -> Result<(), String> {
|
||||
if env.provenance().is_none() {
|
||||
let cwd = std::env::current_dir()
|
||||
.map(|d| d.display().to_string())
|
||||
.unwrap_or_default();
|
||||
return Err(format!(
|
||||
"process register needs a project: the document store lives under the \
|
||||
project store root (no Aura.toml found up from {cwd})"
|
||||
));
|
||||
}
|
||||
let doc = parse_valid_process(file)
|
||||
.map_err(|m| format!("refusing to register: {m}"))?;
|
||||
let canonical = process_to_json(&doc);
|
||||
@@ -580,6 +589,15 @@ fn validate_campaign_file(file: &PathBuf, env: &Env) -> Result<(), String> {
|
||||
}
|
||||
|
||||
fn register_campaign(file: &PathBuf, env: &Env) -> Result<(), String> {
|
||||
if env.provenance().is_none() {
|
||||
let cwd = std::env::current_dir()
|
||||
.map(|d| d.display().to_string())
|
||||
.unwrap_or_default();
|
||||
return Err(format!(
|
||||
"campaign register needs a project: the document store lives under the \
|
||||
project store root (no Aura.toml found up from {cwd})"
|
||||
));
|
||||
}
|
||||
let doc = parse_valid_campaign(file)
|
||||
.map_err(|m| format!("refusing to register: {m}"))?;
|
||||
let canonical = campaign_to_json(&doc);
|
||||
|
||||
@@ -282,7 +282,8 @@ fn process_introspect_metrics_plus_another_mode_is_usage_exit_2() {
|
||||
|
||||
#[test]
|
||||
fn process_register_stores_content_addressed_under_runs_root() {
|
||||
let dir = temp_cwd("process-register");
|
||||
// #305: register needs a project (the show/runs guard family).
|
||||
let (dir, _fixture) = fresh_project();
|
||||
write_doc(&dir, "p.process.json", PROCESS_DOC);
|
||||
let (out, code) = run_code_in(&dir, &["process", "register", "p.process.json"]);
|
||||
assert_eq!(code, Some(0), "stdout/stderr: {out}");
|
||||
@@ -1067,7 +1068,8 @@ fn campaign_introspect_content_id_prints_hash() {
|
||||
|
||||
#[test]
|
||||
fn campaign_register_stores_content_addressed_under_runs_root() {
|
||||
let dir = temp_cwd("campaign-register");
|
||||
// #305: register needs a project (the show/runs guard family).
|
||||
let (dir, _fixture) = fresh_project();
|
||||
write_doc(&dir, "c.campaign.json", CAMPAIGN_DOC);
|
||||
let (out, code) = run_code_in(&dir, &["campaign", "register", "c.campaign.json"]);
|
||||
assert_eq!(code, Some(0), "stdout/stderr: {out}");
|
||||
@@ -1202,7 +1204,8 @@ fn wrong_kind_refusal_names_the_kind_key() {
|
||||
/// have already made.
|
||||
#[test]
|
||||
fn campaign_register_refuses_invalid_document_and_writes_nothing() {
|
||||
let dir = temp_cwd("campaign-register-invalid");
|
||||
// #305: register needs a project (the show/runs guard family).
|
||||
let (dir, _fixture) = fresh_project();
|
||||
let bad = CAMPAIGN_DOC.replacen(r#""values": [8]"#, r#""values": []"#, 1);
|
||||
write_doc(&dir, "bad.campaign.json", &bad);
|
||||
let (out, code) = run_code_in(&dir, &["campaign", "register", "bad.campaign.json"]);
|
||||
@@ -1223,7 +1226,8 @@ fn campaign_register_refuses_invalid_document_and_writes_nothing() {
|
||||
/// would silently persist an unenforceable risk regime.
|
||||
#[test]
|
||||
fn campaign_register_refuses_invalid_risk_section_and_writes_nothing() {
|
||||
let dir = temp_cwd("campaign-register-invalid-risk");
|
||||
// #305: register needs a project (the show/runs guard family).
|
||||
let (dir, _fixture) = fresh_project();
|
||||
let bad = CAMPAIGN_DOC.replacen(
|
||||
"\"seed\": 1,",
|
||||
"\"seed\": 1,\n \"risk\": [ { \"vol\": { \"length\": 0, \"k\": 2.0 } } ],",
|
||||
@@ -1250,7 +1254,8 @@ fn campaign_register_refuses_invalid_risk_section_and_writes_nothing() {
|
||||
/// precedent).
|
||||
#[test]
|
||||
fn campaign_register_refuses_invalid_cost_section_and_writes_nothing() {
|
||||
let dir = temp_cwd("campaign-register-invalid-cost");
|
||||
// #305: register needs a project (the show/runs guard family).
|
||||
let (dir, _fixture) = fresh_project();
|
||||
let bad = CAMPAIGN_DOC.replacen(
|
||||
"\"seed\": 1,",
|
||||
"\"seed\": 1,\n \"cost\": [ { \"constant\": { \"cost_per_trade\": -2.0 } } ],",
|
||||
|
||||
Reference in New Issue
Block a user