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,23 @@ pub(crate) fn tool_create_refactor(args: &Value, ctx: &AppContext) -> Result<Str
|
||||
.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: Option<Vec<String>> = args
|
||||
let acceptance_criteria: Vec<String> = args
|
||||
.get("acceptance_criteria")
|
||||
.and_then(|v| serde_json::from_value(v.clone()).ok());
|
||||
.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 depends_on: Option<Vec<u32>> = args
|
||||
.get("depends_on")
|
||||
.and_then(|v| serde_json::from_value(v.clone()).ok());
|
||||
@@ -41,7 +55,7 @@ pub(crate) fn tool_create_refactor(args: &Value, ctx: &AppContext) -> Result<Str
|
||||
&root,
|
||||
name,
|
||||
description,
|
||||
acceptance_criteria.as_deref(),
|
||||
Some(&acceptance_criteria),
|
||||
depends_on.as_deref(),
|
||||
)?;
|
||||
|
||||
@@ -59,3 +73,76 @@ pub(crate) fn tool_list_refactors(ctx: &AppContext) -> Result<String, String> {
|
||||
))
|
||||
.map_err(|e| format!("Serialization error: {e}"))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::http::test_helpers::test_ctx;
|
||||
use serde_json::json;
|
||||
|
||||
#[test]
|
||||
fn tool_create_refactor_rejects_missing_acceptance_criteria() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let ctx = test_ctx(tmp.path());
|
||||
let result = tool_create_refactor(&json!({"name": "My Refactor"}), &ctx);
|
||||
assert!(result.is_err());
|
||||
assert!(
|
||||
result.unwrap_err().contains("acceptance_criteria"),
|
||||
"error should mention acceptance_criteria"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tool_create_refactor_rejects_empty_acceptance_criteria() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let ctx = test_ctx(tmp.path());
|
||||
let result = tool_create_refactor(
|
||||
&json!({"name": "My Refactor", "acceptance_criteria": []}),
|
||||
&ctx,
|
||||
);
|
||||
assert!(result.is_err());
|
||||
assert!(
|
||||
result.unwrap_err().contains("acceptance_criteria"),
|
||||
"error should mention acceptance_criteria"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tool_create_refactor_accepts_single_criterion() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let ctx = test_ctx(tmp.path());
|
||||
let result = tool_create_refactor(
|
||||
&json!({"name": "Single Criterion Refactor", "acceptance_criteria": ["Code is clean"]}),
|
||||
&ctx,
|
||||
);
|
||||
assert!(result.is_ok(), "expected ok: {result:?}");
|
||||
assert!(result.unwrap().contains("Created refactor:"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tool_create_refactor_rejects_all_junk_acceptance_criteria() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let ctx = test_ctx(tmp.path());
|
||||
let result = tool_create_refactor(
|
||||
&json!({"name": "Junk Refactor", "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_refactor_accepts_mixed_junk_and_real_acceptance_criteria() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let ctx = test_ctx(tmp.path());
|
||||
let result = tool_create_refactor(
|
||||
&json!({"name": "Mixed Refactor", "acceptance_criteria": ["TODO", "Real AC"]}),
|
||||
&ctx,
|
||||
);
|
||||
assert!(result.is_ok(), "expected ok for mixed AC: {result:?}");
|
||||
assert!(result.unwrap().contains("Created refactor:"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user