huskies: merge 677_refactor_reject_promotion_to_current_coder_of_work_items_with_junk_only_acceptance_criteria
This commit is contained in:
@@ -29,9 +29,26 @@ pub(crate) fn tool_create_spike(args: &Value, ctx: &AppContext) -> Result<String
|
||||
.and_then(|v| v.as_str())
|
||||
.ok_or("Missing required argument: name")?;
|
||||
let description = args.get("description").and_then(|v| v.as_str());
|
||||
let acceptance_criteria: Vec<String> = args
|
||||
.get("acceptance_criteria")
|
||||
.and_then(|v| serde_json::from_value(v.clone()).ok())
|
||||
.ok_or("Missing required argument: acceptance_criteria")?;
|
||||
if acceptance_criteria.is_empty() {
|
||||
return Err("acceptance_criteria must contain at least one entry".to_string());
|
||||
}
|
||||
const JUNK_AC: &[&str] = &["", "todo", "tbd", "fixme", "xxx", "???"];
|
||||
let all_junk = acceptance_criteria
|
||||
.iter()
|
||||
.all(|ac| JUNK_AC.contains(&ac.trim().to_lowercase().as_str()));
|
||||
if all_junk {
|
||||
return Err(
|
||||
"acceptance_criteria must contain at least one real entry (not just TODO/TBD/FIXME/XXX/???)."
|
||||
.to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
let root = ctx.state.get_project_root()?;
|
||||
let spike_id = create_spike_file(&root, name, description)?;
|
||||
let spike_id = create_spike_file(&root, name, description, &acceptance_criteria)?;
|
||||
|
||||
Ok(format!("Created spike: {spike_id}"))
|
||||
}
|
||||
@@ -72,7 +89,8 @@ mod tests {
|
||||
fn tool_create_spike_rejects_empty_name() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let ctx = test_ctx(tmp.path());
|
||||
let result = tool_create_spike(&json!({"name": "!!!"}), &ctx);
|
||||
let result =
|
||||
tool_create_spike(&json!({"name": "!!!", "acceptance_criteria": ["AC"]}), &ctx);
|
||||
assert!(result.is_err());
|
||||
assert!(result.unwrap_err().contains("alphanumeric"));
|
||||
}
|
||||
@@ -83,7 +101,11 @@ mod tests {
|
||||
let ctx = test_ctx(tmp.path());
|
||||
|
||||
let result = tool_create_spike(
|
||||
&json!({"name": "Compare Encoders", "description": "Which encoder is fastest?"}),
|
||||
&json!({
|
||||
"name": "Compare Encoders",
|
||||
"description": "Which encoder is fastest?",
|
||||
"acceptance_criteria": ["Encoder comparison is documented"]
|
||||
}),
|
||||
&ctx,
|
||||
)
|
||||
.unwrap();
|
||||
@@ -105,7 +127,11 @@ mod tests {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let ctx = test_ctx(tmp.path());
|
||||
|
||||
let result = tool_create_spike(&json!({"name": "My Spike"}), &ctx).unwrap();
|
||||
let result = tool_create_spike(
|
||||
&json!({"name": "My Spike", "acceptance_criteria": ["Spike findings documented"]}),
|
||||
&ctx,
|
||||
)
|
||||
.unwrap();
|
||||
assert!(
|
||||
result.contains("_spike_my_spike"),
|
||||
"result should contain spike ID: {result}"
|
||||
@@ -118,4 +144,70 @@ mod tests {
|
||||
assert!(contents.starts_with("---\nname: \"My Spike\"\n---"));
|
||||
assert!(contents.contains("## Question\n\n- TBD\n"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tool_create_spike_rejects_missing_acceptance_criteria() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let ctx = test_ctx(tmp.path());
|
||||
let result = tool_create_spike(&json!({"name": "My Spike"}), &ctx);
|
||||
assert!(result.is_err());
|
||||
assert!(
|
||||
result.unwrap_err().contains("acceptance_criteria"),
|
||||
"error should mention acceptance_criteria"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tool_create_spike_rejects_empty_acceptance_criteria() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let ctx = test_ctx(tmp.path());
|
||||
let result = tool_create_spike(
|
||||
&json!({"name": "My Spike", "acceptance_criteria": []}),
|
||||
&ctx,
|
||||
);
|
||||
assert!(result.is_err());
|
||||
assert!(
|
||||
result.unwrap_err().contains("acceptance_criteria"),
|
||||
"error should mention acceptance_criteria"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tool_create_spike_accepts_single_criterion() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let ctx = test_ctx(tmp.path());
|
||||
let result = tool_create_spike(
|
||||
&json!({"name": "Single Criterion Spike", "acceptance_criteria": ["Findings documented"]}),
|
||||
&ctx,
|
||||
);
|
||||
assert!(result.is_ok(), "expected ok: {result:?}");
|
||||
assert!(result.unwrap().contains("Created spike:"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tool_create_spike_rejects_all_junk_acceptance_criteria() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let ctx = test_ctx(tmp.path());
|
||||
let result = tool_create_spike(
|
||||
&json!({"name": "Junk Spike", "acceptance_criteria": ["TODO", "TBD"]}),
|
||||
&ctx,
|
||||
);
|
||||
assert!(result.is_err());
|
||||
assert!(
|
||||
result.unwrap_err().contains("real entry"),
|
||||
"error should mention real entry"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tool_create_spike_accepts_mixed_junk_and_real_acceptance_criteria() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let ctx = test_ctx(tmp.path());
|
||||
let result = tool_create_spike(
|
||||
&json!({"name": "Mixed Spike", "acceptance_criteria": ["TODO", "Real AC"]}),
|
||||
&ctx,
|
||||
);
|
||||
assert!(result.is_ok(), "expected ok for mixed AC: {result:?}");
|
||||
assert!(result.unwrap().contains("Created spike:"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user