huskies: merge 677_refactor_reject_promotion_to_current_coder_of_work_items_with_junk_only_acceptance_criteria
This commit is contained in:
@@ -44,9 +44,23 @@ pub(crate) fn tool_create_bug(args: &Value, ctx: &AppContext) -> Result<String,
|
||||
.get("expected_result")
|
||||
.and_then(|v| v.as_str())
|
||||
.ok_or("Missing required argument: expected_result")?;
|
||||
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());
|
||||
@@ -59,7 +73,7 @@ pub(crate) fn tool_create_bug(args: &Value, ctx: &AppContext) -> Result<String,
|
||||
steps_to_reproduce,
|
||||
actual_result,
|
||||
expected_result,
|
||||
acceptance_criteria.as_deref(),
|
||||
Some(&acceptance_criteria),
|
||||
depends_on.as_deref(),
|
||||
)?;
|
||||
|
||||
@@ -236,7 +250,8 @@ mod tests {
|
||||
"description": "The app crashes on login.",
|
||||
"steps_to_reproduce": "1. Open app\n2. Click login",
|
||||
"actual_result": "500 error",
|
||||
"expected_result": "Successful login"
|
||||
"expected_result": "Successful login",
|
||||
"acceptance_criteria": ["Login succeeds without error"]
|
||||
}),
|
||||
&ctx,
|
||||
)
|
||||
@@ -300,6 +315,111 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tool_create_bug_rejects_missing_acceptance_criteria() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let ctx = test_ctx(tmp.path());
|
||||
let result = tool_create_bug(
|
||||
&json!({
|
||||
"name": "Some Bug",
|
||||
"description": "d",
|
||||
"steps_to_reproduce": "s",
|
||||
"actual_result": "a",
|
||||
"expected_result": "e"
|
||||
}),
|
||||
&ctx,
|
||||
);
|
||||
assert!(result.is_err());
|
||||
assert!(
|
||||
result.unwrap_err().contains("acceptance_criteria"),
|
||||
"error should mention acceptance_criteria"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tool_create_bug_rejects_empty_acceptance_criteria() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let ctx = test_ctx(tmp.path());
|
||||
let result = tool_create_bug(
|
||||
&json!({
|
||||
"name": "Some Bug",
|
||||
"description": "d",
|
||||
"steps_to_reproduce": "s",
|
||||
"actual_result": "a",
|
||||
"expected_result": "e",
|
||||
"acceptance_criteria": []
|
||||
}),
|
||||
&ctx,
|
||||
);
|
||||
assert!(result.is_err());
|
||||
assert!(
|
||||
result.unwrap_err().contains("acceptance_criteria"),
|
||||
"error should mention acceptance_criteria"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tool_create_bug_accepts_single_criterion() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
setup_git_repo_in(tmp.path());
|
||||
let ctx = test_ctx(tmp.path());
|
||||
let result = tool_create_bug(
|
||||
&json!({
|
||||
"name": "Single Criterion Bug",
|
||||
"description": "d",
|
||||
"steps_to_reproduce": "s",
|
||||
"actual_result": "a",
|
||||
"expected_result": "e",
|
||||
"acceptance_criteria": ["Bug is fixed"]
|
||||
}),
|
||||
&ctx,
|
||||
);
|
||||
assert!(result.is_ok(), "expected ok: {result:?}");
|
||||
assert!(result.unwrap().contains("Created bug:"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tool_create_bug_rejects_all_junk_acceptance_criteria() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let ctx = test_ctx(tmp.path());
|
||||
let result = tool_create_bug(
|
||||
&json!({
|
||||
"name": "Junk Bug",
|
||||
"description": "d",
|
||||
"steps_to_reproduce": "s",
|
||||
"actual_result": "a",
|
||||
"expected_result": "e",
|
||||
"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_bug_accepts_mixed_junk_and_real_acceptance_criteria() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
setup_git_repo_in(tmp.path());
|
||||
let ctx = test_ctx(tmp.path());
|
||||
let result = tool_create_bug(
|
||||
&json!({
|
||||
"name": "Mixed Bug",
|
||||
"description": "d",
|
||||
"steps_to_reproduce": "s",
|
||||
"actual_result": "a",
|
||||
"expected_result": "e",
|
||||
"acceptance_criteria": ["TODO", "Real AC"]
|
||||
}),
|
||||
&ctx,
|
||||
);
|
||||
assert!(result.is_ok(), "expected ok for mixed AC: {result:?}");
|
||||
assert!(result.unwrap().contains("Created bug:"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tool_close_bug_missing_bug_id() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
|
||||
Reference in New Issue
Block a user