huskies: merge 640_bug_create_story_create_refactor_create_bug_silently_drop_the_depends_on_parameter

This commit is contained in:
dave
2026-04-25 19:33:38 +00:00
parent e4dd4bbe2c
commit 120745d102
3 changed files with 160 additions and 2 deletions
+10
View File
@@ -676,6 +676,11 @@ fn handle_tools_list(id: Option<Value>) -> JsonRpcResponse {
"type": "array", "type": "array",
"items": { "type": "string" }, "items": { "type": "string" },
"description": "Optional list of acceptance criteria for the fix" "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"] "required": ["name", "description", "steps_to_reproduce", "actual_result", "expected_result"]
@@ -707,6 +712,11 @@ fn handle_tools_list(id: Option<Value>) -> JsonRpcResponse {
"type": "array", "type": "array",
"items": { "type": "string" }, "items": { "type": "string" },
"description": "Optional list of acceptance criteria" "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"] "required": ["name"]
+14 -2
View File
@@ -489,6 +489,9 @@ pub(super) fn tool_create_bug(args: &Value, ctx: &AppContext) -> Result<String,
let acceptance_criteria: Option<Vec<String>> = args let acceptance_criteria: Option<Vec<String>> = args
.get("acceptance_criteria") .get("acceptance_criteria")
.and_then(|v| serde_json::from_value(v.clone()).ok()); .and_then(|v| serde_json::from_value(v.clone()).ok());
let depends_on: Option<Vec<u32>> = args
.get("depends_on")
.and_then(|v| serde_json::from_value(v.clone()).ok());
let root = ctx.state.get_project_root()?; let root = ctx.state.get_project_root()?;
let bug_id = create_bug_file( let bug_id = create_bug_file(
@@ -499,6 +502,7 @@ pub(super) fn tool_create_bug(args: &Value, ctx: &AppContext) -> Result<String,
actual_result, actual_result,
expected_result, expected_result,
acceptance_criteria.as_deref(), acceptance_criteria.as_deref(),
depends_on.as_deref(),
)?; )?;
Ok(format!("Created bug: {bug_id}")) Ok(format!("Created bug: {bug_id}"))
@@ -689,10 +693,18 @@ pub(super) fn tool_create_refactor(args: &Value, ctx: &AppContext) -> Result<Str
let acceptance_criteria: Option<Vec<String>> = args let acceptance_criteria: Option<Vec<String>> = args
.get("acceptance_criteria") .get("acceptance_criteria")
.and_then(|v| serde_json::from_value(v.clone()).ok()); .and_then(|v| serde_json::from_value(v.clone()).ok());
let depends_on: Option<Vec<u32>> = args
.get("depends_on")
.and_then(|v| serde_json::from_value(v.clone()).ok());
let root = ctx.state.get_project_root()?; let root = ctx.state.get_project_root()?;
let refactor_id = let refactor_id = create_refactor_file(
create_refactor_file(&root, name, description, acceptance_criteria.as_deref())?; &root,
name,
description,
acceptance_criteria.as_deref(),
depends_on.as_deref(),
)?;
Ok(format!("Created refactor: {refactor_id}")) Ok(format!("Created refactor: {refactor_id}"))
} }
+136
View File
@@ -8,6 +8,7 @@ use super::{next_item_number, slugify_name, write_story_content};
/// ///
/// Also writes to the filesystem for backwards compatibility during migration. /// Also writes to the filesystem for backwards compatibility during migration.
/// Returns the bug_id (e.g. `"4_bug_login_crash"`). /// Returns the bug_id (e.g. `"4_bug_login_crash"`).
#[allow(clippy::too_many_arguments)]
pub fn create_bug_file( pub fn create_bug_file(
root: &Path, root: &Path,
name: &str, name: &str,
@@ -16,6 +17,7 @@ pub fn create_bug_file(
actual_result: &str, actual_result: &str,
expected_result: &str, expected_result: &str,
acceptance_criteria: Option<&[String]>, acceptance_criteria: Option<&[String]>,
depends_on: Option<&[u32]>,
) -> Result<String, String> { ) -> Result<String, String> {
let bug_number = next_item_number(root)?; let bug_number = next_item_number(root)?;
let slug = slugify_name(name); let slug = slugify_name(name);
@@ -29,6 +31,10 @@ pub fn create_bug_file(
let mut content = String::new(); let mut content = String::new();
content.push_str("---\n"); content.push_str("---\n");
content.push_str(&format!("name: \"{}\"\n", name.replace('"', "\\\""))); content.push_str(&format!("name: \"{}\"\n", name.replace('"', "\\\"")));
if let Some(deps) = depends_on.filter(|d| !d.is_empty()) {
let nums: Vec<String> = 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("---\n\n");
content.push_str(&format!("# Bug {bug_number}: {name}\n\n")); content.push_str(&format!("# Bug {bug_number}: {name}\n\n"));
content.push_str("## Description\n\n"); content.push_str("## Description\n\n");
@@ -113,6 +119,7 @@ pub fn create_refactor_file(
name: &str, name: &str,
description: Option<&str>, description: Option<&str>,
acceptance_criteria: Option<&[String]>, acceptance_criteria: Option<&[String]>,
depends_on: Option<&[u32]>,
) -> Result<String, String> { ) -> Result<String, String> {
let refactor_number = next_item_number(root)?; let refactor_number = next_item_number(root)?;
let slug = slugify_name(name); let slug = slugify_name(name);
@@ -126,6 +133,10 @@ pub fn create_refactor_file(
let mut content = String::new(); let mut content = String::new();
content.push_str("---\n"); content.push_str("---\n");
content.push_str(&format!("name: \"{}\"\n", name.replace('"', "\\\""))); content.push_str(&format!("name: \"{}\"\n", name.replace('"', "\\\"")));
if let Some(deps) = depends_on.filter(|d| !d.is_empty()) {
let nums: Vec<String> = 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("---\n\n");
content.push_str(&format!("# Refactor {refactor_number}: {name}\n\n")); content.push_str(&format!("# Refactor {refactor_number}: {name}\n\n"));
content.push_str("## Current State\n\n"); content.push_str("## Current State\n\n");
@@ -406,6 +417,7 @@ mod tests {
"Page crashes with 500 error", "Page crashes with 500 error",
"Login succeeds", "Login succeeds",
Some(&["Login form submits without error".to_string()]), Some(&["Login form submits without error".to_string()]),
None,
) )
.unwrap(); .unwrap();
@@ -455,6 +467,7 @@ mod tests {
"actual", "actual",
"expected", "expected",
None, None,
None,
); );
assert!(result.is_err()); assert!(result.is_err());
assert!(result.unwrap_err().contains("alphanumeric")); assert!(result.unwrap_err().contains("alphanumeric"));
@@ -473,6 +486,7 @@ mod tests {
"actual", "actual",
"expected", "expected",
None, None,
None,
) )
.unwrap(); .unwrap();
@@ -618,4 +632,126 @@ mod tests {
"expected spike number >= 7051, got: {spike_id}" "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}"
);
}
} }