The great storkit name conversion
This commit is contained in:
@@ -160,8 +160,7 @@ struct AllTokenUsageResponse {
|
||||
pub fn story_is_archived(project_root: &path::Path, story_id: &str) -> bool {
|
||||
let work = project_root.join(".storkit").join("work");
|
||||
let filename = format!("{story_id}.md");
|
||||
work.join("5_done").join(&filename).exists()
|
||||
|| work.join("6_archived").join(&filename).exists()
|
||||
work.join("5_done").join(&filename).exists() || work.join("6_archived").join(&filename).exists()
|
||||
}
|
||||
|
||||
pub struct AgentsApi {
|
||||
@@ -215,11 +214,7 @@ impl AgentsApi {
|
||||
|
||||
self.ctx
|
||||
.agents
|
||||
.stop_agent(
|
||||
&project_root,
|
||||
&payload.0.story_id,
|
||||
&payload.0.agent_name,
|
||||
)
|
||||
.stop_agent(&project_root, &payload.0.story_id, &payload.0.agent_name)
|
||||
.await
|
||||
.map_err(bad_request)?;
|
||||
|
||||
@@ -258,9 +253,7 @@ impl AgentsApi {
|
||||
|
||||
/// Get the configured agent roster from project.toml.
|
||||
#[oai(path = "/agents/config", method = "get")]
|
||||
async fn get_agent_config(
|
||||
&self,
|
||||
) -> OpenApiResult<Json<Vec<AgentConfigInfoResponse>>> {
|
||||
async fn get_agent_config(&self) -> OpenApiResult<Json<Vec<AgentConfigInfoResponse>>> {
|
||||
let project_root = self
|
||||
.ctx
|
||||
.agents
|
||||
@@ -288,9 +281,7 @@ impl AgentsApi {
|
||||
|
||||
/// Reload project config and return the updated agent roster.
|
||||
#[oai(path = "/agents/config/reload", method = "post")]
|
||||
async fn reload_config(
|
||||
&self,
|
||||
) -> OpenApiResult<Json<Vec<AgentConfigInfoResponse>>> {
|
||||
async fn reload_config(&self) -> OpenApiResult<Json<Vec<AgentConfigInfoResponse>>> {
|
||||
let project_root = self
|
||||
.ctx
|
||||
.agents
|
||||
@@ -440,10 +431,8 @@ impl AgentsApi {
|
||||
.get_project_root(&self.ctx.state)
|
||||
.map_err(bad_request)?;
|
||||
|
||||
let file_results = crate::http::workflow::read_test_results_from_story_file(
|
||||
&project_root,
|
||||
&story_id.0,
|
||||
);
|
||||
let file_results =
|
||||
crate::http::workflow::read_test_results_from_story_file(&project_root, &story_id.0);
|
||||
|
||||
Ok(Json(
|
||||
file_results.map(|r| TestResultsResponse::from_story_results(&r)),
|
||||
@@ -467,8 +456,7 @@ impl AgentsApi {
|
||||
.get_project_root(&self.ctx.state)
|
||||
.map_err(bad_request)?;
|
||||
|
||||
let log_path =
|
||||
crate::agent_log::find_latest_log(&project_root, &story_id.0, &agent_name.0);
|
||||
let log_path = crate::agent_log::find_latest_log(&project_root, &story_id.0, &agent_name.0);
|
||||
|
||||
let Some(path) = log_path else {
|
||||
return Ok(Json(AgentOutputResponse {
|
||||
@@ -480,10 +468,13 @@ impl AgentsApi {
|
||||
|
||||
let output: String = entries
|
||||
.iter()
|
||||
.filter(|e| {
|
||||
e.event.get("type").and_then(|t| t.as_str()) == Some("output")
|
||||
.filter(|e| e.event.get("type").and_then(|t| t.as_str()) == Some("output"))
|
||||
.filter_map(|e| {
|
||||
e.event
|
||||
.get("text")
|
||||
.and_then(|t| t.as_str())
|
||||
.map(str::to_owned)
|
||||
})
|
||||
.filter_map(|e| e.event.get("text").and_then(|t| t.as_str()).map(str::to_owned))
|
||||
.collect();
|
||||
|
||||
Ok(Json(AgentOutputResponse { output }))
|
||||
@@ -562,9 +553,7 @@ impl AgentsApi {
|
||||
///
|
||||
/// Returns the full history from the persistent token_usage.jsonl log.
|
||||
#[oai(path = "/token-usage", method = "get")]
|
||||
async fn get_all_token_usage(
|
||||
&self,
|
||||
) -> OpenApiResult<Json<AllTokenUsageResponse>> {
|
||||
async fn get_all_token_usage(&self) -> OpenApiResult<Json<AllTokenUsageResponse>> {
|
||||
let project_root = self
|
||||
.ctx
|
||||
.agents
|
||||
@@ -659,9 +648,7 @@ mod tests {
|
||||
ctx.agents
|
||||
.inject_test_agent("80_story_active", "coder-1", AgentStatus::Running);
|
||||
|
||||
let api = AgentsApi {
|
||||
ctx: Arc::new(ctx),
|
||||
};
|
||||
let api = AgentsApi { ctx: Arc::new(ctx) };
|
||||
let result = api.list_agents().await.unwrap().0;
|
||||
|
||||
// Archived story's agent should not appear
|
||||
@@ -686,9 +673,7 @@ mod tests {
|
||||
ctx.agents
|
||||
.inject_test_agent("42_story_whatever", "coder-1", AgentStatus::Completed);
|
||||
|
||||
let api = AgentsApi {
|
||||
ctx: Arc::new(ctx),
|
||||
};
|
||||
let api = AgentsApi { ctx: Arc::new(ctx) };
|
||||
let result = api.list_agents().await.unwrap().0;
|
||||
assert!(result.iter().any(|a| a.story_id == "42_story_whatever"));
|
||||
}
|
||||
@@ -705,9 +690,7 @@ mod tests {
|
||||
async fn get_agent_config_returns_default_when_no_toml() {
|
||||
let tmp = TempDir::new().unwrap();
|
||||
let ctx = AppContext::new_test(tmp.path().to_path_buf());
|
||||
let api = AgentsApi {
|
||||
ctx: Arc::new(ctx),
|
||||
};
|
||||
let api = AgentsApi { ctx: Arc::new(ctx) };
|
||||
let result = api.get_agent_config().await.unwrap().0;
|
||||
// Default config has one agent named "default"
|
||||
assert_eq!(result.len(), 1);
|
||||
@@ -734,9 +717,7 @@ model = "haiku"
|
||||
"#,
|
||||
);
|
||||
let ctx = AppContext::new_test(tmp.path().to_path_buf());
|
||||
let api = AgentsApi {
|
||||
ctx: Arc::new(ctx),
|
||||
};
|
||||
let api = AgentsApi { ctx: Arc::new(ctx) };
|
||||
let result = api.get_agent_config().await.unwrap().0;
|
||||
assert_eq!(result.len(), 2);
|
||||
assert_eq!(result[0].name, "coder-1");
|
||||
@@ -753,9 +734,7 @@ model = "haiku"
|
||||
let tmp = TempDir::new().unwrap();
|
||||
let ctx = AppContext::new_test(tmp.path().to_path_buf());
|
||||
*ctx.state.project_root.lock().unwrap() = None;
|
||||
let api = AgentsApi {
|
||||
ctx: Arc::new(ctx),
|
||||
};
|
||||
let api = AgentsApi { ctx: Arc::new(ctx) };
|
||||
let result = api.get_agent_config().await;
|
||||
assert!(result.is_err());
|
||||
}
|
||||
@@ -766,9 +745,7 @@ model = "haiku"
|
||||
async fn reload_config_returns_default_when_no_toml() {
|
||||
let tmp = TempDir::new().unwrap();
|
||||
let ctx = AppContext::new_test(tmp.path().to_path_buf());
|
||||
let api = AgentsApi {
|
||||
ctx: Arc::new(ctx),
|
||||
};
|
||||
let api = AgentsApi { ctx: Arc::new(ctx) };
|
||||
let result = api.reload_config().await.unwrap().0;
|
||||
assert_eq!(result.len(), 1);
|
||||
assert_eq!(result[0].name, "default");
|
||||
@@ -788,9 +765,7 @@ allowed_tools = ["Read", "Bash"]
|
||||
"#,
|
||||
);
|
||||
let ctx = AppContext::new_test(tmp.path().to_path_buf());
|
||||
let api = AgentsApi {
|
||||
ctx: Arc::new(ctx),
|
||||
};
|
||||
let api = AgentsApi { ctx: Arc::new(ctx) };
|
||||
let result = api.reload_config().await.unwrap().0;
|
||||
assert_eq!(result.len(), 1);
|
||||
assert_eq!(result[0].name, "supervisor");
|
||||
@@ -807,9 +782,7 @@ allowed_tools = ["Read", "Bash"]
|
||||
let tmp = TempDir::new().unwrap();
|
||||
let ctx = AppContext::new_test(tmp.path().to_path_buf());
|
||||
*ctx.state.project_root.lock().unwrap() = None;
|
||||
let api = AgentsApi {
|
||||
ctx: Arc::new(ctx),
|
||||
};
|
||||
let api = AgentsApi { ctx: Arc::new(ctx) };
|
||||
let result = api.reload_config().await;
|
||||
assert!(result.is_err());
|
||||
}
|
||||
@@ -820,9 +793,7 @@ allowed_tools = ["Read", "Bash"]
|
||||
async fn list_worktrees_returns_empty_when_no_worktree_dir() {
|
||||
let tmp = TempDir::new().unwrap();
|
||||
let ctx = AppContext::new_test(tmp.path().to_path_buf());
|
||||
let api = AgentsApi {
|
||||
ctx: Arc::new(ctx),
|
||||
};
|
||||
let api = AgentsApi { ctx: Arc::new(ctx) };
|
||||
let result = api.list_worktrees().await.unwrap().0;
|
||||
assert!(result.is_empty());
|
||||
}
|
||||
@@ -835,9 +806,7 @@ allowed_tools = ["Read", "Bash"]
|
||||
std::fs::create_dir_all(worktrees_dir.join("43_story_bar")).unwrap();
|
||||
|
||||
let ctx = AppContext::new_test(tmp.path().to_path_buf());
|
||||
let api = AgentsApi {
|
||||
ctx: Arc::new(ctx),
|
||||
};
|
||||
let api = AgentsApi { ctx: Arc::new(ctx) };
|
||||
let mut result = api.list_worktrees().await.unwrap().0;
|
||||
result.sort_by(|a, b| a.story_id.cmp(&b.story_id));
|
||||
|
||||
@@ -851,9 +820,7 @@ allowed_tools = ["Read", "Bash"]
|
||||
let tmp = TempDir::new().unwrap();
|
||||
let ctx = AppContext::new_test(tmp.path().to_path_buf());
|
||||
*ctx.state.project_root.lock().unwrap() = None;
|
||||
let api = AgentsApi {
|
||||
ctx: Arc::new(ctx),
|
||||
};
|
||||
let api = AgentsApi { ctx: Arc::new(ctx) };
|
||||
let result = api.list_worktrees().await;
|
||||
assert!(result.is_err());
|
||||
}
|
||||
@@ -865,9 +832,7 @@ allowed_tools = ["Read", "Bash"]
|
||||
let tmp = TempDir::new().unwrap();
|
||||
let ctx = AppContext::new_test(tmp.path().to_path_buf());
|
||||
*ctx.state.project_root.lock().unwrap() = None;
|
||||
let api = AgentsApi {
|
||||
ctx: Arc::new(ctx),
|
||||
};
|
||||
let api = AgentsApi { ctx: Arc::new(ctx) };
|
||||
let result = api
|
||||
.stop_agent(Json(StopAgentPayload {
|
||||
story_id: "42_story_foo".to_string(),
|
||||
@@ -881,9 +846,7 @@ allowed_tools = ["Read", "Bash"]
|
||||
async fn stop_agent_returns_error_when_agent_not_found() {
|
||||
let tmp = TempDir::new().unwrap();
|
||||
let ctx = AppContext::new_test(tmp.path().to_path_buf());
|
||||
let api = AgentsApi {
|
||||
ctx: Arc::new(ctx),
|
||||
};
|
||||
let api = AgentsApi { ctx: Arc::new(ctx) };
|
||||
let result = api
|
||||
.stop_agent(Json(StopAgentPayload {
|
||||
story_id: "nonexistent_story".to_string(),
|
||||
@@ -899,9 +862,7 @@ allowed_tools = ["Read", "Bash"]
|
||||
let ctx = AppContext::new_test(tmp.path().to_path_buf());
|
||||
ctx.agents
|
||||
.inject_test_agent("42_story_foo", "coder-1", AgentStatus::Running);
|
||||
let api = AgentsApi {
|
||||
ctx: Arc::new(ctx),
|
||||
};
|
||||
let api = AgentsApi { ctx: Arc::new(ctx) };
|
||||
let result = api
|
||||
.stop_agent(Json(StopAgentPayload {
|
||||
story_id: "42_story_foo".to_string(),
|
||||
@@ -920,9 +881,7 @@ allowed_tools = ["Read", "Bash"]
|
||||
let tmp = TempDir::new().unwrap();
|
||||
let ctx = AppContext::new_test(tmp.path().to_path_buf());
|
||||
*ctx.state.project_root.lock().unwrap() = None;
|
||||
let api = AgentsApi {
|
||||
ctx: Arc::new(ctx),
|
||||
};
|
||||
let api = AgentsApi { ctx: Arc::new(ctx) };
|
||||
let result = api
|
||||
.start_agent(Json(StartAgentPayload {
|
||||
story_id: "42_story_foo".to_string(),
|
||||
@@ -949,9 +908,7 @@ allowed_tools = ["Read", "Bash"]
|
||||
)
|
||||
.unwrap();
|
||||
let ctx = AppContext::new_test(root.to_path_buf());
|
||||
let api = AgentsApi {
|
||||
ctx: Arc::new(ctx),
|
||||
};
|
||||
let api = AgentsApi { ctx: Arc::new(ctx) };
|
||||
let result = api
|
||||
.get_work_item_content(Path("42_story_foo".to_string()))
|
||||
.await
|
||||
@@ -973,9 +930,7 @@ allowed_tools = ["Read", "Bash"]
|
||||
)
|
||||
.unwrap();
|
||||
let ctx = AppContext::new_test(root.to_path_buf());
|
||||
let api = AgentsApi {
|
||||
ctx: Arc::new(ctx),
|
||||
};
|
||||
let api = AgentsApi { ctx: Arc::new(ctx) };
|
||||
let result = api
|
||||
.get_work_item_content(Path("43_story_bar".to_string()))
|
||||
.await
|
||||
@@ -989,9 +944,7 @@ allowed_tools = ["Read", "Bash"]
|
||||
async fn get_work_item_content_returns_not_found_when_absent() {
|
||||
let tmp = TempDir::new().unwrap();
|
||||
let ctx = AppContext::new_test(tmp.path().to_path_buf());
|
||||
let api = AgentsApi {
|
||||
ctx: Arc::new(ctx),
|
||||
};
|
||||
let api = AgentsApi { ctx: Arc::new(ctx) };
|
||||
let result = api
|
||||
.get_work_item_content(Path("99_story_nonexistent".to_string()))
|
||||
.await;
|
||||
@@ -1003,9 +956,7 @@ allowed_tools = ["Read", "Bash"]
|
||||
let tmp = TempDir::new().unwrap();
|
||||
let ctx = AppContext::new_test(tmp.path().to_path_buf());
|
||||
*ctx.state.project_root.lock().unwrap() = None;
|
||||
let api = AgentsApi {
|
||||
ctx: Arc::new(ctx),
|
||||
};
|
||||
let api = AgentsApi { ctx: Arc::new(ctx) };
|
||||
let result = api
|
||||
.get_work_item_content(Path("42_story_foo".to_string()))
|
||||
.await;
|
||||
@@ -1018,9 +969,7 @@ allowed_tools = ["Read", "Bash"]
|
||||
async fn get_agent_output_returns_empty_when_no_log_exists() {
|
||||
let tmp = TempDir::new().unwrap();
|
||||
let ctx = AppContext::new_test(tmp.path().to_path_buf());
|
||||
let api = AgentsApi {
|
||||
ctx: Arc::new(ctx),
|
||||
};
|
||||
let api = AgentsApi { ctx: Arc::new(ctx) };
|
||||
let result = api
|
||||
.get_agent_output(
|
||||
Path("42_story_foo".to_string()),
|
||||
@@ -1040,8 +989,7 @@ allowed_tools = ["Read", "Bash"]
|
||||
let tmp = TempDir::new().unwrap();
|
||||
let root = tmp.path();
|
||||
|
||||
let mut writer =
|
||||
AgentLogWriter::new(root, "42_story_foo", "coder-1", "sess-test").unwrap();
|
||||
let mut writer = AgentLogWriter::new(root, "42_story_foo", "coder-1", "sess-test").unwrap();
|
||||
|
||||
writer
|
||||
.write_event(&AgentEvent::Status {
|
||||
@@ -1073,9 +1021,7 @@ allowed_tools = ["Read", "Bash"]
|
||||
.unwrap();
|
||||
|
||||
let ctx = AppContext::new_test(root.to_path_buf());
|
||||
let api = AgentsApi {
|
||||
ctx: Arc::new(ctx),
|
||||
};
|
||||
let api = AgentsApi { ctx: Arc::new(ctx) };
|
||||
let result = api
|
||||
.get_agent_output(
|
||||
Path("42_story_foo".to_string()),
|
||||
@@ -1094,9 +1040,7 @@ allowed_tools = ["Read", "Bash"]
|
||||
let tmp = TempDir::new().unwrap();
|
||||
let ctx = AppContext::new_test(tmp.path().to_path_buf());
|
||||
*ctx.state.project_root.lock().unwrap() = None;
|
||||
let api = AgentsApi {
|
||||
ctx: Arc::new(ctx),
|
||||
};
|
||||
let api = AgentsApi { ctx: Arc::new(ctx) };
|
||||
let result = api
|
||||
.get_agent_output(
|
||||
Path("42_story_foo".to_string()),
|
||||
@@ -1113,9 +1057,7 @@ allowed_tools = ["Read", "Bash"]
|
||||
let tmp = TempDir::new().unwrap();
|
||||
let ctx = AppContext::new_test(tmp.path().to_path_buf());
|
||||
*ctx.state.project_root.lock().unwrap() = None;
|
||||
let api = AgentsApi {
|
||||
ctx: Arc::new(ctx),
|
||||
};
|
||||
let api = AgentsApi { ctx: Arc::new(ctx) };
|
||||
let result = api
|
||||
.create_worktree(Json(CreateWorktreePayload {
|
||||
story_id: "42_story_foo".to_string(),
|
||||
@@ -1129,9 +1071,7 @@ allowed_tools = ["Read", "Bash"]
|
||||
let tmp = TempDir::new().unwrap();
|
||||
// project_root is set but has no git repo — git worktree add will fail
|
||||
let ctx = AppContext::new_test(tmp.path().to_path_buf());
|
||||
let api = AgentsApi {
|
||||
ctx: Arc::new(ctx),
|
||||
};
|
||||
let api = AgentsApi { ctx: Arc::new(ctx) };
|
||||
let result = api
|
||||
.create_worktree(Json(CreateWorktreePayload {
|
||||
story_id: "42_story_foo".to_string(),
|
||||
@@ -1147,12 +1087,8 @@ allowed_tools = ["Read", "Bash"]
|
||||
let tmp = TempDir::new().unwrap();
|
||||
let ctx = AppContext::new_test(tmp.path().to_path_buf());
|
||||
*ctx.state.project_root.lock().unwrap() = None;
|
||||
let api = AgentsApi {
|
||||
ctx: Arc::new(ctx),
|
||||
};
|
||||
let result = api
|
||||
.remove_worktree(Path("42_story_foo".to_string()))
|
||||
.await;
|
||||
let api = AgentsApi { ctx: Arc::new(ctx) };
|
||||
let result = api.remove_worktree(Path("42_story_foo".to_string())).await;
|
||||
assert!(result.is_err());
|
||||
}
|
||||
|
||||
@@ -1161,9 +1097,7 @@ allowed_tools = ["Read", "Bash"]
|
||||
let tmp = TempDir::new().unwrap();
|
||||
// project_root is set but no worktree exists for this story_id
|
||||
let ctx = AppContext::new_test(tmp.path().to_path_buf());
|
||||
let api = AgentsApi {
|
||||
ctx: Arc::new(ctx),
|
||||
};
|
||||
let api = AgentsApi { ctx: Arc::new(ctx) };
|
||||
let result = api
|
||||
.remove_worktree(Path("nonexistent_story".to_string()))
|
||||
.await;
|
||||
@@ -1177,9 +1111,7 @@ allowed_tools = ["Read", "Bash"]
|
||||
let tmp = TempDir::new().unwrap();
|
||||
let root = make_work_dirs(&tmp);
|
||||
let ctx = AppContext::new_test(root);
|
||||
let api = AgentsApi {
|
||||
ctx: Arc::new(ctx),
|
||||
};
|
||||
let api = AgentsApi { ctx: Arc::new(ctx) };
|
||||
let result = api
|
||||
.get_test_results(Path("42_story_foo".to_string()))
|
||||
.await
|
||||
@@ -1214,9 +1146,7 @@ allowed_tools = ["Read", "Bash"]
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
let api = AgentsApi {
|
||||
ctx: Arc::new(ctx),
|
||||
};
|
||||
let api = AgentsApi { ctx: Arc::new(ctx) };
|
||||
let result = api
|
||||
.get_test_results(Path("42_story_foo".to_string()))
|
||||
.await
|
||||
@@ -1255,7 +1185,7 @@ name: "Test story"
|
||||
|
||||
## Test Results
|
||||
|
||||
<!-- story-kit-test-results: {"unit":[{"name":"from_file","status":"pass","details":null}],"integration":[]} -->
|
||||
<!-- storkit-test-results: {"unit":[{"name":"from_file","status":"pass","details":null}],"integration":[]} -->
|
||||
"#;
|
||||
std::fs::write(
|
||||
root.join(".storkit/work/2_current/42_story_foo.md"),
|
||||
@@ -1264,9 +1194,7 @@ name: "Test story"
|
||||
.unwrap();
|
||||
|
||||
let ctx = AppContext::new_test(root);
|
||||
let api = AgentsApi {
|
||||
ctx: Arc::new(ctx),
|
||||
};
|
||||
let api = AgentsApi { ctx: Arc::new(ctx) };
|
||||
let result = api
|
||||
.get_test_results(Path("42_story_foo".to_string()))
|
||||
.await
|
||||
|
||||
@@ -3,7 +3,7 @@ use crate::http::context::AppContext;
|
||||
use crate::log_buffer;
|
||||
use crate::slog;
|
||||
use crate::slog_warn;
|
||||
use serde_json::{json, Value};
|
||||
use serde_json::{Value, json};
|
||||
use std::fs;
|
||||
|
||||
pub(super) fn tool_get_server_logs(args: &Value) -> Result<String, String> {
|
||||
@@ -29,7 +29,7 @@ pub(super) fn tool_get_server_logs(args: &Value) -> Result<String, String> {
|
||||
/// Rebuild the server binary and re-exec.
|
||||
///
|
||||
/// 1. Gracefully stops all running agents (kills PTY children).
|
||||
/// 2. Runs `cargo build [-p story-kit]` from the workspace root, matching
|
||||
/// 2. Runs `cargo build [-p storkit]` from the workspace root, matching
|
||||
/// the current build profile (debug or release).
|
||||
/// 3. If the build fails, returns the build error (server stays up).
|
||||
/// 4. If the build succeeds, re-execs the process with the new binary via
|
||||
@@ -92,8 +92,8 @@ pub(super) async fn tool_rebuild_and_restart(ctx: &AppContext) -> Result<String,
|
||||
|
||||
// 4. Re-exec with the new binary.
|
||||
// Collect current argv so we preserve any CLI arguments (e.g. project path).
|
||||
let current_exe = std::env::current_exe()
|
||||
.map_err(|e| format!("Cannot determine current executable: {e}"))?;
|
||||
let current_exe =
|
||||
std::env::current_exe().map_err(|e| format!("Cannot determine current executable: {e}"))?;
|
||||
let args: Vec<String> = std::env::args().collect();
|
||||
|
||||
// Remove the port file before re-exec so the new process can write its own.
|
||||
@@ -124,7 +124,7 @@ pub(super) async fn tool_rebuild_and_restart(ctx: &AppContext) -> Result<String,
|
||||
///
|
||||
/// - `Edit` / `Write` / `Read` / `Grep` / `Glob` etc. → just the tool name
|
||||
/// - `Bash` → `Bash(first_word *)` derived from the `command` field in `tool_input`
|
||||
/// - `mcp__*` → the full tool name (e.g. `mcp__story-kit__create_story`)
|
||||
/// - `mcp__*` → the full tool name (e.g. `mcp__storkit__create_story`)
|
||||
fn generate_permission_rule(tool_name: &str, tool_input: &Value) -> String {
|
||||
if tool_name == "Bash" {
|
||||
// Extract command from tool_input.command and use first word as prefix
|
||||
@@ -142,7 +142,10 @@ fn generate_permission_rule(tool_name: &str, tool_input: &Value) -> String {
|
||||
|
||||
/// Add a permission rule to `.claude/settings.json` in the project root.
|
||||
/// Does nothing if the rule already exists. Creates the file if missing.
|
||||
pub(super) fn add_permission_rule(project_root: &std::path::Path, rule: &str) -> Result<(), String> {
|
||||
pub(super) fn add_permission_rule(
|
||||
project_root: &std::path::Path,
|
||||
rule: &str,
|
||||
) -> Result<(), String> {
|
||||
let claude_dir = project_root.join(".claude");
|
||||
fs::create_dir_all(&claude_dir)
|
||||
.map_err(|e| format!("Failed to create .claude/ directory: {e}"))?;
|
||||
@@ -151,8 +154,7 @@ pub(super) fn add_permission_rule(project_root: &std::path::Path, rule: &str) ->
|
||||
let mut settings: Value = if settings_path.exists() {
|
||||
let content = fs::read_to_string(&settings_path)
|
||||
.map_err(|e| format!("Failed to read settings.json: {e}"))?;
|
||||
serde_json::from_str(&content)
|
||||
.map_err(|e| format!("Failed to parse settings.json: {e}"))?
|
||||
serde_json::from_str(&content).map_err(|e| format!("Failed to parse settings.json: {e}"))?
|
||||
} else {
|
||||
json!({ "permissions": { "allow": [] } })
|
||||
};
|
||||
@@ -184,8 +186,8 @@ pub(super) fn add_permission_rule(project_root: &std::path::Path, rule: &str) ->
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// Also check for wildcard coverage: if "mcp__story-kit__*" exists, don't add
|
||||
// a more specific "mcp__story-kit__create_story".
|
||||
// Also check for wildcard coverage: if "mcp__storkit__*" exists, don't add
|
||||
// a more specific "mcp__storkit__create_story".
|
||||
let dominated = allow.iter().any(|existing| {
|
||||
if let Some(pat) = existing.as_str()
|
||||
&& let Some(prefix) = pat.strip_suffix('*')
|
||||
@@ -202,8 +204,7 @@ pub(super) fn add_permission_rule(project_root: &std::path::Path, rule: &str) ->
|
||||
|
||||
let pretty =
|
||||
serde_json::to_string_pretty(&settings).map_err(|e| format!("Failed to serialize: {e}"))?;
|
||||
fs::write(&settings_path, pretty)
|
||||
.map_err(|e| format!("Failed to write settings.json: {e}"))?;
|
||||
fs::write(&settings_path, pretty).map_err(|e| format!("Failed to write settings.json: {e}"))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -212,16 +213,16 @@ pub(super) fn add_permission_rule(project_root: &std::path::Path, rule: &str) ->
|
||||
/// Forwards the permission request through the shared channel to the active
|
||||
/// WebSocket session, which presents a dialog to the user. Blocks until the
|
||||
/// user approves or denies (with a 5-minute timeout).
|
||||
pub(super) async fn tool_prompt_permission(args: &Value, ctx: &AppContext) -> Result<String, String> {
|
||||
pub(super) async fn tool_prompt_permission(
|
||||
args: &Value,
|
||||
ctx: &AppContext,
|
||||
) -> Result<String, String> {
|
||||
let tool_name = args
|
||||
.get("tool_name")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("unknown")
|
||||
.to_string();
|
||||
let tool_input = args
|
||||
.get("input")
|
||||
.cloned()
|
||||
.unwrap_or(json!({}));
|
||||
let tool_input = args.get("input").cloned().unwrap_or(json!({}));
|
||||
|
||||
let request_id = uuid::Uuid::new_v4().to_string();
|
||||
let (response_tx, response_rx) = tokio::sync::oneshot::channel();
|
||||
@@ -237,17 +238,14 @@ pub(super) async fn tool_prompt_permission(args: &Value, ctx: &AppContext) -> Re
|
||||
|
||||
use crate::http::context::PermissionDecision;
|
||||
|
||||
let decision = tokio::time::timeout(
|
||||
std::time::Duration::from_secs(300),
|
||||
response_rx,
|
||||
)
|
||||
.await
|
||||
.map_err(|_| {
|
||||
let msg = format!("Permission request for '{tool_name}' timed out after 5 minutes");
|
||||
slog_warn!("[permission] {msg}");
|
||||
msg
|
||||
})?
|
||||
.map_err(|_| "Permission response channel closed unexpectedly".to_string())?;
|
||||
let decision = tokio::time::timeout(std::time::Duration::from_secs(300), response_rx)
|
||||
.await
|
||||
.map_err(|_| {
|
||||
let msg = format!("Permission request for '{tool_name}' timed out after 5 minutes");
|
||||
slog_warn!("[permission] {msg}");
|
||||
msg
|
||||
})?
|
||||
.map_err(|_| "Permission response channel closed unexpectedly".to_string())?;
|
||||
|
||||
if decision == PermissionDecision::AlwaysAllow {
|
||||
// Persist the rule so Claude Code won't prompt again for this tool.
|
||||
@@ -362,9 +360,11 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn tool_get_server_logs_with_filter_returns_matching_lines() {
|
||||
let result =
|
||||
tool_get_server_logs(&json!({"filter": "xyz_unlikely_match_999"})).unwrap();
|
||||
assert_eq!(result, "", "filter with no matches should return empty string");
|
||||
let result = tool_get_server_logs(&json!({"filter": "xyz_unlikely_match_999"})).unwrap();
|
||||
assert_eq!(
|
||||
result, "",
|
||||
"filter with no matches should return empty string"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -431,13 +431,13 @@ mod tests {
|
||||
cache_read_input_tokens: 0,
|
||||
total_cost_usd: 0.5,
|
||||
};
|
||||
let r1 = crate::agents::token_usage::build_record("10_story_a", "coder-1", None, usage.clone());
|
||||
let r1 =
|
||||
crate::agents::token_usage::build_record("10_story_a", "coder-1", None, usage.clone());
|
||||
let r2 = crate::agents::token_usage::build_record("20_story_b", "coder-2", None, usage);
|
||||
crate::agents::token_usage::append_record(root, &r1).unwrap();
|
||||
crate::agents::token_usage::append_record(root, &r2).unwrap();
|
||||
|
||||
let result =
|
||||
tool_get_token_usage(&json!({"story_id": "10_story_a"}), &ctx).unwrap();
|
||||
let result = tool_get_token_usage(&json!({"story_id": "10_story_a"}), &ctx).unwrap();
|
||||
let parsed: Value = serde_json::from_str(&result).unwrap();
|
||||
assert_eq!(parsed["records"].as_array().unwrap().len(), 1);
|
||||
assert_eq!(parsed["records"][0]["story_id"], "10_story_a");
|
||||
@@ -454,7 +454,9 @@ mod tests {
|
||||
tokio::spawn(async move {
|
||||
let mut rx = perm_rx.lock().await;
|
||||
if let Some(forward) = rx.recv().await {
|
||||
let _ = forward.response_tx.send(crate::http::context::PermissionDecision::Approve);
|
||||
let _ = forward
|
||||
.response_tx
|
||||
.send(crate::http::context::PermissionDecision::Approve);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -486,19 +488,21 @@ mod tests {
|
||||
tokio::spawn(async move {
|
||||
let mut rx = perm_rx.lock().await;
|
||||
if let Some(forward) = rx.recv().await {
|
||||
let _ = forward.response_tx.send(crate::http::context::PermissionDecision::Deny);
|
||||
let _ = forward
|
||||
.response_tx
|
||||
.send(crate::http::context::PermissionDecision::Deny);
|
||||
}
|
||||
});
|
||||
|
||||
let result = tool_prompt_permission(
|
||||
&json!({"tool_name": "Write", "input": {}}),
|
||||
&ctx,
|
||||
)
|
||||
.await
|
||||
.expect("denial must return Ok, not Err");
|
||||
let result = tool_prompt_permission(&json!({"tool_name": "Write", "input": {}}), &ctx)
|
||||
.await
|
||||
.expect("denial must return Ok, not Err");
|
||||
|
||||
let parsed: Value = serde_json::from_str(&result).expect("result should be valid JSON");
|
||||
assert_eq!(parsed["behavior"], "deny", "denied must return behavior:deny");
|
||||
assert_eq!(
|
||||
parsed["behavior"], "deny",
|
||||
"denied must return behavior:deny"
|
||||
);
|
||||
assert!(parsed["message"].is_string(), "deny must include a message");
|
||||
}
|
||||
|
||||
@@ -518,15 +522,13 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn generate_rule_for_bash_git() {
|
||||
let rule =
|
||||
generate_permission_rule("Bash", &json!({"command": "git status"}));
|
||||
let rule = generate_permission_rule("Bash", &json!({"command": "git status"}));
|
||||
assert_eq!(rule, "Bash(git *)");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn generate_rule_for_bash_cargo() {
|
||||
let rule =
|
||||
generate_permission_rule("Bash", &json!({"command": "cargo test --all"}));
|
||||
let rule = generate_permission_rule("Bash", &json!({"command": "cargo test --all"}));
|
||||
assert_eq!(rule, "Bash(cargo *)");
|
||||
}
|
||||
|
||||
@@ -538,11 +540,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn generate_rule_for_mcp_tool() {
|
||||
let rule = generate_permission_rule(
|
||||
"mcp__story-kit__create_story",
|
||||
&json!({"name": "foo"}),
|
||||
);
|
||||
assert_eq!(rule, "mcp__story-kit__create_story");
|
||||
let rule = generate_permission_rule("mcp__storkit__create_story", &json!({"name": "foo"}));
|
||||
assert_eq!(rule, "mcp__storkit__create_story");
|
||||
}
|
||||
|
||||
// ── Settings.json writing tests ──────────────────────────────
|
||||
@@ -578,17 +577,17 @@ mod tests {
|
||||
fs::create_dir_all(&claude_dir).unwrap();
|
||||
fs::write(
|
||||
claude_dir.join("settings.json"),
|
||||
r#"{"permissions":{"allow":["mcp__story-kit__*"]}}"#,
|
||||
r#"{"permissions":{"allow":["mcp__storkit__*"]}}"#,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
add_permission_rule(tmp.path(), "mcp__story-kit__create_story").unwrap();
|
||||
add_permission_rule(tmp.path(), "mcp__storkit__create_story").unwrap();
|
||||
|
||||
let content = fs::read_to_string(claude_dir.join("settings.json")).unwrap();
|
||||
let settings: Value = serde_json::from_str(&content).unwrap();
|
||||
let allow = settings["permissions"]["allow"].as_array().unwrap();
|
||||
assert_eq!(allow.len(), 1);
|
||||
assert_eq!(allow[0], "mcp__story-kit__*");
|
||||
assert_eq!(allow[0], "mcp__storkit__*");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -634,7 +633,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn rebuild_and_restart_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"] == "rebuild_and_restart");
|
||||
@@ -687,7 +686,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn move_story_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"] == "move_story");
|
||||
@@ -814,6 +813,10 @@ mod tests {
|
||||
&ctx,
|
||||
);
|
||||
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")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ use crate::agents::{move_story_to_merge, move_story_to_qa, reject_story_from_qa}
|
||||
use crate::http::context::AppContext;
|
||||
use crate::slog;
|
||||
use crate::slog_warn;
|
||||
use serde_json::{json, Value};
|
||||
use serde_json::{Value, json};
|
||||
|
||||
pub(super) async fn tool_request_qa(args: &Value, ctx: &AppContext) -> Result<String, String> {
|
||||
let story_id = args
|
||||
@@ -160,7 +160,7 @@ pub(super) async fn tool_launch_qa_app(args: &Value, ctx: &AppContext) -> Result
|
||||
// Launch the server from the worktree
|
||||
let child = std::process::Command::new("cargo")
|
||||
.args(["run"])
|
||||
.env("STORYKIT_PORT", port.to_string())
|
||||
.env("STORKIT_PORT", port.to_string())
|
||||
.current_dir(&wt_path)
|
||||
.stdout(std::process::Stdio::null())
|
||||
.stderr(std::process::Stdio::null())
|
||||
@@ -202,7 +202,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn request_qa_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"] == "request_qa");
|
||||
@@ -217,7 +217,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn approve_qa_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"] == "approve_qa");
|
||||
@@ -230,7 +230,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn reject_qa_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"] == "reject_qa");
|
||||
@@ -244,7 +244,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn launch_qa_app_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"] == "launch_qa_app");
|
||||
|
||||
@@ -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"));
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ pub fn parse_port(value: Option<String>) -> u16 {
|
||||
}
|
||||
|
||||
pub fn resolve_port() -> u16 {
|
||||
parse_port(std::env::var("STORYKIT_PORT").ok())
|
||||
parse_port(std::env::var("STORKIT_PORT").ok())
|
||||
}
|
||||
|
||||
pub fn write_port_file(dir: &Path, port: u16) -> Option<PathBuf> {
|
||||
@@ -194,7 +194,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn resolve_port_returns_a_valid_port() {
|
||||
// Exercises the resolve_port code path (reads STORYKIT_PORT env var or defaults).
|
||||
// Exercises the resolve_port code path (reads STORKIT_PORT env var or defaults).
|
||||
let port = resolve_port();
|
||||
assert!(port > 0);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use std::path::Path;
|
||||
|
||||
use super::{find_story_file, replace_or_append_section};
|
||||
|
||||
const TEST_RESULTS_MARKER: &str = "<!-- story-kit-test-results:";
|
||||
const TEST_RESULTS_MARKER: &str = "<!-- storkit-test-results:";
|
||||
|
||||
/// Write (or overwrite) the `## Test Results` section in a story file.
|
||||
///
|
||||
@@ -27,8 +27,7 @@ pub fn write_test_results_to_story_file(
|
||||
let section = build_test_results_section(&json, results);
|
||||
let new_contents = replace_or_append_section(&contents, "## Test Results", §ion);
|
||||
|
||||
fs::write(&path, &new_contents)
|
||||
.map_err(|e| format!("Failed to write story file: {e}"))?;
|
||||
fs::write(&path, &new_contents).map_err(|e| format!("Failed to write story file: {e}"))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -95,12 +94,19 @@ fn build_test_results_section(json: &str, results: &StoryTestResults) -> String
|
||||
}
|
||||
|
||||
fn count_pass_fail(tests: &[TestCaseResult]) -> (usize, usize) {
|
||||
let pass = tests.iter().filter(|t| t.status == TestStatus::Pass).count();
|
||||
let pass = tests
|
||||
.iter()
|
||||
.filter(|t| t.status == TestStatus::Pass)
|
||||
.count();
|
||||
(pass, tests.len() - pass)
|
||||
}
|
||||
|
||||
fn format_test_line(t: &TestCaseResult) -> String {
|
||||
let icon = if t.status == TestStatus::Pass { "✅" } else { "❌" };
|
||||
let icon = if t.status == TestStatus::Pass {
|
||||
"✅"
|
||||
} else {
|
||||
"❌"
|
||||
};
|
||||
match &t.details {
|
||||
Some(d) if !d.is_empty() => format!("- {icon} {} — {d}\n", t.name),
|
||||
_ => format!("- {icon} {}\n", t.name),
|
||||
@@ -132,12 +138,22 @@ mod tests {
|
||||
fn make_results() -> StoryTestResults {
|
||||
StoryTestResults {
|
||||
unit: vec![
|
||||
TestCaseResult { name: "unit-pass".to_string(), status: TestStatus::Pass, details: None },
|
||||
TestCaseResult { name: "unit-fail".to_string(), status: TestStatus::Fail, details: Some("assertion failed".to_string()) },
|
||||
],
|
||||
integration: vec![
|
||||
TestCaseResult { name: "int-pass".to_string(), status: TestStatus::Pass, details: None },
|
||||
TestCaseResult {
|
||||
name: "unit-pass".to_string(),
|
||||
status: TestStatus::Pass,
|
||||
details: None,
|
||||
},
|
||||
TestCaseResult {
|
||||
name: "unit-fail".to_string(),
|
||||
status: TestStatus::Fail,
|
||||
details: Some("assertion failed".to_string()),
|
||||
},
|
||||
],
|
||||
integration: vec![TestCaseResult {
|
||||
name: "int-pass".to_string(),
|
||||
status: TestStatus::Pass,
|
||||
details: None,
|
||||
}],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,7 +162,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_test.md"), "---\nname: Test\n---\n# Story\n").unwrap();
|
||||
fs::write(
|
||||
current.join("1_story_test.md"),
|
||||
"---\nname: Test\n---\n# Story\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let results = make_results();
|
||||
write_test_results_to_story_file(tmp.path(), "1_story_test", &results).unwrap();
|
||||
@@ -157,7 +177,10 @@ mod tests {
|
||||
assert_eq!(read_back.integration.len(), 1);
|
||||
assert_eq!(read_back.unit[0].name, "unit-pass");
|
||||
assert_eq!(read_back.unit[1].status, TestStatus::Fail);
|
||||
assert_eq!(read_back.unit[1].details.as_deref(), Some("assertion failed"));
|
||||
assert_eq!(
|
||||
read_back.unit[1].details.as_deref(),
|
||||
Some("assertion failed")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -166,7 +189,11 @@ mod tests {
|
||||
let current = tmp.path().join(".storkit/work/2_current");
|
||||
fs::create_dir_all(¤t).unwrap();
|
||||
let story_path = current.join("2_story_check.md");
|
||||
fs::write(&story_path, "---\nname: Check\n---\n# Story\n\n## Acceptance Criteria\n\n- [ ] AC1\n").unwrap();
|
||||
fs::write(
|
||||
&story_path,
|
||||
"---\nname: Check\n---\n# Story\n\n## Acceptance Criteria\n\n- [ ] AC1\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let results = make_results();
|
||||
write_test_results_to_story_file(tmp.path(), "2_story_check", &results).unwrap();
|
||||
@@ -176,7 +203,7 @@ mod tests {
|
||||
assert!(contents.contains("✅ unit-pass"));
|
||||
assert!(contents.contains("❌ unit-fail"));
|
||||
assert!(contents.contains("assertion failed"));
|
||||
assert!(contents.contains("story-kit-test-results:"));
|
||||
assert!(contents.contains("storkit-test-results:"));
|
||||
// Original content still present
|
||||
assert!(contents.contains("## Acceptance Criteria"));
|
||||
}
|
||||
@@ -189,7 +216,7 @@ mod tests {
|
||||
let story_path = current.join("3_story_overwrite.md");
|
||||
fs::write(
|
||||
&story_path,
|
||||
"---\nname: Overwrite\n---\n# Story\n\n## Test Results\n\n<!-- story-kit-test-results: {} -->\n\n### Unit Tests (0 passed, 0 failed)\n\n*No unit tests recorded.*\n",
|
||||
"---\nname: Overwrite\n---\n# Story\n\n## Test Results\n\n<!-- storkit-test-results: {} -->\n\n### Unit Tests (0 passed, 0 failed)\n\n*No unit tests recorded.*\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@@ -208,7 +235,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("4_story_empty.md"), "---\nname: Empty\n---\n# Story\n").unwrap();
|
||||
fs::write(
|
||||
current.join("4_story_empty.md"),
|
||||
"---\nname: Empty\n---\n# Story\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let result = read_test_results_from_story_file(tmp.path(), "4_story_empty");
|
||||
assert!(result.is_none());
|
||||
@@ -226,10 +257,18 @@ mod tests {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let qa_dir = tmp.path().join(".storkit/work/3_qa");
|
||||
fs::create_dir_all(&qa_dir).unwrap();
|
||||
fs::write(qa_dir.join("5_story_qa.md"), "---\nname: QA Story\n---\n# Story\n").unwrap();
|
||||
fs::write(
|
||||
qa_dir.join("5_story_qa.md"),
|
||||
"---\nname: QA Story\n---\n# Story\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let results = StoryTestResults {
|
||||
unit: vec![TestCaseResult { name: "u1".to_string(), status: TestStatus::Pass, details: None }],
|
||||
unit: vec![TestCaseResult {
|
||||
name: "u1".to_string(),
|
||||
status: TestStatus::Pass,
|
||||
details: None,
|
||||
}],
|
||||
integration: vec![],
|
||||
};
|
||||
write_test_results_to_story_file(tmp.path(), "5_story_qa", &results).unwrap();
|
||||
@@ -243,12 +282,19 @@ 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("6_story_cov.md"), "---\nname: Cov Story\n---\n# Story\n").unwrap();
|
||||
fs::write(
|
||||
current.join("6_story_cov.md"),
|
||||
"---\nname: Cov Story\n---\n# Story\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
write_coverage_baseline_to_story_file(tmp.path(), "6_story_cov", 75.4).unwrap();
|
||||
|
||||
let contents = fs::read_to_string(current.join("6_story_cov.md")).unwrap();
|
||||
assert!(contents.contains("coverage_baseline: 75.4%"), "got: {contents}");
|
||||
assert!(
|
||||
contents.contains("coverage_baseline: 75.4%"),
|
||||
"got: {contents}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -555,7 +555,10 @@ mod tests {
|
||||
match req {
|
||||
WsRequest::Chat { messages, config } => {
|
||||
assert!(messages.is_empty());
|
||||
assert_eq!(config.base_url.as_deref(), Some("https://api.anthropic.com"));
|
||||
assert_eq!(
|
||||
config.base_url.as_deref(),
|
||||
Some("https://api.anthropic.com")
|
||||
);
|
||||
assert_eq!(config.enable_tools, Some(true));
|
||||
assert_eq!(config.session_id.as_deref(), Some("sess-123"));
|
||||
}
|
||||
@@ -719,14 +722,14 @@ mod tests {
|
||||
stage: "2_current".to_string(),
|
||||
item_id: "42_story_foo".to_string(),
|
||||
action: "start".to_string(),
|
||||
commit_msg: "story-kit: start 42_story_foo".to_string(),
|
||||
commit_msg: "storkit: start 42_story_foo".to_string(),
|
||||
};
|
||||
let json = serde_json::to_value(&resp).unwrap();
|
||||
assert_eq!(json["type"], "work_item_changed");
|
||||
assert_eq!(json["stage"], "2_current");
|
||||
assert_eq!(json["item_id"], "42_story_foo");
|
||||
assert_eq!(json["action"], "start");
|
||||
assert_eq!(json["commit_msg"], "story-kit: start 42_story_foo");
|
||||
assert_eq!(json["commit_msg"], "storkit: start 42_story_foo");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -847,7 +850,7 @@ mod tests {
|
||||
stage: "2_current".to_string(),
|
||||
item_id: "42_story_foo".to_string(),
|
||||
action: "start".to_string(),
|
||||
commit_msg: "story-kit: start 42_story_foo".to_string(),
|
||||
commit_msg: "storkit: start 42_story_foo".to_string(),
|
||||
};
|
||||
let ws_msg: Option<WsResponse> = evt.into();
|
||||
let ws_msg = ws_msg.expect("WorkItem should produce Some");
|
||||
@@ -1126,9 +1129,7 @@ mod tests {
|
||||
|
||||
tokio::spawn(async move {
|
||||
let acceptor = poem::listener::TcpAcceptor::from_tokio(listener).unwrap();
|
||||
let _ = poem::Server::new_with_acceptor(acceptor)
|
||||
.run(app)
|
||||
.await;
|
||||
let _ = poem::Server::new_with_acceptor(acceptor).run(app).await;
|
||||
});
|
||||
|
||||
// Small delay to let the server start.
|
||||
@@ -1256,17 +1257,12 @@ mod tests {
|
||||
let (mut sink, mut stream, _initial) = connect_ws(&url).await;
|
||||
|
||||
// Send invalid JSON.
|
||||
sink.send(ws_text("not valid json"))
|
||||
.await
|
||||
.unwrap();
|
||||
sink.send(ws_text("not valid json")).await.unwrap();
|
||||
|
||||
let msg = next_msg(&mut stream).await;
|
||||
assert_eq!(msg["type"], "error");
|
||||
assert!(
|
||||
msg["message"]
|
||||
.as_str()
|
||||
.unwrap()
|
||||
.contains("Invalid request"),
|
||||
msg["message"].as_str().unwrap().contains("Invalid request"),
|
||||
"error message should indicate invalid request, got: {}",
|
||||
msg["message"]
|
||||
);
|
||||
@@ -1278,9 +1274,7 @@ mod tests {
|
||||
let (mut sink, mut stream, _initial) = connect_ws(&url).await;
|
||||
|
||||
// Send a message with an unknown type.
|
||||
sink.send(ws_text(r#"{"type": "bogus"}"#))
|
||||
.await
|
||||
.unwrap();
|
||||
sink.send(ws_text(r#"{"type": "bogus"}"#)).await.unwrap();
|
||||
|
||||
let msg = next_msg(&mut stream).await;
|
||||
assert_eq!(msg["type"], "error");
|
||||
@@ -1293,14 +1287,10 @@ mod tests {
|
||||
let (mut sink, mut stream, _initial) = connect_ws(&url).await;
|
||||
|
||||
// Send cancel when no chat is active — should not produce an error.
|
||||
sink.send(ws_text(r#"{"type": "cancel"}"#))
|
||||
.await
|
||||
.unwrap();
|
||||
sink.send(ws_text(r#"{"type": "cancel"}"#)).await.unwrap();
|
||||
|
||||
// Send another invalid message to check the connection is still alive.
|
||||
sink.send(ws_text("{}"))
|
||||
.await
|
||||
.unwrap();
|
||||
sink.send(ws_text("{}")).await.unwrap();
|
||||
|
||||
let msg = next_msg(&mut stream).await;
|
||||
// The invalid JSON message should produce an error, confirming
|
||||
@@ -1321,9 +1311,7 @@ mod tests {
|
||||
.unwrap();
|
||||
|
||||
// Send a probe message to check the connection is still alive.
|
||||
sink.send(ws_text("bad"))
|
||||
.await
|
||||
.unwrap();
|
||||
sink.send(ws_text("bad")).await.unwrap();
|
||||
|
||||
let msg = next_msg(&mut stream).await;
|
||||
assert_eq!(msg["type"], "error");
|
||||
@@ -1341,7 +1329,7 @@ mod tests {
|
||||
stage: "2_current".to_string(),
|
||||
item_id: "99_story_test".to_string(),
|
||||
action: "start".to_string(),
|
||||
commit_msg: "story-kit: start 99_story_test".to_string(),
|
||||
commit_msg: "storkit: start 99_story_test".to_string(),
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user