diff --git a/server/src/http/mcp/mod.rs b/server/src/http/mcp/mod.rs index 3fda0d77..1d53e3e1 100644 --- a/server/src/http/mcp/mod.rs +++ b/server/src/http/mcp/mod.rs @@ -676,6 +676,11 @@ fn handle_tools_list(id: Option) -> JsonRpcResponse { "type": "array", "items": { "type": "string" }, "description": "Optional list of acceptance criteria for the fix" + }, + "depends_on": { + "type": "array", + "items": { "type": "integer" }, + "description": "Optional list of story numbers this bug depends on (e.g. [42, 43]). Persisted as depends_on in YAML front matter." } }, "required": ["name", "description", "steps_to_reproduce", "actual_result", "expected_result"] @@ -707,6 +712,11 @@ fn handle_tools_list(id: Option) -> JsonRpcResponse { "type": "array", "items": { "type": "string" }, "description": "Optional list of acceptance criteria" + }, + "depends_on": { + "type": "array", + "items": { "type": "integer" }, + "description": "Optional list of story numbers this refactor depends on (e.g. [42, 43]). Persisted as depends_on in YAML front matter." } }, "required": ["name"] diff --git a/server/src/http/mcp/story_tools.rs b/server/src/http/mcp/story_tools.rs index badc1b9b..2fd3d148 100644 --- a/server/src/http/mcp/story_tools.rs +++ b/server/src/http/mcp/story_tools.rs @@ -489,6 +489,9 @@ pub(super) fn tool_create_bug(args: &Value, ctx: &AppContext) -> Result> = args .get("acceptance_criteria") .and_then(|v| serde_json::from_value(v.clone()).ok()); + let depends_on: Option> = args + .get("depends_on") + .and_then(|v| serde_json::from_value(v.clone()).ok()); let root = ctx.state.get_project_root()?; let bug_id = create_bug_file( @@ -499,6 +502,7 @@ pub(super) fn tool_create_bug(args: &Value, ctx: &AppContext) -> Result Result> = args .get("acceptance_criteria") .and_then(|v| serde_json::from_value(v.clone()).ok()); + let depends_on: Option> = args + .get("depends_on") + .and_then(|v| serde_json::from_value(v.clone()).ok()); let root = ctx.state.get_project_root()?; - let refactor_id = - create_refactor_file(&root, name, description, acceptance_criteria.as_deref())?; + let refactor_id = create_refactor_file( + &root, + name, + description, + acceptance_criteria.as_deref(), + depends_on.as_deref(), + )?; Ok(format!("Created refactor: {refactor_id}")) } diff --git a/server/src/http/workflow/bug_ops.rs b/server/src/http/workflow/bug_ops.rs index 46ee6647..c9dac045 100644 --- a/server/src/http/workflow/bug_ops.rs +++ b/server/src/http/workflow/bug_ops.rs @@ -8,6 +8,7 @@ use super::{next_item_number, slugify_name, write_story_content}; /// /// Also writes to the filesystem for backwards compatibility during migration. /// Returns the bug_id (e.g. `"4_bug_login_crash"`). +#[allow(clippy::too_many_arguments)] pub fn create_bug_file( root: &Path, name: &str, @@ -16,6 +17,7 @@ pub fn create_bug_file( actual_result: &str, expected_result: &str, acceptance_criteria: Option<&[String]>, + depends_on: Option<&[u32]>, ) -> Result { let bug_number = next_item_number(root)?; let slug = slugify_name(name); @@ -29,6 +31,10 @@ pub fn create_bug_file( let mut content = String::new(); content.push_str("---\n"); content.push_str(&format!("name: \"{}\"\n", name.replace('"', "\\\""))); + if let Some(deps) = depends_on.filter(|d| !d.is_empty()) { + let nums: Vec = deps.iter().map(|n| n.to_string()).collect(); + content.push_str(&format!("depends_on: [{}]\n", nums.join(", "))); + } content.push_str("---\n\n"); content.push_str(&format!("# Bug {bug_number}: {name}\n\n")); content.push_str("## Description\n\n"); @@ -113,6 +119,7 @@ pub fn create_refactor_file( name: &str, description: Option<&str>, acceptance_criteria: Option<&[String]>, + depends_on: Option<&[u32]>, ) -> Result { let refactor_number = next_item_number(root)?; let slug = slugify_name(name); @@ -126,6 +133,10 @@ pub fn create_refactor_file( let mut content = String::new(); content.push_str("---\n"); content.push_str(&format!("name: \"{}\"\n", name.replace('"', "\\\""))); + if let Some(deps) = depends_on.filter(|d| !d.is_empty()) { + let nums: Vec = deps.iter().map(|n| n.to_string()).collect(); + content.push_str(&format!("depends_on: [{}]\n", nums.join(", "))); + } content.push_str("---\n\n"); content.push_str(&format!("# Refactor {refactor_number}: {name}\n\n")); content.push_str("## Current State\n\n"); @@ -406,6 +417,7 @@ mod tests { "Page crashes with 500 error", "Login succeeds", Some(&["Login form submits without error".to_string()]), + None, ) .unwrap(); @@ -455,6 +467,7 @@ mod tests { "actual", "expected", None, + None, ); assert!(result.is_err()); assert!(result.unwrap_err().contains("alphanumeric")); @@ -473,6 +486,7 @@ mod tests { "actual", "expected", None, + None, ) .unwrap(); @@ -618,4 +632,126 @@ mod tests { "expected spike number >= 7051, got: {spike_id}" ); } + + // ── Bug 640: create_bug_file / create_refactor_file depends_on tests ──────── + + #[test] + fn create_bug_file_with_depends_on_writes_front_matter_array() { + let tmp = tempfile::tempdir().unwrap(); + setup_git_repo(tmp.path()); + + let bug_id = create_bug_file( + tmp.path(), + "Dep Bug", + "desc", + "steps", + "actual", + "expected", + None, + Some(&[42, 43]), + ) + .unwrap(); + + let contents = crate::db::read_content(&bug_id) + .or_else(|| { + let filepath = tmp + .path() + .join(format!(".huskies/work/1_backlog/{bug_id}.md")); + fs::read_to_string(filepath).ok() + }) + .expect("bug content should exist"); + + assert!( + contents.contains("depends_on: [42, 43]"), + "front matter should contain depends_on array: {contents}" + ); + assert!( + !contents.contains("depends_on: \"["), + "depends_on must not be quoted string: {contents}" + ); + + let meta = parse_front_matter(&contents).expect("front matter should be valid YAML"); + assert_eq!(meta.depends_on, Some(vec![42, 43])); + } + + #[test] + fn create_bug_file_without_depends_on_omits_field() { + let tmp = tempfile::tempdir().unwrap(); + setup_git_repo(tmp.path()); + + let bug_id = create_bug_file( + tmp.path(), + "No Dep Bug", + "desc", + "steps", + "actual", + "expected", + None, + None, + ) + .unwrap(); + + let contents = crate::db::read_content(&bug_id) + .or_else(|| { + let filepath = tmp + .path() + .join(format!(".huskies/work/1_backlog/{bug_id}.md")); + fs::read_to_string(filepath).ok() + }) + .expect("bug content should exist"); + + assert!( + !contents.contains("depends_on"), + "front matter must not contain depends_on when not provided: {contents}" + ); + } + + #[test] + fn create_refactor_file_with_depends_on_writes_front_matter_array() { + let tmp = tempfile::tempdir().unwrap(); + setup_git_repo(tmp.path()); + + let refactor_id = + create_refactor_file(tmp.path(), "Dep Refactor", None, None, Some(&[99])).unwrap(); + + let contents = crate::db::read_content(&refactor_id) + .or_else(|| { + let filepath = tmp + .path() + .join(format!(".huskies/work/1_backlog/{refactor_id}.md")); + fs::read_to_string(filepath).ok() + }) + .expect("refactor content should exist"); + + assert!( + contents.contains("depends_on: [99]"), + "front matter should contain depends_on array: {contents}" + ); + + let meta = parse_front_matter(&contents).expect("front matter should be valid YAML"); + assert_eq!(meta.depends_on, Some(vec![99])); + } + + #[test] + fn create_refactor_file_without_depends_on_omits_field() { + let tmp = tempfile::tempdir().unwrap(); + setup_git_repo(tmp.path()); + + let refactor_id = + create_refactor_file(tmp.path(), "No Dep Refactor", None, None, None).unwrap(); + + let contents = crate::db::read_content(&refactor_id) + .or_else(|| { + let filepath = tmp + .path() + .join(format!(".huskies/work/1_backlog/{refactor_id}.md")); + fs::read_to_string(filepath).ok() + }) + .expect("refactor content should exist"); + + assert!( + !contents.contains("depends_on"), + "front matter must not contain depends_on when not provided: {contents}" + ); + } }