huskies: merge 484_story_story_dependencies_in_pipeline_auto_assign
This commit is contained in:
@@ -14,7 +14,8 @@ use super::scan::{
|
|||||||
is_story_assigned_for_stage, scan_stage_items,
|
is_story_assigned_for_stage, scan_stage_items,
|
||||||
};
|
};
|
||||||
use super::story_checks::{
|
use super::story_checks::{
|
||||||
has_merge_failure, has_review_hold, is_story_blocked, read_story_front_matter_agent,
|
has_merge_failure, has_review_hold, has_unmet_dependencies, is_story_blocked,
|
||||||
|
read_story_front_matter_agent,
|
||||||
};
|
};
|
||||||
|
|
||||||
impl AgentPool {
|
impl AgentPool {
|
||||||
@@ -52,6 +53,14 @@ impl AgentPool {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Skip stories whose dependencies haven't landed yet.
|
||||||
|
if has_unmet_dependencies(project_root, stage_dir, story_id) {
|
||||||
|
slog!(
|
||||||
|
"[auto-assign] Story '{story_id}' has unmet dependencies; skipping until deps are done."
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Skip stories in 4_merge/ that already have a reported merge failure.
|
// Skip stories in 4_merge/ that already have a reported merge failure.
|
||||||
// These need human intervention — auto-assigning a new mergemaster
|
// These need human intervention — auto-assigning a new mergemaster
|
||||||
// would just waste tokens on the same broken merge.
|
// would just waste tokens on the same broken merge.
|
||||||
@@ -420,6 +429,74 @@ mod tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Story 484: auto_assign must skip stories whose depends_on entries are not
|
||||||
|
/// yet in 5_done or 6_archived.
|
||||||
|
#[tokio::test]
|
||||||
|
async fn auto_assign_skips_stories_with_unmet_dependencies() {
|
||||||
|
let tmp = tempfile::tempdir().unwrap();
|
||||||
|
let root = tmp.path();
|
||||||
|
let sk = root.join(".huskies");
|
||||||
|
let current = sk.join("work/2_current");
|
||||||
|
std::fs::create_dir_all(¤t).unwrap();
|
||||||
|
std::fs::write(
|
||||||
|
sk.join("project.toml"),
|
||||||
|
"[[agent]]\nname = \"coder-1\"\nstage = \"coder\"\n",
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
// Story 10 depends on 999 which is not done.
|
||||||
|
std::fs::write(
|
||||||
|
current.join("10_story_waiting.md"),
|
||||||
|
"---\nname: Waiting\ndepends_on: [999]\n---\n",
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let pool = AgentPool::new_test(3001);
|
||||||
|
pool.auto_assign_available_work(root).await;
|
||||||
|
|
||||||
|
let agents = pool.agents.lock().unwrap();
|
||||||
|
assert!(
|
||||||
|
agents.is_empty(),
|
||||||
|
"story with unmet deps should not be auto-assigned"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Story 484: auto_assign must pick up a story once its dependency lands in 5_done.
|
||||||
|
#[tokio::test]
|
||||||
|
async fn auto_assign_picks_up_story_after_dep_completes() {
|
||||||
|
let tmp = tempfile::tempdir().unwrap();
|
||||||
|
let root = tmp.path();
|
||||||
|
let sk = root.join(".huskies");
|
||||||
|
let current = sk.join("work/2_current");
|
||||||
|
let done = sk.join("work/5_done");
|
||||||
|
std::fs::create_dir_all(¤t).unwrap();
|
||||||
|
std::fs::create_dir_all(&done).unwrap();
|
||||||
|
std::fs::write(
|
||||||
|
sk.join("project.toml"),
|
||||||
|
"[[agent]]\nname = \"coder-1\"\nstage = \"coder\"\n",
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
// Dep 999 is now done.
|
||||||
|
std::fs::write(done.join("999_story_dep.md"), "---\nname: Dep\n---\n").unwrap();
|
||||||
|
// Story 10 depends on 999 which is done.
|
||||||
|
std::fs::write(
|
||||||
|
current.join("10_story_unblocked.md"),
|
||||||
|
"---\nname: Unblocked\ndepends_on: [999]\n---\n",
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let pool = AgentPool::new_test(3001);
|
||||||
|
pool.auto_assign_available_work(root).await;
|
||||||
|
|
||||||
|
let agents = pool.agents.lock().unwrap();
|
||||||
|
let has_pending = agents
|
||||||
|
.values()
|
||||||
|
.any(|a| matches!(a.status, crate::agents::AgentStatus::Pending | crate::agents::AgentStatus::Running));
|
||||||
|
assert!(
|
||||||
|
has_pending,
|
||||||
|
"story with all deps done should be auto-assigned"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/// Two concurrent auto_assign_available_work calls must not assign the same
|
/// Two concurrent auto_assign_available_work calls must not assign the same
|
||||||
/// agent to two stories simultaneously. After both complete, at most one
|
/// agent to two stories simultaneously. After both complete, at most one
|
||||||
/// Pending/Running entry must exist per agent name.
|
/// Pending/Running entry must exist per agent name.
|
||||||
|
|||||||
@@ -57,6 +57,18 @@ pub(super) fn is_story_blocked(project_root: &Path, stage_dir: &str, story_id: &
|
|||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return `true` if the story has any `depends_on` entries that are not yet in
|
||||||
|
/// `5_done` or `6_archived`.
|
||||||
|
///
|
||||||
|
/// Auto-assign calls this to hold back stories whose dependencies haven't landed.
|
||||||
|
pub(super) fn has_unmet_dependencies(
|
||||||
|
project_root: &Path,
|
||||||
|
stage_dir: &str,
|
||||||
|
story_id: &str,
|
||||||
|
) -> bool {
|
||||||
|
!crate::io::story_metadata::check_unmet_deps(project_root, stage_dir, story_id).is_empty()
|
||||||
|
}
|
||||||
|
|
||||||
/// Return `true` if the story file has a `merge_failure` field in its front matter.
|
/// Return `true` if the story file has a `merge_failure` field in its front matter.
|
||||||
pub(super) fn has_merge_failure(project_root: &Path, stage_dir: &str, story_id: &str) -> bool {
|
pub(super) fn has_merge_failure(project_root: &Path, stage_dir: &str, story_id: &str) -> bool {
|
||||||
use crate::io::story_metadata::parse_front_matter;
|
use crate::io::story_metadata::parse_front_matter;
|
||||||
@@ -110,4 +122,42 @@ mod tests {
|
|||||||
let tmp = tempfile::tempdir().unwrap();
|
let tmp = tempfile::tempdir().unwrap();
|
||||||
assert!(!has_review_hold(tmp.path(), "3_qa", "99_spike_missing"));
|
assert!(!has_review_hold(tmp.path(), "3_qa", "99_spike_missing"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn has_unmet_dependencies_returns_true_when_dep_not_done() {
|
||||||
|
let tmp = tempfile::tempdir().unwrap();
|
||||||
|
let current = tmp.path().join(".huskies/work/2_current");
|
||||||
|
std::fs::create_dir_all(¤t).unwrap();
|
||||||
|
std::fs::write(
|
||||||
|
current.join("10_story_blocked.md"),
|
||||||
|
"---\nname: Blocked\ndepends_on: [999]\n---\n",
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
assert!(has_unmet_dependencies(tmp.path(), "2_current", "10_story_blocked"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn has_unmet_dependencies_returns_false_when_dep_done() {
|
||||||
|
let tmp = tempfile::tempdir().unwrap();
|
||||||
|
let current = tmp.path().join(".huskies/work/2_current");
|
||||||
|
let done = tmp.path().join(".huskies/work/5_done");
|
||||||
|
std::fs::create_dir_all(¤t).unwrap();
|
||||||
|
std::fs::create_dir_all(&done).unwrap();
|
||||||
|
std::fs::write(done.join("999_story_dep.md"), "---\nname: Dep\n---\n").unwrap();
|
||||||
|
std::fs::write(
|
||||||
|
current.join("10_story_ok.md"),
|
||||||
|
"---\nname: Ok\ndepends_on: [999]\n---\n",
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
assert!(!has_unmet_dependencies(tmp.path(), "2_current", "10_story_ok"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn has_unmet_dependencies_returns_false_when_no_deps() {
|
||||||
|
let tmp = tempfile::tempdir().unwrap();
|
||||||
|
let current = tmp.path().join(".huskies/work/2_current");
|
||||||
|
std::fs::create_dir_all(¤t).unwrap();
|
||||||
|
std::fs::write(current.join("5_story_free.md"), "---\nname: Free\n---\n").unwrap();
|
||||||
|
assert!(!has_unmet_dependencies(tmp.path(), "2_current", "5_story_free"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,282 @@
|
|||||||
|
//! Handler for the `depends` command.
|
||||||
|
//!
|
||||||
|
//! `{bot_name} depends <number> <dep1> [dep2 ...]` locates the work item by
|
||||||
|
//! number across all pipeline stages and writes (or updates) the `depends_on`
|
||||||
|
//! front-matter field with the provided dependency numbers.
|
||||||
|
//!
|
||||||
|
//! Passing no dependency numbers clears the field entirely.
|
||||||
|
|
||||||
|
use super::CommandContext;
|
||||||
|
use crate::io::story_metadata::{parse_front_matter, write_depends_on};
|
||||||
|
|
||||||
|
/// All pipeline stage directories searched when finding a work item by number.
|
||||||
|
const SEARCH_DIRS: &[&str] = &[
|
||||||
|
"1_backlog",
|
||||||
|
"2_current",
|
||||||
|
"3_qa",
|
||||||
|
"4_merge",
|
||||||
|
"5_done",
|
||||||
|
"6_archived",
|
||||||
|
];
|
||||||
|
|
||||||
|
/// Handle the `depends` command.
|
||||||
|
///
|
||||||
|
/// Syntax: `depends <number> [dep1 dep2 ...]`
|
||||||
|
///
|
||||||
|
/// - `depends 484 477 478` — set story 484's dependencies to [477, 478]
|
||||||
|
/// - `depends 484` — clear all dependencies for story 484
|
||||||
|
pub(super) fn handle_depends(ctx: &CommandContext) -> Option<String> {
|
||||||
|
let args = ctx.args.trim();
|
||||||
|
|
||||||
|
if args.is_empty() {
|
||||||
|
return Some(format!(
|
||||||
|
"Usage: `{} depends <number> [dep1 dep2 ...]`\n\nExamples:\n\
|
||||||
|
• `{0} depends 484 477 478` — set depends_on: [477, 478]\n\
|
||||||
|
• `{0} depends 484` — clear all dependencies",
|
||||||
|
ctx.bot_name
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut parts = args.split_whitespace();
|
||||||
|
let num_str = parts.next().unwrap_or("");
|
||||||
|
|
||||||
|
if !num_str.chars().all(|c| c.is_ascii_digit()) || num_str.is_empty() {
|
||||||
|
return Some(format!(
|
||||||
|
"Invalid story number: `{num_str}`. Usage: `{} depends <number> [dep1 dep2 ...]`",
|
||||||
|
ctx.bot_name
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse dependency numbers.
|
||||||
|
let mut deps: Vec<u32> = Vec::new();
|
||||||
|
for token in parts {
|
||||||
|
match token.parse::<u32>() {
|
||||||
|
Ok(n) => deps.push(n),
|
||||||
|
Err(_) => {
|
||||||
|
return Some(format!(
|
||||||
|
"Invalid dependency number: `{token}`. All numbers must be positive integers."
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find the story file across all pipeline stages by numeric prefix.
|
||||||
|
let mut found: Option<(std::path::PathBuf, String)> = None;
|
||||||
|
|
||||||
|
'outer: for stage_dir in SEARCH_DIRS {
|
||||||
|
let dir = ctx
|
||||||
|
.project_root
|
||||||
|
.join(".huskies")
|
||||||
|
.join("work")
|
||||||
|
.join(stage_dir);
|
||||||
|
if !dir.exists() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if let Ok(entries) = std::fs::read_dir(&dir) {
|
||||||
|
for entry in entries.flatten() {
|
||||||
|
let path = entry.path();
|
||||||
|
if path.extension().and_then(|e| e.to_str()) != Some("md") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if let Some(stem) = path.file_stem().and_then(|s| s.to_str()) {
|
||||||
|
let file_num = stem
|
||||||
|
.split('_')
|
||||||
|
.next()
|
||||||
|
.filter(|s| !s.is_empty() && s.chars().all(|c| c.is_ascii_digit()))
|
||||||
|
.unwrap_or("");
|
||||||
|
if file_num == num_str {
|
||||||
|
found = Some((path.to_path_buf(), stem.to_string()));
|
||||||
|
break 'outer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let (path, story_id) = match found {
|
||||||
|
Some(f) => f,
|
||||||
|
None => {
|
||||||
|
return Some(format!(
|
||||||
|
"No story, bug, or spike with number **{num_str}** found."
|
||||||
|
));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let story_name = std::fs::read_to_string(&path)
|
||||||
|
.ok()
|
||||||
|
.and_then(|c| parse_front_matter(&c).ok())
|
||||||
|
.and_then(|m| m.name)
|
||||||
|
.unwrap_or_else(|| story_id.clone());
|
||||||
|
|
||||||
|
match write_depends_on(&path, &deps) {
|
||||||
|
Ok(()) if deps.is_empty() => Some(format!(
|
||||||
|
"Cleared all dependencies for **{story_name}** ({story_id})."
|
||||||
|
)),
|
||||||
|
Ok(()) => {
|
||||||
|
let nums: Vec<String> = deps.iter().map(|n| n.to_string()).collect();
|
||||||
|
Some(format!(
|
||||||
|
"Set depends_on: [{}] for **{story_name}** ({story_id}).",
|
||||||
|
nums.join(", ")
|
||||||
|
))
|
||||||
|
}
|
||||||
|
Err(e) => Some(format!("Failed to update dependencies for {story_id}: {e}")),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Tests
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use crate::agents::AgentPool;
|
||||||
|
use std::collections::HashSet;
|
||||||
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
|
use super::super::{CommandDispatch, try_handle_command};
|
||||||
|
|
||||||
|
fn depends_cmd_with_root(root: &std::path::Path, args: &str) -> Option<String> {
|
||||||
|
let agents = Arc::new(AgentPool::new_test(3000));
|
||||||
|
let ambient_rooms = Arc::new(Mutex::new(HashSet::new()));
|
||||||
|
let room_id = "!test:example.com".to_string();
|
||||||
|
let dispatch = CommandDispatch {
|
||||||
|
bot_name: "Timmy",
|
||||||
|
bot_user_id: "@timmy:homeserver.local",
|
||||||
|
project_root: root,
|
||||||
|
agents: &agents,
|
||||||
|
ambient_rooms: &ambient_rooms,
|
||||||
|
room_id: &room_id,
|
||||||
|
};
|
||||||
|
try_handle_command(&dispatch, &format!("@timmy depends {args}"))
|
||||||
|
}
|
||||||
|
|
||||||
|
use crate::chat::test_helpers::write_story_file;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn depends_command_is_registered() {
|
||||||
|
use super::super::commands;
|
||||||
|
assert!(
|
||||||
|
commands().iter().any(|c| c.name == "depends"),
|
||||||
|
"depends command must be in the registry"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn depends_command_appears_in_help() {
|
||||||
|
let result = super::super::tests::try_cmd_addressed(
|
||||||
|
"Timmy",
|
||||||
|
"@timmy:homeserver.local",
|
||||||
|
"@timmy help",
|
||||||
|
);
|
||||||
|
let output = result.unwrap();
|
||||||
|
assert!(output.contains("depends"), "help should list depends command: {output}");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn depends_no_args_returns_usage() {
|
||||||
|
let tmp = tempfile::TempDir::new().unwrap();
|
||||||
|
let output = depends_cmd_with_root(tmp.path(), "").unwrap();
|
||||||
|
assert!(output.contains("Usage"), "no args should show usage: {output}");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn depends_non_numeric_number_returns_error() {
|
||||||
|
let tmp = tempfile::TempDir::new().unwrap();
|
||||||
|
let output = depends_cmd_with_root(tmp.path(), "abc 1 2").unwrap();
|
||||||
|
assert!(
|
||||||
|
output.contains("Invalid story number"),
|
||||||
|
"non-numeric story number should error: {output}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn depends_not_found_returns_error() {
|
||||||
|
let tmp = tempfile::TempDir::new().unwrap();
|
||||||
|
let output = depends_cmd_with_root(tmp.path(), "999 1 2").unwrap();
|
||||||
|
assert!(
|
||||||
|
output.contains("999") && output.contains("found"),
|
||||||
|
"not-found should mention number: {output}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn depends_invalid_dep_number_returns_error() {
|
||||||
|
let tmp = tempfile::TempDir::new().unwrap();
|
||||||
|
write_story_file(
|
||||||
|
tmp.path(),
|
||||||
|
"1_backlog",
|
||||||
|
"42_story_foo.md",
|
||||||
|
"---\nname: Foo\n---\n",
|
||||||
|
);
|
||||||
|
let output = depends_cmd_with_root(tmp.path(), "42 abc").unwrap();
|
||||||
|
assert!(
|
||||||
|
output.contains("Invalid dependency number"),
|
||||||
|
"non-numeric dep should error: {output}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn depends_sets_deps_and_writes_to_file() {
|
||||||
|
let tmp = tempfile::TempDir::new().unwrap();
|
||||||
|
write_story_file(
|
||||||
|
tmp.path(),
|
||||||
|
"1_backlog",
|
||||||
|
"42_story_foo.md",
|
||||||
|
"---\nname: Foo\n---\n",
|
||||||
|
);
|
||||||
|
let output = depends_cmd_with_root(tmp.path(), "42 477 478").unwrap();
|
||||||
|
assert!(
|
||||||
|
output.contains("477") && output.contains("478"),
|
||||||
|
"response should mention dep numbers: {output}"
|
||||||
|
);
|
||||||
|
let contents = std::fs::read_to_string(
|
||||||
|
tmp.path().join(".huskies/work/1_backlog/42_story_foo.md"),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
assert!(
|
||||||
|
contents.contains("depends_on: [477, 478]"),
|
||||||
|
"file should have depends_on set: {contents}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn depends_clears_deps_when_no_deps_given() {
|
||||||
|
let tmp = tempfile::TempDir::new().unwrap();
|
||||||
|
write_story_file(
|
||||||
|
tmp.path(),
|
||||||
|
"2_current",
|
||||||
|
"10_story_bar.md",
|
||||||
|
"---\nname: Bar\ndepends_on: [477]\n---\n",
|
||||||
|
);
|
||||||
|
let output = depends_cmd_with_root(tmp.path(), "10").unwrap();
|
||||||
|
assert!(
|
||||||
|
output.contains("Cleared"),
|
||||||
|
"should confirm clearing deps: {output}"
|
||||||
|
);
|
||||||
|
let contents = std::fs::read_to_string(
|
||||||
|
tmp.path().join(".huskies/work/2_current/10_story_bar.md"),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
assert!(
|
||||||
|
!contents.contains("depends_on"),
|
||||||
|
"file should have depends_on cleared: {contents}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn depends_finds_story_in_any_stage() {
|
||||||
|
let tmp = tempfile::TempDir::new().unwrap();
|
||||||
|
write_story_file(
|
||||||
|
tmp.path(),
|
||||||
|
"3_qa",
|
||||||
|
"55_story_inqa.md",
|
||||||
|
"---\nname: In QA\n---\n",
|
||||||
|
);
|
||||||
|
let output = depends_cmd_with_root(tmp.path(), "55 100").unwrap();
|
||||||
|
assert!(
|
||||||
|
output.contains("In QA") || output.contains("55_story_inqa"),
|
||||||
|
"should find story in qa stage: {output}"
|
||||||
|
);
|
||||||
|
assert!(output.contains("100"), "should mention dep 100: {output}");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@ mod ambient;
|
|||||||
mod assign;
|
mod assign;
|
||||||
mod cost;
|
mod cost;
|
||||||
mod coverage;
|
mod coverage;
|
||||||
|
mod depends;
|
||||||
mod git;
|
mod git;
|
||||||
mod help;
|
mod help;
|
||||||
pub(crate) mod loc;
|
pub(crate) mod loc;
|
||||||
@@ -104,6 +105,11 @@ pub fn commands() -> &'static [BotCommand] {
|
|||||||
description: "Toggle ambient mode for this room: `ambient on` or `ambient off`",
|
description: "Toggle ambient mode for this room: `ambient on` or `ambient off`",
|
||||||
handler: ambient::handle_ambient,
|
handler: ambient::handle_ambient,
|
||||||
},
|
},
|
||||||
|
BotCommand {
|
||||||
|
name: "depends",
|
||||||
|
description: "Set story dependencies: `depends <number> [dep1 dep2 ...]` (no deps = clear)",
|
||||||
|
handler: depends::handle_depends,
|
||||||
|
},
|
||||||
BotCommand {
|
BotCommand {
|
||||||
name: "git",
|
name: "git",
|
||||||
description: "Show git status: branch, uncommitted changes, and ahead/behind remote",
|
description: "Show git status: branch, uncommitted changes, and ahead/behind remote",
|
||||||
|
|||||||
@@ -200,6 +200,18 @@ pub(super) fn build_pipeline_status(project_root: &std::path::Path, agents: &Age
|
|||||||
let agent = active_map.get(story_id);
|
let agent = active_map.get(story_id);
|
||||||
let throttled = agent.map(|a| a.throttled).unwrap_or(false);
|
let throttled = agent.map(|a| a.throttled).unwrap_or(false);
|
||||||
let dot = traffic_light_dot(blocked, throttled, agent.is_some());
|
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 {
|
if let Some(agent) = agent {
|
||||||
let model_str = config
|
let model_str = config
|
||||||
.as_ref()
|
.as_ref()
|
||||||
@@ -207,11 +219,11 @@ pub(super) fn build_pipeline_status(project_root: &std::path::Path, agents: &Age
|
|||||||
.and_then(|ac| ac.model.as_deref())
|
.and_then(|ac| ac.model.as_deref())
|
||||||
.unwrap_or("?");
|
.unwrap_or("?");
|
||||||
out.push_str(&format!(
|
out.push_str(&format!(
|
||||||
" {dot}{display}{cost_suffix} — {} ({model_str})\n",
|
" {dot}{display}{cost_suffix}{dep_suffix} — {} ({model_str})\n",
|
||||||
agent.agent_name
|
agent.agent_name
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
out.push_str(&format!(" {dot}{display}{cost_suffix}\n"));
|
out.push_str(&format!(" {dot}{display}{cost_suffix}{dep_suffix}\n"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -470,6 +482,79 @@ mod tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -- dependency display in status output --------------------------------
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn status_shows_waiting_on_for_story_with_unmet_deps() {
|
||||||
|
use std::io::Write;
|
||||||
|
use tempfile::TempDir;
|
||||||
|
|
||||||
|
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.
|
||||||
|
let story_path = stage_dir.join("10_story_waiting.md");
|
||||||
|
let mut f = std::fs::File::create(&story_path).unwrap();
|
||||||
|
writeln!(f, "---\nname: Waiting Story\ndepends_on: [999]\n---\n").unwrap();
|
||||||
|
|
||||||
|
let agents = AgentPool::new_test(3000);
|
||||||
|
let output = build_pipeline_status(tmp.path(), &agents);
|
||||||
|
|
||||||
|
assert!(
|
||||||
|
output.contains("waiting on: 999"),
|
||||||
|
"status should show waiting-on info for unmet deps: {output}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn status_does_not_show_waiting_on_when_dep_is_done() {
|
||||||
|
use std::io::Write;
|
||||||
|
use tempfile::TempDir;
|
||||||
|
|
||||||
|
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.
|
||||||
|
std::fs::write(done_dir.join("999_story_dep.md"), "---\nname: Dep\n---\n").unwrap();
|
||||||
|
let story_path = stage_dir.join("10_story_unblocked.md");
|
||||||
|
let mut f = std::fs::File::create(&story_path).unwrap();
|
||||||
|
writeln!(f, "---\nname: Unblocked Story\ndepends_on: [999]\n---\n").unwrap();
|
||||||
|
|
||||||
|
let agents = AgentPool::new_test(3000);
|
||||||
|
let output = build_pipeline_status(tmp.path(), &agents);
|
||||||
|
|
||||||
|
assert!(
|
||||||
|
!output.contains("waiting on"),
|
||||||
|
"status should not show waiting-on when all deps are done: {output}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn status_shows_no_waiting_info_when_no_deps() {
|
||||||
|
use std::io::Write;
|
||||||
|
use tempfile::TempDir;
|
||||||
|
|
||||||
|
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 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 output = build_pipeline_status(tmp.path(), &agents);
|
||||||
|
|
||||||
|
assert!(
|
||||||
|
!output.contains("waiting on"),
|
||||||
|
"status should not show waiting-on for stories without deps: {output}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// -- traffic_light_dot --------------------------------------------------
|
// -- traffic_light_dot --------------------------------------------------
|
||||||
|
|
||||||
// -- build_pipeline_status_html (colored dots) --------------------------
|
// -- build_pipeline_status_html (colored dots) --------------------------
|
||||||
|
|||||||
@@ -53,6 +53,9 @@ pub struct StoryMetadata {
|
|||||||
pub retry_count: Option<u32>,
|
pub retry_count: Option<u32>,
|
||||||
/// When `true`, auto-assign will skip this story (retry limit exceeded).
|
/// When `true`, auto-assign will skip this story (retry limit exceeded).
|
||||||
pub blocked: Option<bool>,
|
pub blocked: Option<bool>,
|
||||||
|
/// Story numbers this story depends on. Auto-assign will skip this story
|
||||||
|
/// until all dependencies have reached `5_done` or `6_archived`.
|
||||||
|
pub depends_on: Option<Vec<u32>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
@@ -83,6 +86,8 @@ struct FrontMatter {
|
|||||||
retry_count: Option<u32>,
|
retry_count: Option<u32>,
|
||||||
/// When `true`, auto-assign will skip this story (retry limit exceeded).
|
/// When `true`, auto-assign will skip this story (retry limit exceeded).
|
||||||
blocked: Option<bool>,
|
blocked: Option<bool>,
|
||||||
|
/// Story numbers this story depends on.
|
||||||
|
depends_on: Option<Vec<u32>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_front_matter(contents: &str) -> Result<StoryMetadata, StoryMetaError> {
|
pub fn parse_front_matter(contents: &str) -> Result<StoryMetadata, StoryMetaError> {
|
||||||
@@ -122,6 +127,7 @@ fn build_metadata(front: FrontMatter) -> StoryMetadata {
|
|||||||
qa,
|
qa,
|
||||||
retry_count: front.retry_count,
|
retry_count: front.retry_count,
|
||||||
blocked: front.blocked,
|
blocked: front.blocked,
|
||||||
|
depends_on: front.depends_on,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -279,6 +285,72 @@ pub fn write_blocked(path: &Path) -> Result<(), String> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Write or update a `depends_on:` field in the YAML front matter of a story file.
|
||||||
|
///
|
||||||
|
/// Serialises `deps` as an inline YAML sequence, e.g. `[477, 478]`.
|
||||||
|
/// If `deps` is empty the field is removed.
|
||||||
|
/// If no front matter is present, this is a no-op (returns Ok).
|
||||||
|
pub fn write_depends_on(path: &Path, deps: &[u32]) -> Result<(), String> {
|
||||||
|
let contents =
|
||||||
|
fs::read_to_string(path).map_err(|e| format!("Failed to read story file: {e}"))?;
|
||||||
|
let updated = if deps.is_empty() {
|
||||||
|
remove_front_matter_field(&contents, "depends_on")
|
||||||
|
} else {
|
||||||
|
let nums: Vec<String> = deps.iter().map(|n| n.to_string()).collect();
|
||||||
|
let yaml_value = format!("[{}]", nums.join(", "));
|
||||||
|
set_front_matter_field(&contents, "depends_on", &yaml_value)
|
||||||
|
};
|
||||||
|
fs::write(path, &updated).map_err(|e| format!("Failed to write story file: {e}"))?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return the list of dependency story numbers from `story_id`'s front matter
|
||||||
|
/// that have **not** yet reached `5_done` or `6_archived`.
|
||||||
|
///
|
||||||
|
/// Returns an empty `Vec` when there are no unmet dependencies (including when
|
||||||
|
/// the story has no `depends_on` field at all).
|
||||||
|
pub fn check_unmet_deps(project_root: &Path, stage_dir: &str, story_id: &str) -> Vec<u32> {
|
||||||
|
let path = project_root
|
||||||
|
.join(".huskies")
|
||||||
|
.join("work")
|
||||||
|
.join(stage_dir)
|
||||||
|
.join(format!("{story_id}.md"));
|
||||||
|
let contents = match fs::read_to_string(&path) {
|
||||||
|
Ok(c) => c,
|
||||||
|
Err(_) => return Vec::new(),
|
||||||
|
};
|
||||||
|
let deps = match parse_front_matter(&contents).ok().and_then(|m| m.depends_on) {
|
||||||
|
Some(d) => d,
|
||||||
|
None => return Vec::new(),
|
||||||
|
};
|
||||||
|
deps.into_iter()
|
||||||
|
.filter(|&dep| !dep_is_done(project_root, dep))
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return `true` if a story with the given numeric ID exists in `5_done` or `6_archived`.
|
||||||
|
fn dep_is_done(project_root: &Path, dep_number: u32) -> bool {
|
||||||
|
let prefix = format!("{dep_number}_");
|
||||||
|
let exact = dep_number.to_string();
|
||||||
|
for stage in &["5_done", "6_archived"] {
|
||||||
|
let dir = project_root.join(".huskies").join("work").join(stage);
|
||||||
|
if let Ok(entries) = fs::read_dir(&dir) {
|
||||||
|
for entry in entries.flatten() {
|
||||||
|
let path = entry.path();
|
||||||
|
if path.extension().and_then(|e| e.to_str()) != Some("md") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if let Some(stem) = path.file_stem().and_then(|s| s.to_str())
|
||||||
|
&& (stem == exact || stem.starts_with(&prefix))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
/// Append rejection notes to a story file body.
|
/// Append rejection notes to a story file body.
|
||||||
///
|
///
|
||||||
/// Adds a `## QA Rejection Notes` section at the end of the file so the coder
|
/// Adds a `## QA Rejection Notes` section at the end of the file so the coder
|
||||||
@@ -529,6 +601,96 @@ workflow: tdd
|
|||||||
assert_eq!(resolve_qa_mode(path, QaMode::Server), QaMode::Server);
|
assert_eq!(resolve_qa_mode(path, QaMode::Server), QaMode::Server);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parses_depends_on_from_front_matter() {
|
||||||
|
let input = "---\nname: Story\ndepends_on: [477, 478]\n---\n# Story\n";
|
||||||
|
let meta = parse_front_matter(input).expect("front matter");
|
||||||
|
assert_eq!(meta.depends_on, Some(vec![477, 478]));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn depends_on_defaults_to_none() {
|
||||||
|
let input = "---\nname: Story\n---\n# Story\n";
|
||||||
|
let meta = parse_front_matter(input).expect("front matter");
|
||||||
|
assert_eq!(meta.depends_on, None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn write_depends_on_sets_field() {
|
||||||
|
let tmp = tempfile::tempdir().unwrap();
|
||||||
|
let path = tmp.path().join("story.md");
|
||||||
|
std::fs::write(&path, "---\nname: Test\n---\n# Story\n").unwrap();
|
||||||
|
write_depends_on(&path, &[477, 478]).unwrap();
|
||||||
|
let contents = std::fs::read_to_string(&path).unwrap();
|
||||||
|
assert!(contents.contains("depends_on: [477, 478]"), "{contents}");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn write_depends_on_removes_field_when_empty() {
|
||||||
|
let tmp = tempfile::tempdir().unwrap();
|
||||||
|
let path = tmp.path().join("story.md");
|
||||||
|
std::fs::write(&path, "---\nname: Test\ndepends_on: [477]\n---\n# Story\n").unwrap();
|
||||||
|
write_depends_on(&path, &[]).unwrap();
|
||||||
|
let contents = std::fs::read_to_string(&path).unwrap();
|
||||||
|
assert!(!contents.contains("depends_on"), "{contents}");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn check_unmet_deps_returns_empty_when_no_deps() {
|
||||||
|
let tmp = tempfile::tempdir().unwrap();
|
||||||
|
let stage = tmp.path().join(".huskies/work/2_current");
|
||||||
|
std::fs::create_dir_all(&stage).unwrap();
|
||||||
|
std::fs::write(stage.join("10_story_foo.md"), "---\nname: Foo\n---\n").unwrap();
|
||||||
|
let unmet = check_unmet_deps(tmp.path(), "2_current", "10_story_foo");
|
||||||
|
assert!(unmet.is_empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn check_unmet_deps_returns_unmet_numbers() {
|
||||||
|
let tmp = tempfile::tempdir().unwrap();
|
||||||
|
let current = tmp.path().join(".huskies/work/2_current");
|
||||||
|
let done = tmp.path().join(".huskies/work/5_done");
|
||||||
|
std::fs::create_dir_all(¤t).unwrap();
|
||||||
|
std::fs::create_dir_all(&done).unwrap();
|
||||||
|
// Dep 477 is done, dep 478 is not.
|
||||||
|
std::fs::write(done.join("477_story_dep.md"), "---\nname: Dep\n---\n").unwrap();
|
||||||
|
std::fs::write(
|
||||||
|
current.join("10_story_foo.md"),
|
||||||
|
"---\nname: Foo\ndepends_on: [477, 478]\n---\n",
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
let unmet = check_unmet_deps(tmp.path(), "2_current", "10_story_foo");
|
||||||
|
assert_eq!(unmet, vec![478]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn check_unmet_deps_returns_empty_when_all_deps_done() {
|
||||||
|
let tmp = tempfile::tempdir().unwrap();
|
||||||
|
let current = tmp.path().join(".huskies/work/2_current");
|
||||||
|
let done = tmp.path().join(".huskies/work/5_done");
|
||||||
|
std::fs::create_dir_all(¤t).unwrap();
|
||||||
|
std::fs::create_dir_all(&done).unwrap();
|
||||||
|
std::fs::write(done.join("477_story_a.md"), "---\nname: A\n---\n").unwrap();
|
||||||
|
std::fs::write(done.join("478_story_b.md"), "---\nname: B\n---\n").unwrap();
|
||||||
|
std::fs::write(
|
||||||
|
current.join("10_story_foo.md"),
|
||||||
|
"---\nname: Foo\ndepends_on: [477, 478]\n---\n",
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
let unmet = check_unmet_deps(tmp.path(), "2_current", "10_story_foo");
|
||||||
|
assert!(unmet.is_empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn dep_is_done_finds_story_in_archived() {
|
||||||
|
let tmp = tempfile::tempdir().unwrap();
|
||||||
|
let archived = tmp.path().join(".huskies/work/6_archived");
|
||||||
|
std::fs::create_dir_all(&archived).unwrap();
|
||||||
|
std::fs::write(archived.join("100_story_old.md"), "---\nname: Old\n---\n").unwrap();
|
||||||
|
assert!(dep_is_done(tmp.path(), 100));
|
||||||
|
assert!(!dep_is_done(tmp.path(), 101));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn write_rejection_notes_appends_section() {
|
fn write_rejection_notes_appends_section() {
|
||||||
let tmp = tempfile::tempdir().unwrap();
|
let tmp = tempfile::tempdir().unwrap();
|
||||||
|
|||||||
Reference in New Issue
Block a user