huskies: merge 484_story_story_dependencies_in_pipeline_auto_assign

This commit is contained in:
dave
2026-04-04 21:43:29 +00:00
parent 26de009259
commit 5413a26406
6 changed files with 665 additions and 3 deletions
+282
View File
@@ -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}");
}
}
+6
View File
@@ -9,6 +9,7 @@ mod ambient;
mod assign;
mod cost;
mod coverage;
mod depends;
mod git;
mod help;
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`",
handler: ambient::handle_ambient,
},
BotCommand {
name: "depends",
description: "Set story dependencies: `depends <number> [dep1 dep2 ...]` (no deps = clear)",
handler: depends::handle_depends,
},
BotCommand {
name: "git",
description: "Show git status: branch, uncommitted changes, and ahead/behind remote",
+87 -2
View File
@@ -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 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()
@@ -207,11 +219,11 @@ pub(super) fn build_pipeline_status(project_root: &std::path::Path, agents: &Age
.and_then(|ac| ac.model.as_deref())
.unwrap_or("?");
out.push_str(&format!(
" {dot}{display}{cost_suffix}{} ({model_str})\n",
" {dot}{display}{cost_suffix}{dep_suffix}{} ({model_str})\n",
agent.agent_name
));
} 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 --------------------------------------------------
// -- build_pipeline_status_html (colored dots) --------------------------