The great storkit name conversion
This commit is contained in:
@@ -1,14 +1,16 @@
|
||||
use crate::agents::{
|
||||
close_bug_to_archive, feature_branch_has_unmerged_changes, move_story_to_archived,
|
||||
};
|
||||
use crate::http::context::AppContext;
|
||||
use crate::http::workflow::{
|
||||
add_criterion_to_file, check_criterion_in_file, create_bug_file, create_refactor_file,
|
||||
create_spike_file, create_story_file, list_bug_files, list_refactor_files,
|
||||
load_pipeline_state, load_upcoming_stories, update_story_in_file, validate_story_dirs,
|
||||
create_spike_file, create_story_file, list_bug_files, list_refactor_files, load_pipeline_state,
|
||||
load_upcoming_stories, update_story_in_file, validate_story_dirs,
|
||||
};
|
||||
use crate::agents::{close_bug_to_archive, feature_branch_has_unmerged_changes, move_story_to_archived};
|
||||
use crate::slog_warn;
|
||||
use crate::io::story_metadata::{parse_front_matter, parse_unchecked_todos};
|
||||
use crate::workflow::{evaluate_acceptance_with_coverage, TestCaseResult, TestStatus};
|
||||
use serde_json::{json, Value};
|
||||
use crate::slog_warn;
|
||||
use crate::workflow::{TestCaseResult, TestStatus, evaluate_acceptance_with_coverage};
|
||||
use serde_json::{Value, json};
|
||||
use std::collections::HashMap;
|
||||
use std::fs;
|
||||
|
||||
@@ -40,27 +42,31 @@ pub(super) fn tool_create_story(args: &Value, ctx: &AppContext) -> Result<String
|
||||
pub(super) fn tool_validate_stories(ctx: &AppContext) -> Result<String, String> {
|
||||
let root = ctx.state.get_project_root()?;
|
||||
let results = validate_story_dirs(&root)?;
|
||||
serde_json::to_string_pretty(&json!(results
|
||||
.iter()
|
||||
.map(|r| json!({
|
||||
"story_id": r.story_id,
|
||||
"valid": r.valid,
|
||||
"error": r.error,
|
||||
}))
|
||||
.collect::<Vec<_>>()))
|
||||
serde_json::to_string_pretty(&json!(
|
||||
results
|
||||
.iter()
|
||||
.map(|r| json!({
|
||||
"story_id": r.story_id,
|
||||
"valid": r.valid,
|
||||
"error": r.error,
|
||||
}))
|
||||
.collect::<Vec<_>>()
|
||||
))
|
||||
.map_err(|e| format!("Serialization error: {e}"))
|
||||
}
|
||||
|
||||
pub(super) fn tool_list_upcoming(ctx: &AppContext) -> Result<String, String> {
|
||||
let stories = load_upcoming_stories(ctx)?;
|
||||
serde_json::to_string_pretty(&json!(stories
|
||||
.iter()
|
||||
.map(|s| json!({
|
||||
"story_id": s.story_id,
|
||||
"name": s.name,
|
||||
"error": s.error,
|
||||
}))
|
||||
.collect::<Vec<_>>()))
|
||||
serde_json::to_string_pretty(&json!(
|
||||
stories
|
||||
.iter()
|
||||
.map(|s| json!({
|
||||
"story_id": s.story_id,
|
||||
"name": s.name,
|
||||
"error": s.error,
|
||||
}))
|
||||
.collect::<Vec<_>>()
|
||||
))
|
||||
.map_err(|e| format!("Serialization error: {e}"))
|
||||
}
|
||||
|
||||
@@ -131,12 +137,10 @@ pub(super) fn tool_get_story_todos(args: &Value, ctx: &AppContext) -> Result<Str
|
||||
return Err(format!("Story file not found: {story_id}.md"));
|
||||
}
|
||||
|
||||
let contents = fs::read_to_string(&filepath)
|
||||
.map_err(|e| format!("Failed to read story file: {e}"))?;
|
||||
let contents =
|
||||
fs::read_to_string(&filepath).map_err(|e| format!("Failed to read story file: {e}"))?;
|
||||
|
||||
let story_name = parse_front_matter(&contents)
|
||||
.ok()
|
||||
.and_then(|m| m.name);
|
||||
let story_name = parse_front_matter(&contents).ok().and_then(|m| m.name);
|
||||
let todos = parse_unchecked_todos(&contents);
|
||||
|
||||
serde_json::to_string_pretty(&json!({
|
||||
@@ -166,8 +170,11 @@ pub(super) fn tool_record_tests(args: &Value, ctx: &AppContext) -> Result<String
|
||||
// Persist to story file (best-effort — file write errors are warnings, not failures).
|
||||
if let Ok(project_root) = ctx.state.get_project_root()
|
||||
&& let Some(results) = workflow.results.get(story_id)
|
||||
&& let Err(e) =
|
||||
crate::http::workflow::write_test_results_to_story_file(&project_root, story_id, results)
|
||||
&& let Err(e) = crate::http::workflow::write_test_results_to_story_file(
|
||||
&project_root,
|
||||
story_id,
|
||||
results,
|
||||
)
|
||||
{
|
||||
slog_warn!("[record_tests] Could not persist results to story file: {e}");
|
||||
}
|
||||
@@ -305,7 +312,11 @@ pub(super) fn tool_update_story(args: &Value, ctx: &AppContext) -> Result<String
|
||||
front_matter.insert(k.clone(), val);
|
||||
}
|
||||
}
|
||||
let front_matter_opt = if front_matter.is_empty() { None } else { Some(&front_matter) };
|
||||
let front_matter_opt = if front_matter.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(&front_matter)
|
||||
};
|
||||
|
||||
let root = ctx.state.get_project_root()?;
|
||||
update_story_in_file(&root, story_id, user_story, description, front_matter_opt)?;
|
||||
@@ -368,10 +379,11 @@ pub(super) fn tool_create_bug(args: &Value, ctx: &AppContext) -> Result<String,
|
||||
pub(super) fn tool_list_bugs(ctx: &AppContext) -> Result<String, String> {
|
||||
let root = ctx.state.get_project_root()?;
|
||||
let bugs = list_bug_files(&root)?;
|
||||
serde_json::to_string_pretty(&json!(bugs
|
||||
.iter()
|
||||
.map(|(id, name)| json!({ "bug_id": id, "name": name }))
|
||||
.collect::<Vec<_>>()))
|
||||
serde_json::to_string_pretty(&json!(
|
||||
bugs.iter()
|
||||
.map(|(id, name)| json!({ "bug_id": id, "name": name }))
|
||||
.collect::<Vec<_>>()
|
||||
))
|
||||
.map_err(|e| format!("Serialization error: {e}"))
|
||||
}
|
||||
|
||||
@@ -401,7 +413,10 @@ pub(super) async fn tool_delete_story(args: &Value, ctx: &AppContext) -> Result<
|
||||
// 1. Stop any running agents for this story (best-effort)
|
||||
if let Ok(agents) = ctx.agents.list_agents() {
|
||||
for agent in agents.iter().filter(|a| a.story_id == story_id) {
|
||||
let _ = ctx.agents.stop_agent(&project_root, story_id, &agent.agent_name).await;
|
||||
let _ = ctx
|
||||
.agents
|
||||
.stop_agent(&project_root, story_id, &agent.agent_name)
|
||||
.await;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -410,18 +425,25 @@ pub(super) async fn tool_delete_story(args: &Value, ctx: &AppContext) -> Result<
|
||||
|
||||
// 3. Remove worktree (best-effort)
|
||||
if let Ok(config) = crate::config::ProjectConfig::load(&project_root) {
|
||||
let _ = crate::worktree::remove_worktree_by_story_id(&project_root, story_id, &config).await;
|
||||
let _ =
|
||||
crate::worktree::remove_worktree_by_story_id(&project_root, story_id, &config).await;
|
||||
}
|
||||
|
||||
// 4. Find and delete the story file from any pipeline stage
|
||||
let sk = project_root.join(".storkit").join("work");
|
||||
let stage_dirs = ["1_backlog", "2_current", "3_qa", "4_merge", "5_done", "6_archived"];
|
||||
let stage_dirs = [
|
||||
"1_backlog",
|
||||
"2_current",
|
||||
"3_qa",
|
||||
"4_merge",
|
||||
"5_done",
|
||||
"6_archived",
|
||||
];
|
||||
let mut deleted = false;
|
||||
for stage in &stage_dirs {
|
||||
let path = sk.join(stage).join(format!("{story_id}.md"));
|
||||
if path.exists() {
|
||||
fs::remove_file(&path)
|
||||
.map_err(|e| format!("Failed to delete story file: {e}"))?;
|
||||
fs::remove_file(&path).map_err(|e| format!("Failed to delete story file: {e}"))?;
|
||||
slog_warn!("[delete_story] Deleted '{story_id}' from work/{stage}/");
|
||||
deleted = true;
|
||||
break;
|
||||
@@ -448,12 +470,8 @@ pub(super) fn tool_create_refactor(args: &Value, ctx: &AppContext) -> Result<Str
|
||||
.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())?;
|
||||
|
||||
Ok(format!("Created refactor: {refactor_id}"))
|
||||
}
|
||||
@@ -461,10 +479,12 @@ pub(super) fn tool_create_refactor(args: &Value, ctx: &AppContext) -> Result<Str
|
||||
pub(super) fn tool_list_refactors(ctx: &AppContext) -> Result<String, String> {
|
||||
let root = ctx.state.get_project_root()?;
|
||||
let refactors = list_refactor_files(&root)?;
|
||||
serde_json::to_string_pretty(&json!(refactors
|
||||
.iter()
|
||||
.map(|(id, name)| json!({ "refactor_id": id, "name": name }))
|
||||
.collect::<Vec<_>>()))
|
||||
serde_json::to_string_pretty(&json!(
|
||||
refactors
|
||||
.iter()
|
||||
.map(|(id, name)| json!({ "refactor_id": id, "name": name }))
|
||||
.collect::<Vec<_>>()
|
||||
))
|
||||
.map_err(|e| format!("Serialization error: {e}"))
|
||||
}
|
||||
|
||||
@@ -489,9 +509,16 @@ pub(super) fn parse_test_cases(value: Option<&Value>) -> Result<Vec<TestCaseResu
|
||||
let status = match status_str {
|
||||
"pass" => TestStatus::Pass,
|
||||
"fail" => TestStatus::Fail,
|
||||
other => return Err(format!("Invalid test status '{other}'. Use 'pass' or 'fail'.")),
|
||||
other => {
|
||||
return Err(format!(
|
||||
"Invalid test status '{other}'. Use 'pass' or 'fail'."
|
||||
));
|
||||
}
|
||||
};
|
||||
let details = item.get("details").and_then(|v| v.as_str()).map(String::from);
|
||||
let details = item
|
||||
.get("details")
|
||||
.and_then(|v| v.as_str())
|
||||
.map(String::from);
|
||||
Ok(TestCaseResult {
|
||||
name,
|
||||
status,
|
||||
@@ -643,7 +670,10 @@ mod tests {
|
||||
let active = parsed["active"].as_array().unwrap();
|
||||
assert_eq!(active.len(), 4);
|
||||
|
||||
let stages: Vec<&str> = active.iter().map(|i| i["stage"].as_str().unwrap()).collect();
|
||||
let stages: Vec<&str> = active
|
||||
.iter()
|
||||
.map(|i| i["stage"].as_str().unwrap())
|
||||
.collect();
|
||||
assert!(stages.contains(&"current"));
|
||||
assert!(stages.contains(&"qa"));
|
||||
assert!(stages.contains(&"merge"));
|
||||
@@ -783,7 +813,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn create_bug_in_tools_list() {
|
||||
use super::super::{handle_tools_list};
|
||||
use super::super::handle_tools_list;
|
||||
let resp = handle_tools_list(Some(json!(1)));
|
||||
let tools = resp.result.unwrap()["tools"].as_array().unwrap().clone();
|
||||
let tool = tools.iter().find(|t| t["name"] == "create_bug");
|
||||
@@ -809,7 +839,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn list_bugs_in_tools_list() {
|
||||
use super::super::{handle_tools_list};
|
||||
use super::super::handle_tools_list;
|
||||
let resp = handle_tools_list(Some(json!(1)));
|
||||
let tools = resp.result.unwrap()["tools"].as_array().unwrap().clone();
|
||||
let tool = tools.iter().find(|t| t["name"] == "list_bugs");
|
||||
@@ -828,7 +858,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn close_bug_in_tools_list() {
|
||||
use super::super::{handle_tools_list};
|
||||
use super::super::handle_tools_list;
|
||||
let resp = handle_tools_list(Some(json!(1)));
|
||||
let tools = resp.result.unwrap()["tools"].as_array().unwrap().clone();
|
||||
let tool = tools.iter().find(|t| t["name"] == "close_bug");
|
||||
@@ -921,11 +951,7 @@ mod tests {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let backlog_dir = tmp.path().join(".storkit/work/1_backlog");
|
||||
std::fs::create_dir_all(&backlog_dir).unwrap();
|
||||
std::fs::write(
|
||||
backlog_dir.join("1_bug_crash.md"),
|
||||
"# Bug 1: App Crash\n",
|
||||
)
|
||||
.unwrap();
|
||||
std::fs::write(backlog_dir.join("1_bug_crash.md"), "# Bug 1: App Crash\n").unwrap();
|
||||
std::fs::write(
|
||||
backlog_dir.join("2_bug_typo.md"),
|
||||
"# Bug 2: Typo in Header\n",
|
||||
@@ -975,12 +1001,16 @@ mod tests {
|
||||
let result = tool_close_bug(&json!({"bug_id": "1_bug_crash"}), &ctx).unwrap();
|
||||
assert!(result.contains("1_bug_crash"));
|
||||
assert!(!bug_file.exists());
|
||||
assert!(tmp.path().join(".storkit/work/5_done/1_bug_crash.md").exists());
|
||||
assert!(
|
||||
tmp.path()
|
||||
.join(".storkit/work/5_done/1_bug_crash.md")
|
||||
.exists()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create_spike_in_tools_list() {
|
||||
use super::super::{handle_tools_list};
|
||||
use super::super::handle_tools_list;
|
||||
let resp = handle_tools_list(Some(json!(1)));
|
||||
let tools = resp.result.unwrap()["tools"].as_array().unwrap().clone();
|
||||
let tool = tools.iter().find(|t| t["name"] == "create_spike");
|
||||
@@ -1041,7 +1071,9 @@ mod tests {
|
||||
let result = tool_create_spike(&json!({"name": "My Spike"}), &ctx).unwrap();
|
||||
assert!(result.contains("1_spike_my_spike"));
|
||||
|
||||
let spike_file = tmp.path().join(".storkit/work/1_backlog/1_spike_my_spike.md");
|
||||
let spike_file = tmp
|
||||
.path()
|
||||
.join(".storkit/work/1_backlog/1_spike_my_spike.md");
|
||||
assert!(spike_file.exists());
|
||||
let contents = std::fs::read_to_string(&spike_file).unwrap();
|
||||
assert!(contents.starts_with("---\nname: \"My Spike\"\n---"));
|
||||
@@ -1052,10 +1084,7 @@ mod tests {
|
||||
fn tool_record_tests_missing_story_id() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let ctx = test_ctx(tmp.path());
|
||||
let result = tool_record_tests(
|
||||
&json!({"unit": [], "integration": []}),
|
||||
&ctx,
|
||||
);
|
||||
let result = tool_record_tests(&json!({"unit": [], "integration": []}), &ctx);
|
||||
assert!(result.is_err());
|
||||
assert!(result.unwrap_err().contains("story_id"));
|
||||
}
|
||||
@@ -1106,11 +1135,7 @@ mod tests {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let current_dir = tmp.path().join(".storkit").join("work").join("2_current");
|
||||
fs::create_dir_all(¤t_dir).unwrap();
|
||||
fs::write(
|
||||
current_dir.join("1_test.md"),
|
||||
"## No front matter at all\n",
|
||||
)
|
||||
.unwrap();
|
||||
fs::write(current_dir.join("1_test.md"), "## No front matter at all\n").unwrap();
|
||||
let ctx = test_ctx(tmp.path());
|
||||
let result = tool_validate_stories(&ctx).unwrap();
|
||||
let parsed: Vec<Value> = serde_json::from_str(&result).unwrap();
|
||||
@@ -1123,7 +1148,11 @@ mod tests {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let current = tmp.path().join(".storkit/work/2_current");
|
||||
fs::create_dir_all(¤t).unwrap();
|
||||
fs::write(current.join("1_story_persist.md"), "---\nname: Persist\n---\n# Story\n").unwrap();
|
||||
fs::write(
|
||||
current.join("1_story_persist.md"),
|
||||
"---\nname: Persist\n---\n# Story\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let ctx = test_ctx(tmp.path());
|
||||
tool_record_tests(
|
||||
@@ -1137,8 +1166,14 @@ mod tests {
|
||||
.unwrap();
|
||||
|
||||
let contents = fs::read_to_string(current.join("1_story_persist.md")).unwrap();
|
||||
assert!(contents.contains("## Test Results"), "file should have Test Results section");
|
||||
assert!(contents.contains("story-kit-test-results:"), "file should have JSON marker");
|
||||
assert!(
|
||||
contents.contains("## Test Results"),
|
||||
"file should have Test Results section"
|
||||
);
|
||||
assert!(
|
||||
contents.contains("storkit-test-results:"),
|
||||
"file should have JSON marker"
|
||||
);
|
||||
assert!(contents.contains("u1"), "file should contain test name");
|
||||
}
|
||||
|
||||
@@ -1149,7 +1184,7 @@ mod tests {
|
||||
fs::create_dir_all(¤t).unwrap();
|
||||
|
||||
// Write a story file with a pre-populated Test Results section (simulating a restart)
|
||||
let story_content = "---\nname: Persist\n---\n# Story\n\n## Test Results\n\n<!-- story-kit-test-results: {\"unit\":[{\"name\":\"u1\",\"status\":\"pass\",\"details\":null}],\"integration\":[{\"name\":\"i1\",\"status\":\"pass\",\"details\":null}]} -->\n";
|
||||
let story_content = "---\nname: Persist\n---\n# Story\n\n## Test Results\n\n<!-- storkit-test-results: {\"unit\":[{\"name\":\"u1\",\"status\":\"pass\",\"details\":null}],\"integration\":[{\"name\":\"i1\",\"status\":\"pass\",\"details\":null}]} -->\n";
|
||||
fs::write(current.join("2_story_file_only.md"), story_content).unwrap();
|
||||
|
||||
// Use a fresh context (empty in-memory state, simulating a restart)
|
||||
@@ -1157,7 +1192,11 @@ mod tests {
|
||||
|
||||
// ensure_acceptance should read from file and succeed
|
||||
let result = tool_ensure_acceptance(&json!({"story_id": "2_story_file_only"}), &ctx);
|
||||
assert!(result.is_ok(), "should accept based on file data, got: {:?}", result);
|
||||
assert!(
|
||||
result.is_ok(),
|
||||
"should accept based on file data, got: {:?}",
|
||||
result
|
||||
);
|
||||
assert!(result.unwrap().contains("All gates pass"));
|
||||
}
|
||||
|
||||
@@ -1167,7 +1206,7 @@ mod tests {
|
||||
let current = tmp.path().join(".storkit/work/2_current");
|
||||
fs::create_dir_all(¤t).unwrap();
|
||||
|
||||
let story_content = "---\nname: Fail\n---\n# Story\n\n## Test Results\n\n<!-- story-kit-test-results: {\"unit\":[{\"name\":\"u1\",\"status\":\"fail\",\"details\":\"error\"}],\"integration\":[]} -->\n";
|
||||
let story_content = "---\nname: Fail\n---\n# Story\n\n## Test Results\n\n<!-- storkit-test-results: {\"unit\":[{\"name\":\"u1\",\"status\":\"fail\",\"details\":\"error\"}],\"integration\":[]} -->\n";
|
||||
fs::write(current.join("3_story_fail.md"), story_content).unwrap();
|
||||
|
||||
let ctx = test_ctx(tmp.path());
|
||||
@@ -1191,7 +1230,11 @@ mod tests {
|
||||
let ctx = test_ctx(tmp.path());
|
||||
let result = tool_delete_story(&json!({"story_id": "99_nonexistent"}), &ctx).await;
|
||||
assert!(result.is_err());
|
||||
assert!(result.unwrap_err().contains("not found in any pipeline stage"));
|
||||
assert!(
|
||||
result
|
||||
.unwrap_err()
|
||||
.contains("not found in any pipeline stage")
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -1280,9 +1323,11 @@ mod tests {
|
||||
.unwrap();
|
||||
|
||||
let ctx = test_ctx(tmp.path());
|
||||
let result =
|
||||
tool_accept_story(&json!({"story_id": "50_story_test"}), &ctx);
|
||||
assert!(result.is_err(), "should refuse when feature branch has unmerged code");
|
||||
let result = tool_accept_story(&json!({"story_id": "50_story_test"}), &ctx);
|
||||
assert!(
|
||||
result.is_err(),
|
||||
"should refuse when feature branch has unmerged code"
|
||||
);
|
||||
let err = result.unwrap_err();
|
||||
assert!(
|
||||
err.contains("unmerged"),
|
||||
@@ -1306,9 +1351,11 @@ mod tests {
|
||||
.unwrap();
|
||||
|
||||
let ctx = test_ctx(tmp.path());
|
||||
let result =
|
||||
tool_accept_story(&json!({"story_id": "51_story_no_branch"}), &ctx);
|
||||
assert!(result.is_ok(), "should succeed when no feature branch: {result:?}");
|
||||
let result = tool_accept_story(&json!({"story_id": "51_story_no_branch"}), &ctx);
|
||||
assert!(
|
||||
result.is_ok(),
|
||||
"should succeed when no feature branch: {result:?}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1352,10 +1399,8 @@ mod tests {
|
||||
.unwrap();
|
||||
|
||||
let ctx = test_ctx(tmp.path());
|
||||
let result = tool_check_criterion(
|
||||
&json!({"story_id": "1_test", "criterion_index": 0}),
|
||||
&ctx,
|
||||
);
|
||||
let result =
|
||||
tool_check_criterion(&json!({"story_id": "1_test", "criterion_index": 0}), &ctx);
|
||||
assert!(result.is_ok(), "Expected ok: {result:?}");
|
||||
assert!(result.unwrap().contains("Criterion 0 checked"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user