2026-02-20 19:39:19 +00:00
|
|
|
use crate::http::context::AppContext;
|
|
|
|
|
use crate::io::story_metadata::parse_front_matter;
|
|
|
|
|
use serde::Serialize;
|
2026-02-19 12:54:04 +00:00
|
|
|
use std::fs;
|
2026-02-20 15:31:13 +00:00
|
|
|
use std::path::{Path, PathBuf};
|
2026-02-19 12:54:04 +00:00
|
|
|
|
2026-02-20 19:39:19 +00:00
|
|
|
#[derive(Clone, Debug, Serialize)]
|
Accept spike 2: MCP HTTP endpoint for workflow and agent tools
Adds POST /mcp endpoint speaking MCP Streamable HTTP (JSON-RPC 2.0)
with 12 tools for workflow management and agent orchestration.
Supports both JSON and SSE response modes. Includes real-time agent
output streaming over SSE, Content-Type validation, and 15 integration
tests (134 total).
Tools: create_story, validate_stories, list_upcoming, get_story_todos,
record_tests, ensure_acceptance, start_agent, stop_agent, list_agents,
get_agent_config, reload_agent_config, get_agent_output.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 19:34:03 +00:00
|
|
|
pub struct UpcomingStory {
|
2026-02-19 15:51:12 +00:00
|
|
|
pub story_id: String,
|
|
|
|
|
pub name: Option<String>,
|
2026-02-19 18:02:48 +00:00
|
|
|
pub error: Option<String>,
|
2026-02-19 15:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
Accept spike 2: MCP HTTP endpoint for workflow and agent tools
Adds POST /mcp endpoint speaking MCP Streamable HTTP (JSON-RPC 2.0)
with 12 tools for workflow management and agent orchestration.
Supports both JSON and SSE response modes. Includes real-time agent
output streaming over SSE, Content-Type validation, and 15 integration
tests (134 total).
Tools: create_story, validate_stories, list_upcoming, get_story_todos,
record_tests, ensure_acceptance, start_agent, stop_agent, list_agents,
get_agent_config, reload_agent_config, get_agent_output.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 19:34:03 +00:00
|
|
|
pub struct StoryValidationResult {
|
2026-02-19 18:02:48 +00:00
|
|
|
pub story_id: String,
|
|
|
|
|
pub valid: bool,
|
|
|
|
|
pub error: Option<String>,
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-20 19:39:19 +00:00
|
|
|
/// Full pipeline state across all stages.
|
|
|
|
|
#[derive(Clone, Debug, Serialize)]
|
|
|
|
|
pub struct PipelineState {
|
|
|
|
|
pub upcoming: Vec<UpcomingStory>,
|
|
|
|
|
pub current: Vec<UpcomingStory>,
|
|
|
|
|
pub qa: Vec<UpcomingStory>,
|
|
|
|
|
pub merge: Vec<UpcomingStory>,
|
2026-02-19 18:02:48 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-20 19:39:19 +00:00
|
|
|
/// Load the full pipeline state (all 4 active stages).
|
|
|
|
|
pub fn load_pipeline_state(ctx: &AppContext) -> Result<PipelineState, String> {
|
|
|
|
|
Ok(PipelineState {
|
|
|
|
|
upcoming: load_stage_items(ctx, "1_upcoming")?,
|
|
|
|
|
current: load_stage_items(ctx, "2_current")?,
|
|
|
|
|
qa: load_stage_items(ctx, "3_qa")?,
|
|
|
|
|
merge: load_stage_items(ctx, "4_merge")?,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Load work items from any pipeline stage directory.
|
|
|
|
|
fn load_stage_items(ctx: &AppContext, stage_dir: &str) -> Result<Vec<UpcomingStory>, String> {
|
2026-02-19 15:51:12 +00:00
|
|
|
let root = ctx.state.get_project_root()?;
|
2026-02-20 19:39:19 +00:00
|
|
|
let dir = root.join(".story_kit").join("work").join(stage_dir);
|
2026-02-19 15:51:12 +00:00
|
|
|
|
2026-02-20 19:39:19 +00:00
|
|
|
if !dir.exists() {
|
2026-02-19 15:51:12 +00:00
|
|
|
return Ok(Vec::new());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let mut stories = Vec::new();
|
2026-02-20 19:39:19 +00:00
|
|
|
for entry in fs::read_dir(&dir)
|
|
|
|
|
.map_err(|e| format!("Failed to read {stage_dir} directory: {e}"))?
|
2026-02-19 15:51:12 +00:00
|
|
|
{
|
2026-02-20 19:39:19 +00:00
|
|
|
let entry = entry.map_err(|e| format!("Failed to read {stage_dir} entry: {e}"))?;
|
2026-02-19 15:51:12 +00:00
|
|
|
let path = entry.path();
|
|
|
|
|
if path.extension().and_then(|ext| ext.to_str()) != Some("md") {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
let story_id = path
|
|
|
|
|
.file_stem()
|
|
|
|
|
.and_then(|stem| stem.to_str())
|
|
|
|
|
.ok_or_else(|| "Invalid story file name.".to_string())?
|
|
|
|
|
.to_string();
|
|
|
|
|
let contents = fs::read_to_string(&path)
|
|
|
|
|
.map_err(|e| format!("Failed to read story file {}: {e}", path.display()))?;
|
2026-02-19 18:02:48 +00:00
|
|
|
let (name, error) = match parse_front_matter(&contents) {
|
|
|
|
|
Ok(meta) => (meta.name, None),
|
|
|
|
|
Err(e) => (None, Some(e.to_string())),
|
|
|
|
|
};
|
|
|
|
|
stories.push(UpcomingStory { story_id, name, error });
|
2026-02-19 15:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stories.sort_by(|a, b| a.story_id.cmp(&b.story_id));
|
|
|
|
|
Ok(stories)
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-20 19:39:19 +00:00
|
|
|
pub fn load_upcoming_stories(ctx: &AppContext) -> Result<Vec<UpcomingStory>, String> {
|
|
|
|
|
load_stage_items(ctx, "1_upcoming")
|
2026-02-19 12:54:04 +00:00
|
|
|
}
|
|
|
|
|
|
Accept spike 2: MCP HTTP endpoint for workflow and agent tools
Adds POST /mcp endpoint speaking MCP Streamable HTTP (JSON-RPC 2.0)
with 12 tools for workflow management and agent orchestration.
Supports both JSON and SSE response modes. Includes real-time agent
output streaming over SSE, Content-Type validation, and 15 integration
tests (134 total).
Tools: create_story, validate_stories, list_upcoming, get_story_todos,
record_tests, ensure_acceptance, start_agent, stop_agent, list_agents,
get_agent_config, reload_agent_config, get_agent_output.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 19:34:03 +00:00
|
|
|
/// Shared create-story logic used by both the OpenApi and MCP handlers.
|
2026-02-20 14:09:52 +00:00
|
|
|
///
|
|
|
|
|
/// When `commit` is `true`, the new story file is git-added and committed to
|
|
|
|
|
/// the current branch immediately after creation.
|
Accept spike 2: MCP HTTP endpoint for workflow and agent tools
Adds POST /mcp endpoint speaking MCP Streamable HTTP (JSON-RPC 2.0)
with 12 tools for workflow management and agent orchestration.
Supports both JSON and SSE response modes. Includes real-time agent
output streaming over SSE, Content-Type validation, and 15 integration
tests (134 total).
Tools: create_story, validate_stories, list_upcoming, get_story_todos,
record_tests, ensure_acceptance, start_agent, stop_agent, list_agents,
get_agent_config, reload_agent_config, get_agent_output.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 19:34:03 +00:00
|
|
|
pub fn create_story_file(
|
|
|
|
|
root: &std::path::Path,
|
|
|
|
|
name: &str,
|
|
|
|
|
user_story: Option<&str>,
|
|
|
|
|
acceptance_criteria: Option<&[String]>,
|
2026-02-20 14:09:52 +00:00
|
|
|
commit: bool,
|
Accept spike 2: MCP HTTP endpoint for workflow and agent tools
Adds POST /mcp endpoint speaking MCP Streamable HTTP (JSON-RPC 2.0)
with 12 tools for workflow management and agent orchestration.
Supports both JSON and SSE response modes. Includes real-time agent
output streaming over SSE, Content-Type validation, and 15 integration
tests (134 total).
Tools: create_story, validate_stories, list_upcoming, get_story_todos,
record_tests, ensure_acceptance, start_agent, stop_agent, list_agents,
get_agent_config, reload_agent_config, get_agent_output.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 19:34:03 +00:00
|
|
|
) -> Result<String, String> {
|
2026-02-20 17:16:48 +00:00
|
|
|
let story_number = next_item_number(root)?;
|
Accept spike 2: MCP HTTP endpoint for workflow and agent tools
Adds POST /mcp endpoint speaking MCP Streamable HTTP (JSON-RPC 2.0)
with 12 tools for workflow management and agent orchestration.
Supports both JSON and SSE response modes. Includes real-time agent
output streaming over SSE, Content-Type validation, and 15 integration
tests (134 total).
Tools: create_story, validate_stories, list_upcoming, get_story_todos,
record_tests, ensure_acceptance, start_agent, stop_agent, list_agents,
get_agent_config, reload_agent_config, get_agent_output.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 19:34:03 +00:00
|
|
|
let slug = slugify_name(name);
|
|
|
|
|
|
|
|
|
|
if slug.is_empty() {
|
|
|
|
|
return Err("Name must contain at least one alphanumeric character.".to_string());
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-20 17:16:48 +00:00
|
|
|
let filename = format!("{story_number}_story_{slug}.md");
|
|
|
|
|
let upcoming_dir = root.join(".story_kit").join("work").join("1_upcoming");
|
Accept spike 2: MCP HTTP endpoint for workflow and agent tools
Adds POST /mcp endpoint speaking MCP Streamable HTTP (JSON-RPC 2.0)
with 12 tools for workflow management and agent orchestration.
Supports both JSON and SSE response modes. Includes real-time agent
output streaming over SSE, Content-Type validation, and 15 integration
tests (134 total).
Tools: create_story, validate_stories, list_upcoming, get_story_todos,
record_tests, ensure_acceptance, start_agent, stop_agent, list_agents,
get_agent_config, reload_agent_config, get_agent_output.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 19:34:03 +00:00
|
|
|
fs::create_dir_all(&upcoming_dir)
|
|
|
|
|
.map_err(|e| format!("Failed to create upcoming directory: {e}"))?;
|
|
|
|
|
|
|
|
|
|
let filepath = upcoming_dir.join(&filename);
|
|
|
|
|
if filepath.exists() {
|
|
|
|
|
return Err(format!("Story file already exists: {filename}"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let story_id = filepath
|
|
|
|
|
.file_stem()
|
|
|
|
|
.and_then(|s| s.to_str())
|
|
|
|
|
.unwrap_or_default()
|
|
|
|
|
.to_string();
|
|
|
|
|
|
|
|
|
|
let mut content = String::new();
|
|
|
|
|
content.push_str("---\n");
|
|
|
|
|
content.push_str(&format!("name: {name}\n"));
|
|
|
|
|
content.push_str("test_plan: pending\n");
|
|
|
|
|
content.push_str("---\n\n");
|
|
|
|
|
content.push_str(&format!("# Story {story_number}: {name}\n\n"));
|
|
|
|
|
|
|
|
|
|
content.push_str("## User Story\n\n");
|
|
|
|
|
if let Some(us) = user_story {
|
|
|
|
|
content.push_str(us);
|
|
|
|
|
content.push('\n');
|
|
|
|
|
} else {
|
|
|
|
|
content.push_str("As a ..., I want ..., so that ...\n");
|
|
|
|
|
}
|
|
|
|
|
content.push('\n');
|
|
|
|
|
|
|
|
|
|
content.push_str("## Acceptance Criteria\n\n");
|
|
|
|
|
if let Some(criteria) = acceptance_criteria {
|
|
|
|
|
for criterion in criteria {
|
|
|
|
|
content.push_str(&format!("- [ ] {criterion}\n"));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
content.push_str("- [ ] TODO\n");
|
|
|
|
|
}
|
|
|
|
|
content.push('\n');
|
|
|
|
|
|
|
|
|
|
content.push_str("## Out of Scope\n\n");
|
|
|
|
|
content.push_str("- TBD\n");
|
|
|
|
|
|
|
|
|
|
fs::write(&filepath, &content)
|
|
|
|
|
.map_err(|e| format!("Failed to write story file: {e}"))?;
|
|
|
|
|
|
2026-02-20 19:39:19 +00:00
|
|
|
// Watcher handles the git commit asynchronously.
|
|
|
|
|
let _ = commit; // kept for API compat, ignored
|
2026-02-20 14:09:52 +00:00
|
|
|
|
Accept spike 2: MCP HTTP endpoint for workflow and agent tools
Adds POST /mcp endpoint speaking MCP Streamable HTTP (JSON-RPC 2.0)
with 12 tools for workflow management and agent orchestration.
Supports both JSON and SSE response modes. Includes real-time agent
output streaming over SSE, Content-Type validation, and 15 integration
tests (134 total).
Tools: create_story, validate_stories, list_upcoming, get_story_todos,
record_tests, ensure_acceptance, start_agent, stop_agent, list_agents,
get_agent_config, reload_agent_config, get_agent_output.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 19:34:03 +00:00
|
|
|
Ok(story_id)
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-20 16:34:32 +00:00
|
|
|
// ── Bug file helpers ──────────────────────────────────────────────
|
|
|
|
|
|
2026-02-20 17:16:48 +00:00
|
|
|
/// Create a bug file in `work/1_upcoming/` with a deterministic filename and auto-commit.
|
2026-02-20 16:34:32 +00:00
|
|
|
///
|
2026-02-20 17:16:48 +00:00
|
|
|
/// Returns the bug_id (e.g. `"4_bug_login_crash"`).
|
2026-02-20 16:34:32 +00:00
|
|
|
pub fn create_bug_file(
|
|
|
|
|
root: &Path,
|
|
|
|
|
name: &str,
|
|
|
|
|
description: &str,
|
|
|
|
|
steps_to_reproduce: &str,
|
|
|
|
|
actual_result: &str,
|
|
|
|
|
expected_result: &str,
|
|
|
|
|
acceptance_criteria: Option<&[String]>,
|
|
|
|
|
) -> Result<String, String> {
|
2026-02-20 17:16:48 +00:00
|
|
|
let bug_number = next_item_number(root)?;
|
2026-02-20 16:34:32 +00:00
|
|
|
let slug = slugify_name(name);
|
|
|
|
|
|
|
|
|
|
if slug.is_empty() {
|
|
|
|
|
return Err("Name must contain at least one alphanumeric character.".to_string());
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-20 17:16:48 +00:00
|
|
|
let filename = format!("{bug_number}_bug_{slug}.md");
|
|
|
|
|
let bugs_dir = root.join(".story_kit").join("work").join("1_upcoming");
|
2026-02-20 16:34:32 +00:00
|
|
|
fs::create_dir_all(&bugs_dir)
|
2026-02-20 17:16:48 +00:00
|
|
|
.map_err(|e| format!("Failed to create upcoming directory: {e}"))?;
|
2026-02-20 16:34:32 +00:00
|
|
|
|
|
|
|
|
let filepath = bugs_dir.join(&filename);
|
|
|
|
|
if filepath.exists() {
|
|
|
|
|
return Err(format!("Bug file already exists: {filename}"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let bug_id = filepath
|
|
|
|
|
.file_stem()
|
|
|
|
|
.and_then(|s| s.to_str())
|
|
|
|
|
.unwrap_or_default()
|
|
|
|
|
.to_string();
|
|
|
|
|
|
|
|
|
|
let mut content = String::new();
|
|
|
|
|
content.push_str(&format!("# Bug {bug_number}: {name}\n\n"));
|
|
|
|
|
content.push_str("## Description\n\n");
|
|
|
|
|
content.push_str(description);
|
|
|
|
|
content.push_str("\n\n");
|
|
|
|
|
content.push_str("## How to Reproduce\n\n");
|
|
|
|
|
content.push_str(steps_to_reproduce);
|
|
|
|
|
content.push_str("\n\n");
|
|
|
|
|
content.push_str("## Actual Result\n\n");
|
|
|
|
|
content.push_str(actual_result);
|
|
|
|
|
content.push_str("\n\n");
|
|
|
|
|
content.push_str("## Expected Result\n\n");
|
|
|
|
|
content.push_str(expected_result);
|
|
|
|
|
content.push_str("\n\n");
|
|
|
|
|
content.push_str("## Acceptance Criteria\n\n");
|
|
|
|
|
if let Some(criteria) = acceptance_criteria {
|
|
|
|
|
for criterion in criteria {
|
|
|
|
|
content.push_str(&format!("- [ ] {criterion}\n"));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
content.push_str("- [ ] Bug is fixed and verified\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fs::write(&filepath, &content).map_err(|e| format!("Failed to write bug file: {e}"))?;
|
|
|
|
|
|
2026-02-20 19:39:19 +00:00
|
|
|
// Watcher handles the git commit asynchronously.
|
2026-02-20 16:34:32 +00:00
|
|
|
|
|
|
|
|
Ok(bug_id)
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-20 17:16:48 +00:00
|
|
|
/// Returns true if the item stem (filename without extension) is a bug item.
|
|
|
|
|
/// Bug items follow the pattern: {N}_bug_{slug}
|
|
|
|
|
fn is_bug_item(stem: &str) -> bool {
|
|
|
|
|
// Format: {digits}_bug_{rest}
|
|
|
|
|
let after_num = stem.trim_start_matches(|c: char| c.is_ascii_digit());
|
|
|
|
|
after_num.starts_with("_bug_")
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-20 16:34:32 +00:00
|
|
|
/// Extract the human-readable name from a bug file's first heading.
|
|
|
|
|
fn extract_bug_name(path: &Path) -> Option<String> {
|
|
|
|
|
let contents = fs::read_to_string(path).ok()?;
|
|
|
|
|
for line in contents.lines() {
|
|
|
|
|
if let Some(rest) = line.strip_prefix("# Bug ") {
|
|
|
|
|
// Format: "N: Name"
|
|
|
|
|
if let Some(colon_pos) = rest.find(": ") {
|
|
|
|
|
return Some(rest[colon_pos + 2..].to_string());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-20 17:16:48 +00:00
|
|
|
/// List all open bugs — files in `work/1_upcoming/` matching the `_bug_` naming pattern.
|
2026-02-20 16:34:32 +00:00
|
|
|
///
|
|
|
|
|
/// Returns a sorted list of `(bug_id, name)` pairs.
|
|
|
|
|
pub fn list_bug_files(root: &Path) -> Result<Vec<(String, String)>, String> {
|
2026-02-20 17:16:48 +00:00
|
|
|
let upcoming_dir = root.join(".story_kit").join("work").join("1_upcoming");
|
|
|
|
|
if !upcoming_dir.exists() {
|
2026-02-20 16:34:32 +00:00
|
|
|
return Ok(Vec::new());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let mut bugs = Vec::new();
|
|
|
|
|
for entry in
|
2026-02-20 17:16:48 +00:00
|
|
|
fs::read_dir(&upcoming_dir).map_err(|e| format!("Failed to read upcoming directory: {e}"))?
|
2026-02-20 16:34:32 +00:00
|
|
|
{
|
|
|
|
|
let entry = entry.map_err(|e| format!("Failed to read entry: {e}"))?;
|
|
|
|
|
let path = entry.path();
|
|
|
|
|
|
|
|
|
|
if path.is_dir() {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if path.extension().and_then(|ext| ext.to_str()) != Some("md") {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-20 17:16:48 +00:00
|
|
|
let stem = path
|
2026-02-20 16:34:32 +00:00
|
|
|
.file_stem()
|
2026-02-20 17:16:48 +00:00
|
|
|
.and_then(|s| s.to_str())
|
|
|
|
|
.ok_or_else(|| "Invalid file name.".to_string())?;
|
|
|
|
|
|
|
|
|
|
// Only include bug items: {N}_bug_{slug}
|
|
|
|
|
if !is_bug_item(stem) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2026-02-20 16:34:32 +00:00
|
|
|
|
2026-02-20 17:16:48 +00:00
|
|
|
let bug_id = stem.to_string();
|
2026-02-20 16:34:32 +00:00
|
|
|
let name = extract_bug_name(&path).unwrap_or_else(|| bug_id.clone());
|
|
|
|
|
bugs.push((bug_id, name));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bugs.sort_by(|a, b| a.0.cmp(&b.0));
|
|
|
|
|
Ok(bugs)
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-20 17:16:48 +00:00
|
|
|
/// Locate a work item file by searching work/2_current/ then work/1_upcoming/.
|
2026-02-20 15:31:13 +00:00
|
|
|
fn find_story_file(project_root: &Path, story_id: &str) -> Result<PathBuf, String> {
|
|
|
|
|
let filename = format!("{story_id}.md");
|
2026-02-20 17:16:48 +00:00
|
|
|
let sk = project_root.join(".story_kit").join("work");
|
|
|
|
|
// Check 2_current/ first
|
|
|
|
|
let current_path = sk.join("2_current").join(&filename);
|
2026-02-20 16:21:30 +00:00
|
|
|
if current_path.exists() {
|
|
|
|
|
return Ok(current_path);
|
|
|
|
|
}
|
2026-02-20 17:16:48 +00:00
|
|
|
// Fall back to 1_upcoming/
|
|
|
|
|
let upcoming_path = sk.join("1_upcoming").join(&filename);
|
2026-02-20 16:21:30 +00:00
|
|
|
if upcoming_path.exists() {
|
|
|
|
|
return Ok(upcoming_path);
|
2026-02-20 15:31:13 +00:00
|
|
|
}
|
|
|
|
|
Err(format!(
|
2026-02-20 17:16:48 +00:00
|
|
|
"Story '{story_id}' not found in work/2_current/ or work/1_upcoming/."
|
2026-02-20 15:31:13 +00:00
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Check off the Nth unchecked acceptance criterion in a story file and auto-commit.
|
|
|
|
|
///
|
|
|
|
|
/// `criterion_index` is 0-based among unchecked (`- [ ]`) items.
|
|
|
|
|
pub fn check_criterion_in_file(
|
|
|
|
|
project_root: &Path,
|
|
|
|
|
story_id: &str,
|
|
|
|
|
criterion_index: usize,
|
2026-02-20 14:09:52 +00:00
|
|
|
) -> Result<(), String> {
|
2026-02-20 15:31:13 +00:00
|
|
|
let filepath = find_story_file(project_root, story_id)?;
|
|
|
|
|
let contents = fs::read_to_string(&filepath)
|
|
|
|
|
.map_err(|e| format!("Failed to read story file: {e}"))?;
|
|
|
|
|
|
|
|
|
|
let mut unchecked_count: usize = 0;
|
|
|
|
|
let mut found = false;
|
|
|
|
|
let new_lines: Vec<String> = contents
|
|
|
|
|
.lines()
|
|
|
|
|
.map(|line| {
|
|
|
|
|
let trimmed = line.trim();
|
|
|
|
|
if let Some(rest) = trimmed.strip_prefix("- [ ] ") {
|
|
|
|
|
if unchecked_count == criterion_index {
|
|
|
|
|
unchecked_count += 1;
|
|
|
|
|
found = true;
|
|
|
|
|
let indent_len = line.len() - trimmed.len();
|
|
|
|
|
let indent = &line[..indent_len];
|
|
|
|
|
return format!("{indent}- [x] {rest}");
|
|
|
|
|
}
|
|
|
|
|
unchecked_count += 1;
|
|
|
|
|
}
|
|
|
|
|
line.to_string()
|
|
|
|
|
})
|
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
|
|
if !found {
|
|
|
|
|
return Err(format!(
|
|
|
|
|
"Criterion index {criterion_index} out of range. Story '{story_id}' has \
|
|
|
|
|
{unchecked_count} unchecked criteria (indices 0..{}).",
|
|
|
|
|
unchecked_count.saturating_sub(1)
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let mut new_str = new_lines.join("\n");
|
|
|
|
|
if contents.ends_with('\n') {
|
|
|
|
|
new_str.push('\n');
|
|
|
|
|
}
|
|
|
|
|
fs::write(&filepath, &new_str)
|
|
|
|
|
.map_err(|e| format!("Failed to write story file: {e}"))?;
|
|
|
|
|
|
2026-02-20 19:39:19 +00:00
|
|
|
// Watcher handles the git commit asynchronously.
|
|
|
|
|
Ok(())
|
2026-02-20 15:31:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Update the `test_plan` front-matter field in a story file and auto-commit.
|
|
|
|
|
pub fn set_test_plan_in_file(
|
|
|
|
|
project_root: &Path,
|
|
|
|
|
story_id: &str,
|
|
|
|
|
status: &str,
|
|
|
|
|
) -> Result<(), String> {
|
|
|
|
|
let filepath = find_story_file(project_root, story_id)?;
|
|
|
|
|
let contents = fs::read_to_string(&filepath)
|
|
|
|
|
.map_err(|e| format!("Failed to read story file: {e}"))?;
|
|
|
|
|
|
|
|
|
|
let mut in_front_matter = false;
|
|
|
|
|
let mut front_matter_started = false;
|
|
|
|
|
let mut found = false;
|
|
|
|
|
|
|
|
|
|
let new_lines: Vec<String> = contents
|
|
|
|
|
.lines()
|
|
|
|
|
.map(|line| {
|
|
|
|
|
if line.trim() == "---" {
|
|
|
|
|
if !front_matter_started {
|
|
|
|
|
front_matter_started = true;
|
|
|
|
|
in_front_matter = true;
|
|
|
|
|
} else if in_front_matter {
|
|
|
|
|
in_front_matter = false;
|
|
|
|
|
}
|
|
|
|
|
return line.to_string();
|
|
|
|
|
}
|
|
|
|
|
if in_front_matter {
|
|
|
|
|
let trimmed = line.trim_start();
|
|
|
|
|
if trimmed.starts_with("test_plan:") {
|
|
|
|
|
found = true;
|
|
|
|
|
return format!("test_plan: {status}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
line.to_string()
|
|
|
|
|
})
|
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
|
|
if !found {
|
|
|
|
|
return Err(format!(
|
|
|
|
|
"Story '{story_id}' does not have a 'test_plan' field in its front matter."
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let mut new_str = new_lines.join("\n");
|
|
|
|
|
if contents.ends_with('\n') {
|
|
|
|
|
new_str.push('\n');
|
|
|
|
|
}
|
|
|
|
|
fs::write(&filepath, &new_str)
|
|
|
|
|
.map_err(|e| format!("Failed to write story file: {e}"))?;
|
|
|
|
|
|
2026-02-20 19:39:19 +00:00
|
|
|
// Watcher handles the git commit asynchronously.
|
|
|
|
|
Ok(())
|
2026-02-20 14:09:52 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-19 18:02:48 +00:00
|
|
|
fn slugify_name(name: &str) -> String {
|
|
|
|
|
let slug: String = name
|
|
|
|
|
.chars()
|
|
|
|
|
.map(|c| {
|
|
|
|
|
if c.is_ascii_alphanumeric() {
|
|
|
|
|
c.to_ascii_lowercase()
|
|
|
|
|
} else {
|
|
|
|
|
'_'
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.collect();
|
|
|
|
|
// Collapse consecutive underscores and trim edges
|
|
|
|
|
let mut result = String::new();
|
|
|
|
|
let mut prev_underscore = true; // start true to trim leading _
|
|
|
|
|
for ch in slug.chars() {
|
|
|
|
|
if ch == '_' {
|
|
|
|
|
if !prev_underscore {
|
|
|
|
|
result.push('_');
|
|
|
|
|
}
|
|
|
|
|
prev_underscore = true;
|
|
|
|
|
} else {
|
|
|
|
|
result.push(ch);
|
|
|
|
|
prev_underscore = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Trim trailing underscore
|
|
|
|
|
if result.ends_with('_') {
|
|
|
|
|
result.pop();
|
|
|
|
|
}
|
|
|
|
|
result
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-20 17:16:48 +00:00
|
|
|
/// Scan all `work/` subdirectories for the highest item number across all types (stories, bugs, spikes).
|
|
|
|
|
fn next_item_number(root: &std::path::Path) -> Result<u32, String> {
|
|
|
|
|
let work_base = root.join(".story_kit").join("work");
|
2026-02-19 18:02:48 +00:00
|
|
|
let mut max_num: u32 = 0;
|
|
|
|
|
|
2026-02-20 17:16:48 +00:00
|
|
|
for subdir in &["1_upcoming", "2_current", "3_qa", "4_merge", "5_archived"] {
|
|
|
|
|
let dir = work_base.join(subdir);
|
2026-02-19 18:02:48 +00:00
|
|
|
if !dir.exists() {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
for entry in
|
|
|
|
|
fs::read_dir(&dir).map_err(|e| format!("Failed to read {subdir} directory: {e}"))?
|
|
|
|
|
{
|
|
|
|
|
let entry = entry.map_err(|e| format!("Failed to read entry: {e}"))?;
|
|
|
|
|
let name = entry.file_name();
|
|
|
|
|
let name_str = name.to_string_lossy();
|
2026-02-20 17:16:48 +00:00
|
|
|
// Filename format: {N}_{type}_{slug}.md — extract leading N
|
2026-02-19 18:02:48 +00:00
|
|
|
let num_str: String = name_str.chars().take_while(|c| c.is_ascii_digit()).collect();
|
|
|
|
|
if let Ok(n) = num_str.parse::<u32>()
|
|
|
|
|
&& n > max_num
|
|
|
|
|
{
|
|
|
|
|
max_num = n;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(max_num + 1)
|
|
|
|
|
}
|
|
|
|
|
|
Accept spike 2: MCP HTTP endpoint for workflow and agent tools
Adds POST /mcp endpoint speaking MCP Streamable HTTP (JSON-RPC 2.0)
with 12 tools for workflow management and agent orchestration.
Supports both JSON and SSE response modes. Includes real-time agent
output streaming over SSE, Content-Type validation, and 15 integration
tests (134 total).
Tools: create_story, validate_stories, list_upcoming, get_story_todos,
record_tests, ensure_acceptance, start_agent, stop_agent, list_agents,
get_agent_config, reload_agent_config, get_agent_output.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 19:34:03 +00:00
|
|
|
pub fn validate_story_dirs(
|
2026-02-19 18:02:48 +00:00
|
|
|
root: &std::path::Path,
|
|
|
|
|
) -> Result<Vec<StoryValidationResult>, String> {
|
|
|
|
|
let mut results = Vec::new();
|
|
|
|
|
|
2026-02-20 17:16:48 +00:00
|
|
|
// Directories to validate: work/2_current/ + work/1_upcoming/
|
2026-02-20 16:21:30 +00:00
|
|
|
let dirs_to_validate: Vec<PathBuf> = vec![
|
2026-02-20 17:16:48 +00:00
|
|
|
root.join(".story_kit").join("work").join("2_current"),
|
|
|
|
|
root.join(".story_kit").join("work").join("1_upcoming"),
|
2026-02-20 16:21:30 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
for dir in &dirs_to_validate {
|
|
|
|
|
let subdir = dir.file_name().map(|n| n.to_string_lossy().into_owned()).unwrap_or_default();
|
2026-02-19 18:02:48 +00:00
|
|
|
if !dir.exists() {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
for entry in
|
2026-02-20 16:34:32 +00:00
|
|
|
fs::read_dir(dir).map_err(|e| format!("Failed to read {subdir} directory: {e}"))?
|
2026-02-19 18:02:48 +00:00
|
|
|
{
|
|
|
|
|
let entry = entry.map_err(|e| format!("Failed to read entry: {e}"))?;
|
|
|
|
|
let path = entry.path();
|
|
|
|
|
if path.extension().and_then(|ext| ext.to_str()) != Some("md") {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
let story_id = path
|
|
|
|
|
.file_stem()
|
|
|
|
|
.and_then(|stem| stem.to_str())
|
|
|
|
|
.unwrap_or_default()
|
|
|
|
|
.to_string();
|
|
|
|
|
let contents = fs::read_to_string(&path)
|
|
|
|
|
.map_err(|e| format!("Failed to read {}: {e}", path.display()))?;
|
|
|
|
|
match parse_front_matter(&contents) {
|
|
|
|
|
Ok(meta) => {
|
|
|
|
|
let mut errors = Vec::new();
|
|
|
|
|
if meta.name.is_none() {
|
|
|
|
|
errors.push("Missing 'name' field".to_string());
|
|
|
|
|
}
|
|
|
|
|
if meta.test_plan.is_none() {
|
|
|
|
|
errors.push("Missing 'test_plan' field".to_string());
|
|
|
|
|
}
|
|
|
|
|
if errors.is_empty() {
|
|
|
|
|
results.push(StoryValidationResult {
|
|
|
|
|
story_id,
|
|
|
|
|
valid: true,
|
|
|
|
|
error: None,
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
results.push(StoryValidationResult {
|
|
|
|
|
story_id,
|
|
|
|
|
valid: false,
|
|
|
|
|
error: Some(errors.join("; ")),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Err(e) => results.push(StoryValidationResult {
|
|
|
|
|
story_id,
|
|
|
|
|
valid: false,
|
|
|
|
|
error: Some(e.to_string()),
|
|
|
|
|
}),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
results.sort_by(|a, b| a.story_id.cmp(&b.story_id));
|
|
|
|
|
Ok(results)
|
|
|
|
|
}
|
|
|
|
|
|
WIP: Batch 2 — backfill tests for fs, shell, and http/workflow
- io/fs.rs: 20 tests (path resolution, project open/close/get, known projects,
model prefs, file read/write, list dir, validate path, scaffold)
- io/shell.rs: 4 new tests (allowlist, command execution, stdout capture, exit codes)
- http/workflow.rs: 8 tests (parse_test_status, to_test_case, to_review_story)
Coverage: 28.6% → 48.1%
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 13:52:19 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
|
mod tests {
|
|
|
|
|
use super::*;
|
2026-02-19 15:51:12 +00:00
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn load_upcoming_returns_empty_when_no_dir() {
|
|
|
|
|
let tmp = tempfile::tempdir().unwrap();
|
|
|
|
|
let root = tmp.path().to_path_buf();
|
|
|
|
|
// No .story_kit directory at all
|
|
|
|
|
let ctx = crate::http::context::AppContext::new_test(root);
|
|
|
|
|
let result = load_upcoming_stories(&ctx).unwrap();
|
|
|
|
|
assert!(result.is_empty());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn load_upcoming_parses_metadata() {
|
|
|
|
|
let tmp = tempfile::tempdir().unwrap();
|
2026-02-20 17:24:26 +00:00
|
|
|
let upcoming = tmp.path().join(".story_kit/work/1_upcoming");
|
2026-02-19 15:51:12 +00:00
|
|
|
fs::create_dir_all(&upcoming).unwrap();
|
|
|
|
|
fs::write(
|
2026-02-20 17:24:26 +00:00
|
|
|
upcoming.join("31_story_view_upcoming.md"),
|
2026-02-19 15:51:12 +00:00
|
|
|
"---\nname: View Upcoming\ntest_plan: pending\n---\n# Story\n",
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
fs::write(
|
2026-02-20 17:24:26 +00:00
|
|
|
upcoming.join("32_story_worktree.md"),
|
2026-02-19 15:51:12 +00:00
|
|
|
"---\nname: Worktree Orchestration\ntest_plan: pending\n---\n# Story\n",
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
let ctx = crate::http::context::AppContext::new_test(tmp.path().to_path_buf());
|
|
|
|
|
let stories = load_upcoming_stories(&ctx).unwrap();
|
|
|
|
|
assert_eq!(stories.len(), 2);
|
2026-02-20 17:24:26 +00:00
|
|
|
assert_eq!(stories[0].story_id, "31_story_view_upcoming");
|
2026-02-19 15:51:12 +00:00
|
|
|
assert_eq!(stories[0].name.as_deref(), Some("View Upcoming"));
|
2026-02-20 17:24:26 +00:00
|
|
|
assert_eq!(stories[1].story_id, "32_story_worktree");
|
2026-02-19 15:51:12 +00:00
|
|
|
assert_eq!(stories[1].name.as_deref(), Some("Worktree Orchestration"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn load_upcoming_skips_non_md_files() {
|
|
|
|
|
let tmp = tempfile::tempdir().unwrap();
|
2026-02-20 17:24:26 +00:00
|
|
|
let upcoming = tmp.path().join(".story_kit/work/1_upcoming");
|
2026-02-19 15:51:12 +00:00
|
|
|
fs::create_dir_all(&upcoming).unwrap();
|
|
|
|
|
fs::write(upcoming.join(".gitkeep"), "").unwrap();
|
|
|
|
|
fs::write(
|
2026-02-20 17:24:26 +00:00
|
|
|
upcoming.join("31_story_example.md"),
|
2026-02-19 15:51:12 +00:00
|
|
|
"---\nname: A Story\ntest_plan: pending\n---\n",
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
let ctx = crate::http::context::AppContext::new_test(tmp.path().to_path_buf());
|
|
|
|
|
let stories = load_upcoming_stories(&ctx).unwrap();
|
|
|
|
|
assert_eq!(stories.len(), 1);
|
2026-02-20 17:24:26 +00:00
|
|
|
assert_eq!(stories[0].story_id, "31_story_example");
|
2026-02-19 15:51:12 +00:00
|
|
|
}
|
2026-02-19 18:02:48 +00:00
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn validate_story_dirs_valid_files() {
|
|
|
|
|
let tmp = tempfile::tempdir().unwrap();
|
2026-02-20 17:24:26 +00:00
|
|
|
let current = tmp.path().join(".story_kit/work/2_current");
|
|
|
|
|
let upcoming = tmp.path().join(".story_kit/work/1_upcoming");
|
2026-02-19 18:02:48 +00:00
|
|
|
fs::create_dir_all(¤t).unwrap();
|
|
|
|
|
fs::create_dir_all(&upcoming).unwrap();
|
|
|
|
|
fs::write(
|
2026-02-20 17:24:26 +00:00
|
|
|
current.join("28_story_todos.md"),
|
2026-02-19 18:02:48 +00:00
|
|
|
"---\nname: Show TODOs\ntest_plan: approved\n---\n# Story\n",
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
fs::write(
|
2026-02-20 17:24:26 +00:00
|
|
|
upcoming.join("36_story_front_matter.md"),
|
2026-02-19 18:02:48 +00:00
|
|
|
"---\nname: Enforce Front Matter\ntest_plan: pending\n---\n# Story\n",
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
let results = validate_story_dirs(tmp.path()).unwrap();
|
|
|
|
|
assert_eq!(results.len(), 2);
|
|
|
|
|
assert!(results.iter().all(|r| r.valid));
|
|
|
|
|
assert!(results.iter().all(|r| r.error.is_none()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn validate_story_dirs_missing_front_matter() {
|
|
|
|
|
let tmp = tempfile::tempdir().unwrap();
|
2026-02-20 17:24:26 +00:00
|
|
|
let current = tmp.path().join(".story_kit/work/2_current");
|
2026-02-19 18:02:48 +00:00
|
|
|
fs::create_dir_all(¤t).unwrap();
|
2026-02-20 17:24:26 +00:00
|
|
|
fs::write(current.join("28_story_todos.md"), "# No front matter\n").unwrap();
|
2026-02-19 18:02:48 +00:00
|
|
|
|
|
|
|
|
let results = validate_story_dirs(tmp.path()).unwrap();
|
|
|
|
|
assert_eq!(results.len(), 1);
|
|
|
|
|
assert!(!results[0].valid);
|
|
|
|
|
assert_eq!(results[0].error.as_deref(), Some("Missing front matter"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn validate_story_dirs_missing_required_fields() {
|
|
|
|
|
let tmp = tempfile::tempdir().unwrap();
|
2026-02-20 17:24:26 +00:00
|
|
|
let current = tmp.path().join(".story_kit/work/2_current");
|
2026-02-19 18:02:48 +00:00
|
|
|
fs::create_dir_all(¤t).unwrap();
|
2026-02-20 17:24:26 +00:00
|
|
|
fs::write(current.join("28_story_todos.md"), "---\n---\n# Story\n").unwrap();
|
2026-02-19 18:02:48 +00:00
|
|
|
|
|
|
|
|
let results = validate_story_dirs(tmp.path()).unwrap();
|
|
|
|
|
assert_eq!(results.len(), 1);
|
|
|
|
|
assert!(!results[0].valid);
|
|
|
|
|
let err = results[0].error.as_deref().unwrap();
|
|
|
|
|
assert!(err.contains("Missing 'name' field"));
|
|
|
|
|
assert!(err.contains("Missing 'test_plan' field"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn validate_story_dirs_missing_test_plan_only() {
|
|
|
|
|
let tmp = tempfile::tempdir().unwrap();
|
2026-02-20 17:24:26 +00:00
|
|
|
let current = tmp.path().join(".story_kit/work/2_current");
|
2026-02-19 18:02:48 +00:00
|
|
|
fs::create_dir_all(¤t).unwrap();
|
|
|
|
|
fs::write(
|
2026-02-20 17:24:26 +00:00
|
|
|
current.join("28_story_todos.md"),
|
2026-02-19 18:02:48 +00:00
|
|
|
"---\nname: A Story\n---\n# Story\n",
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
let results = validate_story_dirs(tmp.path()).unwrap();
|
|
|
|
|
assert_eq!(results.len(), 1);
|
|
|
|
|
assert!(!results[0].valid);
|
|
|
|
|
let err = results[0].error.as_deref().unwrap();
|
|
|
|
|
assert!(err.contains("Missing 'test_plan' field"));
|
|
|
|
|
assert!(!err.contains("Missing 'name' field"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn validate_story_dirs_empty_when_no_dirs() {
|
|
|
|
|
let tmp = tempfile::tempdir().unwrap();
|
|
|
|
|
let results = validate_story_dirs(tmp.path()).unwrap();
|
|
|
|
|
assert!(results.is_empty());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- slugify_name tests ---
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn slugify_simple_name() {
|
|
|
|
|
assert_eq!(
|
|
|
|
|
slugify_name("Enforce Front Matter on All Story Files"),
|
|
|
|
|
"enforce_front_matter_on_all_story_files"
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn slugify_with_special_chars() {
|
|
|
|
|
assert_eq!(slugify_name("Hello, World! (v2)"), "hello_world_v2");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn slugify_leading_trailing_underscores() {
|
|
|
|
|
assert_eq!(slugify_name(" spaces "), "spaces");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn slugify_consecutive_separators() {
|
|
|
|
|
assert_eq!(slugify_name("a--b__c d"), "a_b_c_d");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn slugify_empty_after_strip() {
|
|
|
|
|
assert_eq!(slugify_name("!!!"), "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn slugify_already_snake_case() {
|
|
|
|
|
assert_eq!(slugify_name("my_story_name"), "my_story_name");
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-20 17:24:26 +00:00
|
|
|
// --- next_item_number tests ---
|
2026-02-19 18:02:48 +00:00
|
|
|
|
|
|
|
|
#[test]
|
2026-02-20 17:24:26 +00:00
|
|
|
fn next_item_number_empty_dirs() {
|
2026-02-19 18:02:48 +00:00
|
|
|
let tmp = tempfile::tempdir().unwrap();
|
2026-02-20 17:24:26 +00:00
|
|
|
let base = tmp.path().join(".story_kit/work/1_upcoming");
|
2026-02-19 18:02:48 +00:00
|
|
|
fs::create_dir_all(&base).unwrap();
|
2026-02-20 17:24:26 +00:00
|
|
|
assert_eq!(next_item_number(tmp.path()).unwrap(), 1);
|
2026-02-19 18:02:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
2026-02-20 17:24:26 +00:00
|
|
|
fn next_item_number_scans_all_dirs() {
|
2026-02-19 18:02:48 +00:00
|
|
|
let tmp = tempfile::tempdir().unwrap();
|
2026-02-20 17:24:26 +00:00
|
|
|
let upcoming = tmp.path().join(".story_kit/work/1_upcoming");
|
|
|
|
|
let current = tmp.path().join(".story_kit/work/2_current");
|
|
|
|
|
let archived = tmp.path().join(".story_kit/work/5_archived");
|
2026-02-19 18:02:48 +00:00
|
|
|
fs::create_dir_all(&upcoming).unwrap();
|
|
|
|
|
fs::create_dir_all(¤t).unwrap();
|
|
|
|
|
fs::create_dir_all(&archived).unwrap();
|
2026-02-20 17:24:26 +00:00
|
|
|
fs::write(upcoming.join("10_story_foo.md"), "").unwrap();
|
|
|
|
|
fs::write(current.join("20_story_bar.md"), "").unwrap();
|
|
|
|
|
fs::write(archived.join("15_story_baz.md"), "").unwrap();
|
|
|
|
|
assert_eq!(next_item_number(tmp.path()).unwrap(), 21);
|
2026-02-19 18:02:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
2026-02-20 17:24:26 +00:00
|
|
|
fn next_item_number_no_work_dirs() {
|
2026-02-19 18:02:48 +00:00
|
|
|
let tmp = tempfile::tempdir().unwrap();
|
|
|
|
|
// No .story_kit at all
|
2026-02-20 17:24:26 +00:00
|
|
|
assert_eq!(next_item_number(tmp.path()).unwrap(), 1);
|
2026-02-19 18:02:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- create_story integration tests ---
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn create_story_writes_correct_content() {
|
|
|
|
|
let tmp = tempfile::tempdir().unwrap();
|
2026-02-20 17:24:26 +00:00
|
|
|
let upcoming = tmp.path().join(".story_kit/work/1_upcoming");
|
2026-02-19 18:02:48 +00:00
|
|
|
fs::create_dir_all(&upcoming).unwrap();
|
2026-02-20 17:24:26 +00:00
|
|
|
fs::write(upcoming.join("36_story_existing.md"), "").unwrap();
|
2026-02-19 18:02:48 +00:00
|
|
|
|
2026-02-20 17:24:26 +00:00
|
|
|
let number = next_item_number(tmp.path()).unwrap();
|
2026-02-19 18:02:48 +00:00
|
|
|
assert_eq!(number, 37);
|
|
|
|
|
|
|
|
|
|
let slug = slugify_name("My New Feature");
|
|
|
|
|
assert_eq!(slug, "my_new_feature");
|
|
|
|
|
|
|
|
|
|
let filename = format!("{number}_{slug}.md");
|
|
|
|
|
let filepath = upcoming.join(&filename);
|
|
|
|
|
|
|
|
|
|
let mut content = String::new();
|
|
|
|
|
content.push_str("---\n");
|
|
|
|
|
content.push_str("name: My New Feature\n");
|
|
|
|
|
content.push_str("test_plan: pending\n");
|
|
|
|
|
content.push_str("---\n\n");
|
|
|
|
|
content.push_str(&format!("# Story {number}: My New Feature\n\n"));
|
|
|
|
|
content.push_str("## User Story\n\n");
|
|
|
|
|
content.push_str("As a dev, I want this feature\n\n");
|
|
|
|
|
content.push_str("## Acceptance Criteria\n\n");
|
|
|
|
|
content.push_str("- [ ] It works\n");
|
|
|
|
|
content.push_str("- [ ] It is tested\n\n");
|
|
|
|
|
content.push_str("## Out of Scope\n\n");
|
|
|
|
|
content.push_str("- TBD\n");
|
|
|
|
|
|
|
|
|
|
fs::write(&filepath, &content).unwrap();
|
|
|
|
|
|
|
|
|
|
let written = fs::read_to_string(&filepath).unwrap();
|
|
|
|
|
assert!(written.starts_with("---\nname: My New Feature\ntest_plan: pending\n---"));
|
|
|
|
|
assert!(written.contains("# Story 37: My New Feature"));
|
|
|
|
|
assert!(written.contains("- [ ] It works"));
|
|
|
|
|
assert!(written.contains("- [ ] It is tested"));
|
|
|
|
|
assert!(written.contains("## Out of Scope"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn create_story_rejects_duplicate() {
|
|
|
|
|
let tmp = tempfile::tempdir().unwrap();
|
2026-02-20 17:24:26 +00:00
|
|
|
let upcoming = tmp.path().join(".story_kit/work/1_upcoming");
|
2026-02-19 18:02:48 +00:00
|
|
|
fs::create_dir_all(&upcoming).unwrap();
|
|
|
|
|
|
2026-02-20 17:24:26 +00:00
|
|
|
let filepath = upcoming.join("1_story_my_feature.md");
|
2026-02-19 18:02:48 +00:00
|
|
|
fs::write(&filepath, "existing").unwrap();
|
|
|
|
|
|
|
|
|
|
// Simulate the check
|
|
|
|
|
assert!(filepath.exists());
|
|
|
|
|
}
|
2026-02-20 15:31:13 +00:00
|
|
|
|
|
|
|
|
// ── check_criterion_in_file tests ─────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
fn setup_git_repo(root: &std::path::Path) {
|
|
|
|
|
std::process::Command::new("git")
|
|
|
|
|
.args(["init"])
|
|
|
|
|
.current_dir(root)
|
|
|
|
|
.output()
|
|
|
|
|
.unwrap();
|
|
|
|
|
std::process::Command::new("git")
|
|
|
|
|
.args(["config", "user.email", "test@test.com"])
|
|
|
|
|
.current_dir(root)
|
|
|
|
|
.output()
|
|
|
|
|
.unwrap();
|
|
|
|
|
std::process::Command::new("git")
|
|
|
|
|
.args(["config", "user.name", "Test"])
|
|
|
|
|
.current_dir(root)
|
|
|
|
|
.output()
|
|
|
|
|
.unwrap();
|
|
|
|
|
std::process::Command::new("git")
|
|
|
|
|
.args(["commit", "--allow-empty", "-m", "init"])
|
|
|
|
|
.current_dir(root)
|
|
|
|
|
.output()
|
|
|
|
|
.unwrap();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn story_with_criteria(n: usize) -> String {
|
|
|
|
|
let mut s = "---\nname: Test Story\ntest_plan: pending\n---\n\n## Acceptance Criteria\n\n".to_string();
|
|
|
|
|
for i in 0..n {
|
|
|
|
|
s.push_str(&format!("- [ ] Criterion {i}\n"));
|
|
|
|
|
}
|
|
|
|
|
s
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn check_criterion_marks_first_unchecked() {
|
|
|
|
|
let tmp = tempfile::tempdir().unwrap();
|
|
|
|
|
setup_git_repo(tmp.path());
|
2026-02-20 17:24:26 +00:00
|
|
|
let current = tmp.path().join(".story_kit/work/2_current");
|
2026-02-20 15:31:13 +00:00
|
|
|
fs::create_dir_all(¤t).unwrap();
|
|
|
|
|
let filepath = current.join("1_test.md");
|
|
|
|
|
fs::write(&filepath, story_with_criteria(3)).unwrap();
|
|
|
|
|
std::process::Command::new("git")
|
|
|
|
|
.args(["add", "."])
|
|
|
|
|
.current_dir(tmp.path())
|
|
|
|
|
.output()
|
|
|
|
|
.unwrap();
|
|
|
|
|
std::process::Command::new("git")
|
|
|
|
|
.args(["commit", "-m", "add story"])
|
|
|
|
|
.current_dir(tmp.path())
|
|
|
|
|
.output()
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
check_criterion_in_file(tmp.path(), "1_test", 0).unwrap();
|
|
|
|
|
|
|
|
|
|
let contents = fs::read_to_string(&filepath).unwrap();
|
|
|
|
|
assert!(contents.contains("- [x] Criterion 0"), "first should be checked");
|
|
|
|
|
assert!(contents.contains("- [ ] Criterion 1"), "second should stay unchecked");
|
|
|
|
|
assert!(contents.contains("- [ ] Criterion 2"), "third should stay unchecked");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn check_criterion_marks_second_unchecked() {
|
|
|
|
|
let tmp = tempfile::tempdir().unwrap();
|
|
|
|
|
setup_git_repo(tmp.path());
|
2026-02-20 17:24:26 +00:00
|
|
|
let current = tmp.path().join(".story_kit/work/2_current");
|
2026-02-20 15:31:13 +00:00
|
|
|
fs::create_dir_all(¤t).unwrap();
|
|
|
|
|
let filepath = current.join("2_test.md");
|
|
|
|
|
fs::write(&filepath, story_with_criteria(3)).unwrap();
|
|
|
|
|
std::process::Command::new("git")
|
|
|
|
|
.args(["add", "."])
|
|
|
|
|
.current_dir(tmp.path())
|
|
|
|
|
.output()
|
|
|
|
|
.unwrap();
|
|
|
|
|
std::process::Command::new("git")
|
|
|
|
|
.args(["commit", "-m", "add story"])
|
|
|
|
|
.current_dir(tmp.path())
|
|
|
|
|
.output()
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
check_criterion_in_file(tmp.path(), "2_test", 1).unwrap();
|
|
|
|
|
|
|
|
|
|
let contents = fs::read_to_string(&filepath).unwrap();
|
|
|
|
|
assert!(contents.contains("- [ ] Criterion 0"), "first should stay unchecked");
|
|
|
|
|
assert!(contents.contains("- [x] Criterion 1"), "second should be checked");
|
|
|
|
|
assert!(contents.contains("- [ ] Criterion 2"), "third should stay unchecked");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn check_criterion_out_of_range_returns_error() {
|
|
|
|
|
let tmp = tempfile::tempdir().unwrap();
|
|
|
|
|
setup_git_repo(tmp.path());
|
2026-02-20 17:24:26 +00:00
|
|
|
let current = tmp.path().join(".story_kit/work/2_current");
|
2026-02-20 15:31:13 +00:00
|
|
|
fs::create_dir_all(¤t).unwrap();
|
|
|
|
|
let filepath = current.join("3_test.md");
|
|
|
|
|
fs::write(&filepath, story_with_criteria(2)).unwrap();
|
|
|
|
|
std::process::Command::new("git")
|
|
|
|
|
.args(["add", "."])
|
|
|
|
|
.current_dir(tmp.path())
|
|
|
|
|
.output()
|
|
|
|
|
.unwrap();
|
|
|
|
|
std::process::Command::new("git")
|
|
|
|
|
.args(["commit", "-m", "add story"])
|
|
|
|
|
.current_dir(tmp.path())
|
|
|
|
|
.output()
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
let result = check_criterion_in_file(tmp.path(), "3_test", 5);
|
|
|
|
|
assert!(result.is_err(), "should fail for out-of-range index");
|
|
|
|
|
assert!(result.unwrap_err().contains("out of range"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ── set_test_plan_in_file tests ───────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn set_test_plan_updates_pending_to_approved() {
|
|
|
|
|
let tmp = tempfile::tempdir().unwrap();
|
|
|
|
|
setup_git_repo(tmp.path());
|
2026-02-20 17:24:26 +00:00
|
|
|
let current = tmp.path().join(".story_kit/work/2_current");
|
2026-02-20 15:31:13 +00:00
|
|
|
fs::create_dir_all(¤t).unwrap();
|
|
|
|
|
let filepath = current.join("4_test.md");
|
|
|
|
|
fs::write(
|
|
|
|
|
&filepath,
|
|
|
|
|
"---\nname: Test Story\ntest_plan: pending\n---\n\n## Body\n",
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
std::process::Command::new("git")
|
|
|
|
|
.args(["add", "."])
|
|
|
|
|
.current_dir(tmp.path())
|
|
|
|
|
.output()
|
|
|
|
|
.unwrap();
|
|
|
|
|
std::process::Command::new("git")
|
|
|
|
|
.args(["commit", "-m", "add story"])
|
|
|
|
|
.current_dir(tmp.path())
|
|
|
|
|
.output()
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
set_test_plan_in_file(tmp.path(), "4_test", "approved").unwrap();
|
|
|
|
|
|
|
|
|
|
let contents = fs::read_to_string(&filepath).unwrap();
|
|
|
|
|
assert!(contents.contains("test_plan: approved"), "should be updated to approved");
|
|
|
|
|
assert!(!contents.contains("test_plan: pending"), "old value should be replaced");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn set_test_plan_missing_field_returns_error() {
|
|
|
|
|
let tmp = tempfile::tempdir().unwrap();
|
|
|
|
|
setup_git_repo(tmp.path());
|
2026-02-20 17:24:26 +00:00
|
|
|
let current = tmp.path().join(".story_kit/work/2_current");
|
2026-02-20 15:31:13 +00:00
|
|
|
fs::create_dir_all(¤t).unwrap();
|
|
|
|
|
let filepath = current.join("5_test.md");
|
|
|
|
|
fs::write(
|
|
|
|
|
&filepath,
|
|
|
|
|
"---\nname: Test Story\n---\n\n## Body\n",
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
std::process::Command::new("git")
|
|
|
|
|
.args(["add", "."])
|
|
|
|
|
.current_dir(tmp.path())
|
|
|
|
|
.output()
|
|
|
|
|
.unwrap();
|
|
|
|
|
std::process::Command::new("git")
|
|
|
|
|
.args(["commit", "-m", "add story"])
|
|
|
|
|
.current_dir(tmp.path())
|
|
|
|
|
.output()
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
let result = set_test_plan_in_file(tmp.path(), "5_test", "approved");
|
|
|
|
|
assert!(result.is_err(), "should fail if test_plan field is missing");
|
|
|
|
|
assert!(result.unwrap_err().contains("test_plan"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn find_story_file_searches_current_then_upcoming() {
|
|
|
|
|
let tmp = tempfile::tempdir().unwrap();
|
2026-02-20 17:24:26 +00:00
|
|
|
let current = tmp.path().join(".story_kit/work/2_current");
|
|
|
|
|
let upcoming = tmp.path().join(".story_kit/work/1_upcoming");
|
2026-02-20 15:31:13 +00:00
|
|
|
fs::create_dir_all(¤t).unwrap();
|
|
|
|
|
fs::create_dir_all(&upcoming).unwrap();
|
|
|
|
|
|
|
|
|
|
// Only in upcoming
|
|
|
|
|
fs::write(upcoming.join("6_test.md"), "").unwrap();
|
|
|
|
|
let found = find_story_file(tmp.path(), "6_test").unwrap();
|
2026-02-20 17:24:26 +00:00
|
|
|
assert!(found.ends_with("1_upcoming/6_test.md") || found.ends_with("1_upcoming\\6_test.md"));
|
2026-02-20 15:31:13 +00:00
|
|
|
|
|
|
|
|
// Also in current — current should win
|
|
|
|
|
fs::write(current.join("6_test.md"), "").unwrap();
|
|
|
|
|
let found = find_story_file(tmp.path(), "6_test").unwrap();
|
2026-02-20 17:24:26 +00:00
|
|
|
assert!(found.ends_with("2_current/6_test.md") || found.ends_with("2_current\\6_test.md"));
|
2026-02-20 15:31:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn find_story_file_returns_error_when_not_found() {
|
|
|
|
|
let tmp = tempfile::tempdir().unwrap();
|
|
|
|
|
let result = find_story_file(tmp.path(), "99_missing");
|
|
|
|
|
assert!(result.is_err());
|
|
|
|
|
assert!(result.unwrap_err().contains("not found"));
|
|
|
|
|
}
|
2026-02-20 16:34:32 +00:00
|
|
|
|
|
|
|
|
// ── Bug file helper tests ──────────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
#[test]
|
2026-02-20 17:24:26 +00:00
|
|
|
fn next_item_number_starts_at_1_when_empty_bugs() {
|
2026-02-20 16:34:32 +00:00
|
|
|
let tmp = tempfile::tempdir().unwrap();
|
2026-02-20 17:24:26 +00:00
|
|
|
assert_eq!(next_item_number(tmp.path()).unwrap(), 1);
|
2026-02-20 16:34:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
2026-02-20 17:24:26 +00:00
|
|
|
fn next_item_number_increments_from_existing_bugs() {
|
2026-02-20 16:34:32 +00:00
|
|
|
let tmp = tempfile::tempdir().unwrap();
|
2026-02-20 17:24:26 +00:00
|
|
|
let upcoming = tmp.path().join(".story_kit/work/1_upcoming");
|
|
|
|
|
fs::create_dir_all(&upcoming).unwrap();
|
|
|
|
|
fs::write(upcoming.join("1_bug_crash.md"), "").unwrap();
|
|
|
|
|
fs::write(upcoming.join("3_bug_another.md"), "").unwrap();
|
|
|
|
|
assert_eq!(next_item_number(tmp.path()).unwrap(), 4);
|
2026-02-20 16:34:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
2026-02-20 17:24:26 +00:00
|
|
|
fn next_item_number_scans_archived_too() {
|
2026-02-20 16:34:32 +00:00
|
|
|
let tmp = tempfile::tempdir().unwrap();
|
2026-02-20 17:24:26 +00:00
|
|
|
let upcoming = tmp.path().join(".story_kit/work/1_upcoming");
|
|
|
|
|
let archived = tmp.path().join(".story_kit/work/5_archived");
|
|
|
|
|
fs::create_dir_all(&upcoming).unwrap();
|
|
|
|
|
fs::create_dir_all(&archived).unwrap();
|
|
|
|
|
fs::write(archived.join("5_bug_old.md"), "").unwrap();
|
|
|
|
|
assert_eq!(next_item_number(tmp.path()).unwrap(), 6);
|
2026-02-20 16:34:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn list_bug_files_empty_when_no_bugs_dir() {
|
|
|
|
|
let tmp = tempfile::tempdir().unwrap();
|
|
|
|
|
let result = list_bug_files(tmp.path()).unwrap();
|
|
|
|
|
assert!(result.is_empty());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn list_bug_files_excludes_archive_subdir() {
|
|
|
|
|
let tmp = tempfile::tempdir().unwrap();
|
2026-02-20 17:24:26 +00:00
|
|
|
let upcoming_dir = tmp.path().join(".story_kit/work/1_upcoming");
|
|
|
|
|
let archived_dir = tmp.path().join(".story_kit/work/5_archived");
|
|
|
|
|
fs::create_dir_all(&upcoming_dir).unwrap();
|
|
|
|
|
fs::create_dir_all(&archived_dir).unwrap();
|
|
|
|
|
fs::write(upcoming_dir.join("1_bug_open.md"), "# Bug 1: Open Bug\n").unwrap();
|
|
|
|
|
fs::write(archived_dir.join("2_bug_closed.md"), "# Bug 2: Closed Bug\n").unwrap();
|
2026-02-20 16:34:32 +00:00
|
|
|
|
|
|
|
|
let result = list_bug_files(tmp.path()).unwrap();
|
|
|
|
|
assert_eq!(result.len(), 1);
|
2026-02-20 17:24:26 +00:00
|
|
|
assert_eq!(result[0].0, "1_bug_open");
|
2026-02-20 16:34:32 +00:00
|
|
|
assert_eq!(result[0].1, "Open Bug");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn list_bug_files_sorted_by_id() {
|
|
|
|
|
let tmp = tempfile::tempdir().unwrap();
|
2026-02-20 17:24:26 +00:00
|
|
|
let upcoming_dir = tmp.path().join(".story_kit/work/1_upcoming");
|
|
|
|
|
fs::create_dir_all(&upcoming_dir).unwrap();
|
|
|
|
|
fs::write(upcoming_dir.join("3_bug_third.md"), "# Bug 3: Third\n").unwrap();
|
|
|
|
|
fs::write(upcoming_dir.join("1_bug_first.md"), "# Bug 1: First\n").unwrap();
|
|
|
|
|
fs::write(upcoming_dir.join("2_bug_second.md"), "# Bug 2: Second\n").unwrap();
|
2026-02-20 16:34:32 +00:00
|
|
|
|
|
|
|
|
let result = list_bug_files(tmp.path()).unwrap();
|
|
|
|
|
assert_eq!(result.len(), 3);
|
2026-02-20 17:24:26 +00:00
|
|
|
assert_eq!(result[0].0, "1_bug_first");
|
|
|
|
|
assert_eq!(result[1].0, "2_bug_second");
|
|
|
|
|
assert_eq!(result[2].0, "3_bug_third");
|
2026-02-20 16:34:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn extract_bug_name_parses_heading() {
|
|
|
|
|
let tmp = tempfile::tempdir().unwrap();
|
|
|
|
|
let path = tmp.path().join("bug-1-crash.md");
|
|
|
|
|
fs::write(&path, "# Bug 1: Login page crashes\n\n## Description\n").unwrap();
|
|
|
|
|
let name = extract_bug_name(&path).unwrap();
|
|
|
|
|
assert_eq!(name, "Login page crashes");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn create_bug_file_writes_correct_content() {
|
|
|
|
|
let tmp = tempfile::tempdir().unwrap();
|
|
|
|
|
setup_git_repo(tmp.path());
|
|
|
|
|
|
|
|
|
|
let bug_id = create_bug_file(
|
|
|
|
|
tmp.path(),
|
|
|
|
|
"Login Crash",
|
|
|
|
|
"The login page crashes on submit.",
|
|
|
|
|
"1. Go to /login\n2. Click submit",
|
|
|
|
|
"Page crashes with 500 error",
|
|
|
|
|
"Login succeeds",
|
|
|
|
|
Some(&["Login form submits without error".to_string()]),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
2026-02-20 17:24:26 +00:00
|
|
|
assert_eq!(bug_id, "1_bug_login_crash");
|
2026-02-20 16:34:32 +00:00
|
|
|
|
|
|
|
|
let filepath = tmp
|
|
|
|
|
.path()
|
2026-02-20 17:24:26 +00:00
|
|
|
.join(".story_kit/work/1_upcoming/1_bug_login_crash.md");
|
2026-02-20 16:34:32 +00:00
|
|
|
assert!(filepath.exists());
|
|
|
|
|
let contents = fs::read_to_string(&filepath).unwrap();
|
|
|
|
|
assert!(contents.contains("# Bug 1: Login Crash"));
|
|
|
|
|
assert!(contents.contains("## Description"));
|
|
|
|
|
assert!(contents.contains("The login page crashes on submit."));
|
|
|
|
|
assert!(contents.contains("## How to Reproduce"));
|
|
|
|
|
assert!(contents.contains("1. Go to /login"));
|
|
|
|
|
assert!(contents.contains("## Actual Result"));
|
|
|
|
|
assert!(contents.contains("Page crashes with 500 error"));
|
|
|
|
|
assert!(contents.contains("## Expected Result"));
|
|
|
|
|
assert!(contents.contains("Login succeeds"));
|
|
|
|
|
assert!(contents.contains("## Acceptance Criteria"));
|
|
|
|
|
assert!(contents.contains("- [ ] Login form submits without error"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn create_bug_file_rejects_empty_name() {
|
|
|
|
|
let tmp = tempfile::tempdir().unwrap();
|
|
|
|
|
let result = create_bug_file(tmp.path(), "!!!", "desc", "steps", "actual", "expected", None);
|
|
|
|
|
assert!(result.is_err());
|
|
|
|
|
assert!(result.unwrap_err().contains("alphanumeric"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn create_bug_file_uses_default_acceptance_criterion() {
|
|
|
|
|
let tmp = tempfile::tempdir().unwrap();
|
|
|
|
|
setup_git_repo(tmp.path());
|
|
|
|
|
|
|
|
|
|
create_bug_file(
|
|
|
|
|
tmp.path(),
|
|
|
|
|
"Some Bug",
|
|
|
|
|
"desc",
|
|
|
|
|
"steps",
|
|
|
|
|
"actual",
|
|
|
|
|
"expected",
|
|
|
|
|
None,
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
2026-02-20 17:24:26 +00:00
|
|
|
let filepath = tmp.path().join(".story_kit/work/1_upcoming/1_bug_some_bug.md");
|
2026-02-20 16:34:32 +00:00
|
|
|
let contents = fs::read_to_string(&filepath).unwrap();
|
|
|
|
|
assert!(contents.contains("- [ ] Bug is fixed and verified"));
|
|
|
|
|
}
|
WIP: Batch 2 — backfill tests for fs, shell, and http/workflow
- io/fs.rs: 20 tests (path resolution, project open/close/get, known projects,
model prefs, file read/write, list dir, validate path, scaffold)
- io/shell.rs: 4 new tests (allowlist, command execution, stdout capture, exit codes)
- http/workflow.rs: 8 tests (parse_test_status, to_test_case, to_review_story)
Coverage: 28.6% → 48.1%
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 13:52:19 +00:00
|
|
|
}
|