huskies: merge 522_story_migrate_status_command_pipeline_view_from_filesystem_to_pipeline_state_read_all_typed
This commit is contained in:
+265
-197
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use crate::agents::{AgentPool, AgentStatus};
|
use crate::agents::{AgentPool, AgentStatus};
|
||||||
use crate::config::ProjectConfig;
|
use crate::config::ProjectConfig;
|
||||||
|
use crate::pipeline_state::{PipelineItem, Stage};
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
|
|
||||||
use super::CommandContext;
|
use super::CommandContext;
|
||||||
@@ -49,22 +50,6 @@ pub(super) fn story_short_label(stem: &str, name: Option<&str>) -> String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Read the `blocked` flag from a story file's YAML front matter.
|
|
||||||
///
|
|
||||||
/// Returns `true` when the story has `blocked: true` set (retry limit reached).
|
|
||||||
fn read_story_blocked(project_root: &std::path::Path, stage_dir: &str, stem: &str) -> bool {
|
|
||||||
let path = project_root
|
|
||||||
.join(".huskies")
|
|
||||||
.join("work")
|
|
||||||
.join(stage_dir)
|
|
||||||
.join(format!("{stem}.md"));
|
|
||||||
std::fs::read_to_string(path)
|
|
||||||
.ok()
|
|
||||||
.and_then(|c| crate::io::story_metadata::parse_front_matter(&c).ok())
|
|
||||||
.and_then(|m| m.blocked)
|
|
||||||
.unwrap_or(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Choose the traffic-light indicator for a work item.
|
/// Choose the traffic-light indicator for a work item.
|
||||||
///
|
///
|
||||||
/// Priority: blocked > throttled > running > idle.
|
/// Priority: blocked > throttled > running > idle.
|
||||||
@@ -87,43 +72,44 @@ pub(super) fn traffic_light_dot(blocked: bool, throttled: bool, has_agent: bool)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Read all story IDs and names from a pipeline stage directory.
|
/// Check which dependency numbers from `item.depends_on` are unmet.
|
||||||
fn read_stage_items(
|
///
|
||||||
project_root: &std::path::Path,
|
/// A dependency is considered met if the dep is in `Done` or `Archived` stage
|
||||||
stage_dir: &str,
|
/// in `all_items`. If the dep is not found in `all_items` at all (e.g. it was
|
||||||
) -> Vec<(String, Option<String>)> {
|
/// archived before the CRDT migration and has no row), it is treated as met.
|
||||||
let dir = project_root
|
fn unmet_deps_from_items(item: &PipelineItem, all_items: &[PipelineItem]) -> Vec<u32> {
|
||||||
.join(".huskies")
|
item.depends_on
|
||||||
.join("work")
|
.iter()
|
||||||
.join(stage_dir);
|
.filter_map(|dep_id| {
|
||||||
if !dir.exists() {
|
// dep_id.0 is the raw number string (e.g. "999") as projected
|
||||||
return Vec::new();
|
// from PipelineItemView.depends_on: Vec<u32>.
|
||||||
}
|
let dep_num: u32 = dep_id.0.parse().ok()?;
|
||||||
let mut items = Vec::new();
|
// Find the dep by matching the numeric prefix of its story_id.
|
||||||
if let Ok(entries) = std::fs::read_dir(&dir) {
|
let dep = all_items.iter().find(|i| {
|
||||||
for entry in entries.flatten() {
|
i.story_id.0 == dep_id.0
|
||||||
let path = entry.path();
|
|| i.story_id.0.split('_').next() == Some(dep_id.0.as_str())
|
||||||
if path.extension().and_then(|e| e.to_str()) != Some("md") {
|
});
|
||||||
continue;
|
match dep {
|
||||||
|
Some(d) if matches!(d.stage, Stage::Done { .. } | Stage::Archived { .. }) => None,
|
||||||
|
Some(_) => Some(dep_num), // Found but not done = unmet
|
||||||
|
None => None, // Not in CRDT; treat as met
|
||||||
}
|
}
|
||||||
if let Some(stem) = path.file_stem().and_then(|s| s.to_str()) {
|
})
|
||||||
let name = std::fs::read_to_string(&path)
|
.collect()
|
||||||
.ok()
|
|
||||||
.and_then(|contents| {
|
|
||||||
crate::io::story_metadata::parse_front_matter(&contents)
|
|
||||||
.ok()
|
|
||||||
.and_then(|m| m.name)
|
|
||||||
});
|
|
||||||
items.push((stem.to_string(), name));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
items.sort_by(|a, b| a.0.cmp(&b.0));
|
|
||||||
items
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Build the full pipeline status text formatted for Matrix (markdown).
|
/// Build the full pipeline status text formatted for Matrix (markdown).
|
||||||
pub(super) fn build_pipeline_status(project_root: &std::path::Path, agents: &AgentPool) -> String {
|
pub(super) fn build_pipeline_status(project_root: &std::path::Path, agents: &AgentPool) -> String {
|
||||||
|
let items = crate::pipeline_state::read_all_typed();
|
||||||
|
build_status_from_items(project_root, agents, &items)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Inner implementation that accepts pre-loaded items for testability.
|
||||||
|
fn build_status_from_items(
|
||||||
|
project_root: &std::path::Path,
|
||||||
|
agents: &AgentPool,
|
||||||
|
items: &[PipelineItem],
|
||||||
|
) -> String {
|
||||||
// Build a map from story_id → active AgentInfo for quick lookup.
|
// Build a map from story_id → active AgentInfo for quick lookup.
|
||||||
let active_agents = agents.list_agents().unwrap_or_default();
|
let active_agents = agents.list_agents().unwrap_or_default();
|
||||||
let active_map: HashMap<String, &crate::agents::AgentInfo> = active_agents
|
let active_map: HashMap<String, &crate::agents::AgentInfo> = active_agents
|
||||||
@@ -146,62 +132,58 @@ pub(super) fn build_pipeline_status(project_root: &std::path::Path, agents: &Age
|
|||||||
|
|
||||||
let mut out = String::from("**Pipeline Status**\n\n");
|
let mut out = String::from("**Pipeline Status**\n\n");
|
||||||
|
|
||||||
let stages = [
|
// Active pipeline stages to display (Archived is handled separately below).
|
||||||
("1_backlog", "Backlog"),
|
type StagePredicate = fn(&Stage) -> bool;
|
||||||
("2_current", "In Progress"),
|
let stage_filters: &[(&str, StagePredicate)] = &[
|
||||||
("3_qa", "QA"),
|
("Backlog", |s| matches!(s, Stage::Backlog)),
|
||||||
("4_merge", "Merge"),
|
("In Progress", |s| matches!(s, Stage::Coding)),
|
||||||
("5_done", "Done"),
|
("QA", |s| matches!(s, Stage::Qa)),
|
||||||
|
("Merge", |s| matches!(s, Stage::Merge { .. })),
|
||||||
|
("Done", |s| matches!(s, Stage::Done { .. })),
|
||||||
];
|
];
|
||||||
|
|
||||||
for (dir, label) in &stages {
|
for (label, filter) in stage_filters {
|
||||||
let items = read_stage_items(project_root, dir);
|
let mut stage_items: Vec<&PipelineItem> =
|
||||||
let count = items.len();
|
items.iter().filter(|i| filter(&i.stage)).collect();
|
||||||
|
stage_items.sort_by(|a, b| a.story_id.0.cmp(&b.story_id.0));
|
||||||
|
let count = stage_items.len();
|
||||||
out.push_str(&format!("**{label}** ({count})\n"));
|
out.push_str(&format!("**{label}** ({count})\n"));
|
||||||
if items.is_empty() {
|
if stage_items.is_empty() {
|
||||||
out.push_str(" *(none)*\n");
|
out.push_str(" *(none)*\n");
|
||||||
} else {
|
} else {
|
||||||
for (story_id, name) in &items {
|
for item in &stage_items {
|
||||||
let display = story_short_label(story_id, name.as_deref());
|
out.push_str(&render_item_line(
|
||||||
let cost_suffix = cost_by_story
|
item,
|
||||||
.get(story_id)
|
items,
|
||||||
.filter(|&&c| c > 0.0)
|
&active_map,
|
||||||
.map(|c| format!(" — ${c:.2}"))
|
&cost_by_story,
|
||||||
.unwrap_or_default();
|
&config,
|
||||||
let blocked = read_story_blocked(project_root, dir, story_id);
|
));
|
||||||
let agent = active_map.get(story_id);
|
|
||||||
let throttled = agent.map(|a| a.throttled).unwrap_or(false);
|
|
||||||
let dot = traffic_light_dot(blocked, throttled, agent.is_some());
|
|
||||||
// Check for unmet dependencies and append a note when present.
|
|
||||||
let unmet = crate::io::story_metadata::check_unmet_deps(
|
|
||||||
project_root,
|
|
||||||
dir,
|
|
||||||
story_id,
|
|
||||||
);
|
|
||||||
let dep_suffix = if unmet.is_empty() {
|
|
||||||
String::new()
|
|
||||||
} else {
|
|
||||||
let nums: Vec<String> = unmet.iter().map(|n| n.to_string()).collect();
|
|
||||||
format!(" *(waiting on: {})*", nums.join(", "))
|
|
||||||
};
|
|
||||||
if let Some(agent) = agent {
|
|
||||||
let model_str = config
|
|
||||||
.as_ref()
|
|
||||||
.and_then(|cfg| cfg.find_agent(&agent.agent_name))
|
|
||||||
.and_then(|ac| ac.model.as_deref())
|
|
||||||
.unwrap_or("?");
|
|
||||||
out.push_str(&format!(
|
|
||||||
" {dot}{display}{cost_suffix}{dep_suffix} — {} ({model_str})\n",
|
|
||||||
agent.agent_name
|
|
||||||
));
|
|
||||||
} else {
|
|
||||||
out.push_str(&format!(" {dot}{display}{cost_suffix}{dep_suffix}\n"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out.push('\n');
|
out.push('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Blocked items: Archived { reason: Blocked } shown with 🔴 indicator.
|
||||||
|
let mut blocked_items: Vec<&PipelineItem> = items
|
||||||
|
.iter()
|
||||||
|
.filter(|i| i.stage.is_blocked())
|
||||||
|
.collect();
|
||||||
|
blocked_items.sort_by(|a, b| a.story_id.0.cmp(&b.story_id.0));
|
||||||
|
if !blocked_items.is_empty() {
|
||||||
|
out.push_str(&format!("**Blocked** ({})\n", blocked_items.len()));
|
||||||
|
for item in &blocked_items {
|
||||||
|
out.push_str(&render_item_line(
|
||||||
|
item,
|
||||||
|
items,
|
||||||
|
&active_map,
|
||||||
|
&cost_by_story,
|
||||||
|
&config,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
out.push('\n');
|
||||||
|
}
|
||||||
|
|
||||||
// Free agents: configured agents not currently running or pending.
|
// Free agents: configured agents not currently running or pending.
|
||||||
out.push_str("**Free Agents**\n");
|
out.push_str("**Free Agents**\n");
|
||||||
if let Some(cfg) = &config {
|
if let Some(cfg) = &config {
|
||||||
@@ -235,10 +217,80 @@ pub(super) fn build_pipeline_status(project_root: &std::path::Path, agents: &Age
|
|||||||
out
|
out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Render a single status line for one pipeline item.
|
||||||
|
fn render_item_line(
|
||||||
|
item: &PipelineItem,
|
||||||
|
all_items: &[PipelineItem],
|
||||||
|
active_map: &HashMap<String, &crate::agents::AgentInfo>,
|
||||||
|
cost_by_story: &HashMap<String, f64>,
|
||||||
|
config: &Option<ProjectConfig>,
|
||||||
|
) -> String {
|
||||||
|
let story_id = &item.story_id.0;
|
||||||
|
let name_opt = if item.name.is_empty() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(item.name.as_str())
|
||||||
|
};
|
||||||
|
let display = story_short_label(story_id, name_opt);
|
||||||
|
let cost_suffix = cost_by_story
|
||||||
|
.get(story_id)
|
||||||
|
.filter(|&&c| c > 0.0)
|
||||||
|
.map(|c| format!(" — ${c:.2}"))
|
||||||
|
.unwrap_or_default();
|
||||||
|
let blocked = item.stage.is_blocked();
|
||||||
|
let agent = active_map.get(story_id);
|
||||||
|
let throttled = agent.map(|a| a.throttled).unwrap_or(false);
|
||||||
|
let dot = traffic_light_dot(blocked, throttled, agent.is_some());
|
||||||
|
let unmet = unmet_deps_from_items(item, all_items);
|
||||||
|
let dep_suffix = if unmet.is_empty() {
|
||||||
|
String::new()
|
||||||
|
} else {
|
||||||
|
let nums: Vec<String> = unmet.iter().map(|n| n.to_string()).collect();
|
||||||
|
format!(" *(waiting on: {})*", nums.join(", "))
|
||||||
|
};
|
||||||
|
if let Some(agent) = agent {
|
||||||
|
let model_str = config
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|cfg| cfg.find_agent(&agent.agent_name))
|
||||||
|
.and_then(|ac| ac.model.as_deref())
|
||||||
|
.unwrap_or("?");
|
||||||
|
format!(
|
||||||
|
" {dot}{display}{cost_suffix}{dep_suffix} — {} ({model_str})\n",
|
||||||
|
agent.agent_name
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
format!(" {dot}{display}{cost_suffix}{dep_suffix}\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::agents::AgentPool;
|
use crate::agents::AgentPool;
|
||||||
|
use crate::pipeline_state::{ArchiveReason, PipelineItem, Stage, StoryId};
|
||||||
|
use chrono::Utc;
|
||||||
|
|
||||||
|
/// Build a minimal PipelineItem for tests.
|
||||||
|
fn make_item(id: &str, name: &str, stage: Stage) -> PipelineItem {
|
||||||
|
PipelineItem {
|
||||||
|
story_id: StoryId(id.to_string()),
|
||||||
|
name: name.to_string(),
|
||||||
|
stage,
|
||||||
|
depends_on: Vec::new(),
|
||||||
|
retry_count: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Build a PipelineItem with dependencies for tests.
|
||||||
|
fn make_item_with_deps(id: &str, name: &str, stage: Stage, deps: Vec<u32>) -> PipelineItem {
|
||||||
|
PipelineItem {
|
||||||
|
story_id: StoryId(id.to_string()),
|
||||||
|
name: name.to_string(),
|
||||||
|
stage,
|
||||||
|
depends_on: deps.iter().map(|n| StoryId(n.to_string())).collect(),
|
||||||
|
retry_count: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn status_command_matches() {
|
fn status_command_matches() {
|
||||||
@@ -322,24 +374,21 @@ mod tests {
|
|||||||
assert_eq!(label, "42 — Some item");
|
assert_eq!(label, "42 — Some item");
|
||||||
}
|
}
|
||||||
|
|
||||||
// -- build_pipeline_status formatting -----------------------------------
|
// -- build_status_from_items formatting -----------------------------------
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn status_does_not_show_full_filename_stem() {
|
fn status_does_not_show_full_filename_stem() {
|
||||||
use std::io::Write;
|
|
||||||
use tempfile::TempDir;
|
use tempfile::TempDir;
|
||||||
|
|
||||||
let tmp = TempDir::new().unwrap();
|
let tmp = TempDir::new().unwrap();
|
||||||
let stage_dir = tmp.path().join(".huskies/work/2_current");
|
|
||||||
std::fs::create_dir_all(&stage_dir).unwrap();
|
|
||||||
|
|
||||||
// Write a story file with a front-matter name
|
let items = vec![make_item(
|
||||||
let story_path = stage_dir.join("293_story_register_all_bot_commands.md");
|
"293_story_register_all_bot_commands",
|
||||||
let mut f = std::fs::File::create(&story_path).unwrap();
|
"Register all bot commands",
|
||||||
writeln!(f, "---\nname: Register all bot commands\n---\n").unwrap();
|
Stage::Coding,
|
||||||
|
)];
|
||||||
|
|
||||||
let agents = AgentPool::new_test(3000);
|
let agents = AgentPool::new_test(3000);
|
||||||
let output = build_pipeline_status(tmp.path(), &agents);
|
let output = build_status_from_items(tmp.path(), &agents, &items);
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
!output.contains("293_story_register_all_bot_commands"),
|
!output.contains("293_story_register_all_bot_commands"),
|
||||||
@@ -355,16 +404,14 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn status_shows_cost_when_token_usage_exists() {
|
fn status_shows_cost_when_token_usage_exists() {
|
||||||
use std::io::Write;
|
|
||||||
use tempfile::TempDir;
|
use tempfile::TempDir;
|
||||||
|
|
||||||
let tmp = TempDir::new().unwrap();
|
let tmp = TempDir::new().unwrap();
|
||||||
let stage_dir = tmp.path().join(".huskies/work/2_current");
|
|
||||||
std::fs::create_dir_all(&stage_dir).unwrap();
|
|
||||||
|
|
||||||
let story_path = stage_dir.join("293_story_register_all_bot_commands.md");
|
let items = vec![make_item(
|
||||||
let mut f = std::fs::File::create(&story_path).unwrap();
|
"293_story_register_all_bot_commands",
|
||||||
writeln!(f, "---\nname: Register all bot commands\n---\n").unwrap();
|
"Register all bot commands",
|
||||||
|
Stage::Coding,
|
||||||
|
)];
|
||||||
|
|
||||||
// Write token usage for this story.
|
// Write token usage for this story.
|
||||||
let usage = crate::agents::TokenUsage {
|
let usage = crate::agents::TokenUsage {
|
||||||
@@ -383,7 +430,7 @@ mod tests {
|
|||||||
crate::agents::token_usage::append_record(tmp.path(), &record).unwrap();
|
crate::agents::token_usage::append_record(tmp.path(), &record).unwrap();
|
||||||
|
|
||||||
let agents = AgentPool::new_test(3000);
|
let agents = AgentPool::new_test(3000);
|
||||||
let output = build_pipeline_status(tmp.path(), &agents);
|
let output = build_status_from_items(tmp.path(), &agents, &items);
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
output.contains("293 [story] — Register all bot commands — $0.29"),
|
output.contains("293 [story] — Register all bot commands — $0.29"),
|
||||||
@@ -393,20 +440,17 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn status_no_cost_when_no_usage() {
|
fn status_no_cost_when_no_usage() {
|
||||||
use std::io::Write;
|
|
||||||
use tempfile::TempDir;
|
use tempfile::TempDir;
|
||||||
|
|
||||||
let tmp = TempDir::new().unwrap();
|
let tmp = TempDir::new().unwrap();
|
||||||
let stage_dir = tmp.path().join(".huskies/work/2_current");
|
|
||||||
std::fs::create_dir_all(&stage_dir).unwrap();
|
|
||||||
|
|
||||||
let story_path = stage_dir.join("293_story_register_all_bot_commands.md");
|
let items = vec![make_item(
|
||||||
let mut f = std::fs::File::create(&story_path).unwrap();
|
"293_story_register_all_bot_commands",
|
||||||
writeln!(f, "---\nname: Register all bot commands\n---\n").unwrap();
|
"Register all bot commands",
|
||||||
|
Stage::Coding,
|
||||||
|
)];
|
||||||
|
|
||||||
// No token usage written.
|
|
||||||
let agents = AgentPool::new_test(3000);
|
let agents = AgentPool::new_test(3000);
|
||||||
let output = build_pipeline_status(tmp.path(), &agents);
|
let output = build_status_from_items(tmp.path(), &agents, &items);
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
!output.contains("$"),
|
!output.contains("$"),
|
||||||
@@ -416,16 +460,14 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn status_aggregates_multiple_records_per_story() {
|
fn status_aggregates_multiple_records_per_story() {
|
||||||
use std::io::Write;
|
|
||||||
use tempfile::TempDir;
|
use tempfile::TempDir;
|
||||||
|
|
||||||
let tmp = TempDir::new().unwrap();
|
let tmp = TempDir::new().unwrap();
|
||||||
let stage_dir = tmp.path().join(".huskies/work/2_current");
|
|
||||||
std::fs::create_dir_all(&stage_dir).unwrap();
|
|
||||||
|
|
||||||
let story_path = stage_dir.join("293_story_register_all_bot_commands.md");
|
let items = vec![make_item(
|
||||||
let mut f = std::fs::File::create(&story_path).unwrap();
|
"293_story_register_all_bot_commands",
|
||||||
writeln!(f, "---\nname: Register all bot commands\n---\n").unwrap();
|
"Register all bot commands",
|
||||||
|
Stage::Coding,
|
||||||
|
)];
|
||||||
|
|
||||||
// Write two records for the same story — costs should be summed.
|
// Write two records for the same story — costs should be summed.
|
||||||
for cost in [0.10, 0.19] {
|
for cost in [0.10, 0.19] {
|
||||||
@@ -446,7 +488,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let agents = AgentPool::new_test(3000);
|
let agents = AgentPool::new_test(3000);
|
||||||
let output = build_pipeline_status(tmp.path(), &agents);
|
let output = build_status_from_items(tmp.path(), &agents, &items);
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
output.contains("293 [story] — Register all bot commands — $0.29"),
|
output.contains("293 [story] — Register all bot commands — $0.29"),
|
||||||
@@ -458,20 +500,18 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn status_shows_waiting_on_for_story_with_unmet_deps() {
|
fn status_shows_waiting_on_for_story_with_unmet_deps() {
|
||||||
use std::io::Write;
|
|
||||||
use tempfile::TempDir;
|
use tempfile::TempDir;
|
||||||
|
|
||||||
let tmp = TempDir::new().unwrap();
|
let tmp = TempDir::new().unwrap();
|
||||||
let stage_dir = tmp.path().join(".huskies/work/2_current");
|
|
||||||
std::fs::create_dir_all(&stage_dir).unwrap();
|
|
||||||
|
|
||||||
// Dep 999 is NOT done — no 5_done directory at all.
|
// Story 10 depends on story 999, which is NOT in all_items (treated as met)
|
||||||
let story_path = stage_dir.join("10_story_waiting.md");
|
// OR present in backlog (unmet). Let's add dep 999 in Backlog stage (unmet).
|
||||||
let mut f = std::fs::File::create(&story_path).unwrap();
|
let items = vec![
|
||||||
writeln!(f, "---\nname: Waiting Story\ndepends_on: [999]\n---\n").unwrap();
|
make_item_with_deps("10_story_waiting", "Waiting Story", Stage::Coding, vec![999]),
|
||||||
|
make_item("999_story_dep", "Dep Story", Stage::Backlog),
|
||||||
|
];
|
||||||
|
|
||||||
let agents = AgentPool::new_test(3000);
|
let agents = AgentPool::new_test(3000);
|
||||||
let output = build_pipeline_status(tmp.path(), &agents);
|
let output = build_status_from_items(tmp.path(), &agents, &items);
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
output.contains("waiting on: 999"),
|
output.contains("waiting on: 999"),
|
||||||
@@ -481,23 +521,20 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn status_does_not_show_waiting_on_when_dep_is_done() {
|
fn status_does_not_show_waiting_on_when_dep_is_done() {
|
||||||
use std::io::Write;
|
|
||||||
use tempfile::TempDir;
|
use tempfile::TempDir;
|
||||||
|
|
||||||
let tmp = TempDir::new().unwrap();
|
let tmp = TempDir::new().unwrap();
|
||||||
let stage_dir = tmp.path().join(".huskies/work/2_current");
|
|
||||||
let done_dir = tmp.path().join(".huskies/work/5_done");
|
|
||||||
std::fs::create_dir_all(&stage_dir).unwrap();
|
|
||||||
std::fs::create_dir_all(&done_dir).unwrap();
|
|
||||||
|
|
||||||
// Dep 999 is done.
|
// Dep 999 is in Done stage — met.
|
||||||
std::fs::write(done_dir.join("999_story_dep.md"), "---\nname: Dep\n---\n").unwrap();
|
let items = vec![
|
||||||
let story_path = stage_dir.join("10_story_unblocked.md");
|
make_item_with_deps("10_story_unblocked", "Unblocked Story", Stage::Coding, vec![999]),
|
||||||
let mut f = std::fs::File::create(&story_path).unwrap();
|
make_item("999_story_dep", "Dep Story", Stage::Done {
|
||||||
writeln!(f, "---\nname: Unblocked Story\ndepends_on: [999]\n---\n").unwrap();
|
merged_at: Utc::now(),
|
||||||
|
merge_commit: crate::pipeline_state::GitSha("abc123".to_string()),
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
|
||||||
let agents = AgentPool::new_test(3000);
|
let agents = AgentPool::new_test(3000);
|
||||||
let output = build_pipeline_status(tmp.path(), &agents);
|
let output = build_status_from_items(tmp.path(), &agents, &items);
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
!output.contains("waiting on"),
|
!output.contains("waiting on"),
|
||||||
@@ -507,19 +544,13 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn status_shows_no_waiting_info_when_no_deps() {
|
fn status_shows_no_waiting_info_when_no_deps() {
|
||||||
use std::io::Write;
|
|
||||||
use tempfile::TempDir;
|
use tempfile::TempDir;
|
||||||
|
|
||||||
let tmp = TempDir::new().unwrap();
|
let tmp = TempDir::new().unwrap();
|
||||||
let stage_dir = tmp.path().join(".huskies/work/2_current");
|
|
||||||
std::fs::create_dir_all(&stage_dir).unwrap();
|
|
||||||
|
|
||||||
let story_path = stage_dir.join("42_story_nodeps.md");
|
let items = vec![make_item("42_story_nodeps", "No Deps Story", Stage::Coding)];
|
||||||
let mut f = std::fs::File::create(&story_path).unwrap();
|
|
||||||
writeln!(f, "---\nname: No Deps Story\n---\n").unwrap();
|
|
||||||
|
|
||||||
let agents = AgentPool::new_test(3000);
|
let agents = AgentPool::new_test(3000);
|
||||||
let output = build_pipeline_status(tmp.path(), &agents);
|
let output = build_status_from_items(tmp.path(), &agents, &items);
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
!output.contains("waiting on"),
|
!output.contains("waiting on"),
|
||||||
@@ -554,53 +585,44 @@ mod tests {
|
|||||||
assert_eq!(traffic_light_dot(true, false, false), "\u{1F534} "); // 🔴
|
assert_eq!(traffic_light_dot(true, false, false), "\u{1F534} "); // 🔴
|
||||||
}
|
}
|
||||||
|
|
||||||
// -- read_story_blocked --------------------------------------------------
|
// -- Stage::is_blocked() replaces read_story_blocked --------------------
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn read_story_blocked_returns_true_when_blocked() {
|
fn stage_is_blocked_returns_true_for_archived_blocked() {
|
||||||
use tempfile::TempDir;
|
let stage = Stage::Archived {
|
||||||
let tmp = TempDir::new().unwrap();
|
archived_at: Utc::now(),
|
||||||
let stage_dir = tmp.path().join(".huskies/work/2_current");
|
reason: ArchiveReason::Blocked {
|
||||||
std::fs::create_dir_all(&stage_dir).unwrap();
|
reason: "too many retries".to_string(),
|
||||||
std::fs::write(
|
},
|
||||||
stage_dir.join("42_story_foo.md"),
|
};
|
||||||
"---\nname: Foo\nblocked: true\n---\n",
|
assert!(stage.is_blocked());
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
assert!(read_story_blocked(tmp.path(), "2_current", "42_story_foo"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn read_story_blocked_returns_false_when_not_blocked() {
|
fn stage_is_blocked_returns_false_for_coding() {
|
||||||
use tempfile::TempDir;
|
assert!(!Stage::Coding.is_blocked());
|
||||||
let tmp = TempDir::new().unwrap();
|
}
|
||||||
let stage_dir = tmp.path().join(".huskies/work/2_current");
|
|
||||||
std::fs::create_dir_all(&stage_dir).unwrap();
|
#[test]
|
||||||
std::fs::write(
|
fn stage_is_blocked_returns_false_for_archived_completed() {
|
||||||
stage_dir.join("42_story_foo.md"),
|
let stage = Stage::Archived {
|
||||||
"---\nname: Foo\n---\n",
|
archived_at: Utc::now(),
|
||||||
)
|
reason: ArchiveReason::Completed,
|
||||||
.unwrap();
|
};
|
||||||
assert!(!read_story_blocked(tmp.path(), "2_current", "42_story_foo"));
|
assert!(!stage.is_blocked());
|
||||||
}
|
}
|
||||||
|
|
||||||
// -- status output shows idle dot for items with no active agent --------
|
// -- status output shows idle dot for items with no active agent --------
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn status_shows_idle_dot_for_unassigned_story() {
|
fn status_shows_idle_dot_for_unassigned_story() {
|
||||||
use std::io::Write;
|
|
||||||
use tempfile::TempDir;
|
use tempfile::TempDir;
|
||||||
|
|
||||||
let tmp = TempDir::new().unwrap();
|
let tmp = TempDir::new().unwrap();
|
||||||
let stage_dir = tmp.path().join(".huskies/work/2_current");
|
|
||||||
std::fs::create_dir_all(&stage_dir).unwrap();
|
|
||||||
|
|
||||||
let story_path = stage_dir.join("42_story_idle.md");
|
let items = vec![make_item("42_story_idle", "Idle Story", Stage::Coding)];
|
||||||
let mut f = std::fs::File::create(&story_path).unwrap();
|
|
||||||
writeln!(f, "---\nname: Idle Story\n---\n").unwrap();
|
|
||||||
|
|
||||||
let agents = AgentPool::new_test(3000);
|
let agents = AgentPool::new_test(3000);
|
||||||
let output = build_pipeline_status(tmp.path(), &agents);
|
let output = build_status_from_items(tmp.path(), &agents, &items);
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
output.contains("\u{26AA} "), // ⚪
|
output.contains("\u{26AA} "), // ⚪
|
||||||
@@ -610,23 +632,69 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn status_shows_blocked_dot_for_blocked_story() {
|
fn status_shows_blocked_dot_for_blocked_story() {
|
||||||
use std::io::Write;
|
|
||||||
use tempfile::TempDir;
|
use tempfile::TempDir;
|
||||||
|
|
||||||
let tmp = TempDir::new().unwrap();
|
let tmp = TempDir::new().unwrap();
|
||||||
let stage_dir = tmp.path().join(".huskies/work/2_current");
|
|
||||||
std::fs::create_dir_all(&stage_dir).unwrap();
|
|
||||||
|
|
||||||
let story_path = stage_dir.join("42_story_blocked.md");
|
let items = vec![make_item(
|
||||||
let mut f = std::fs::File::create(&story_path).unwrap();
|
"42_story_blocked",
|
||||||
writeln!(f, "---\nname: Blocked Story\nblocked: true\n---\n").unwrap();
|
"Blocked Story",
|
||||||
|
Stage::Archived {
|
||||||
|
archived_at: Utc::now(),
|
||||||
|
reason: ArchiveReason::Blocked {
|
||||||
|
reason: "retry limit exceeded".to_string(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)];
|
||||||
|
|
||||||
let agents = AgentPool::new_test(3000);
|
let agents = AgentPool::new_test(3000);
|
||||||
let output = build_pipeline_status(tmp.path(), &agents);
|
let output = build_status_from_items(tmp.path(), &agents, &items);
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
output.contains("\u{1F534} "), // 🔴
|
output.contains("\u{1F534} "), // 🔴
|
||||||
"blocked story should show red circle emoji: {output}"
|
"blocked story should show red circle emoji: {output}"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -- Regression: CRDT-only story appears in correct stage ---------------
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn status_shows_crdt_done_story_in_done_not_backlog() {
|
||||||
|
use tempfile::TempDir;
|
||||||
|
let tmp = TempDir::new().unwrap();
|
||||||
|
|
||||||
|
// Story is Done in the typed API — even if a stale 1_backlog/ shadow existed
|
||||||
|
// on the filesystem, the status must show it in Done, not Backlog.
|
||||||
|
let items = vec![make_item(
|
||||||
|
"503_story_some_feature",
|
||||||
|
"Some Feature",
|
||||||
|
Stage::Done {
|
||||||
|
merged_at: Utc::now(),
|
||||||
|
merge_commit: crate::pipeline_state::GitSha("deadbeef".to_string()),
|
||||||
|
},
|
||||||
|
)];
|
||||||
|
|
||||||
|
let agents = AgentPool::new_test(3000);
|
||||||
|
let output = build_status_from_items(tmp.path(), &agents, &items);
|
||||||
|
|
||||||
|
// Must appear under Done, not Backlog.
|
||||||
|
let done_pos = output.find("**Done**").expect("Done section must exist");
|
||||||
|
let backlog_pos = output.find("**Backlog**").expect("Backlog section must exist");
|
||||||
|
let story_pos = output.find("503 [story]").expect("story must appear in output");
|
||||||
|
|
||||||
|
assert!(
|
||||||
|
story_pos > done_pos,
|
||||||
|
"story should appear after Done header: backlog={backlog_pos} done={done_pos} story={story_pos}\n{output}"
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
story_pos > backlog_pos,
|
||||||
|
"story should not be in the Backlog section: {output}"
|
||||||
|
);
|
||||||
|
|
||||||
|
// Verify it's not in Backlog section specifically.
|
||||||
|
let backlog_section = &output[backlog_pos..done_pos];
|
||||||
|
assert!(
|
||||||
|
!backlog_section.contains("503"),
|
||||||
|
"503 must not appear in Backlog section: {backlog_section}"
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user