d06241c20c
The mergemaster agent was burning all 30 turns polling get_merge_status every 2 seconds while the merge pipeline takes ~2 minutes. It would exhaust turns, exit, restart, and repeat — never seeing the result. merge_agent_work now blocks with a 10-second internal poll loop and returns the final result directly. The agent calls it once and gets the answer. No more polling turns wasted. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
242 lines
8.0 KiB
Rust
242 lines
8.0 KiB
Rust
//! 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};
|
|
|
|
/// 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 by numeric prefix: CRDT → content store → filesystem.
|
|
let (story_id, _stage_dir, path, content) =
|
|
match crate::chat::lookup::find_story_by_number(ctx.project_root, num_str) {
|
|
Some(found) => found,
|
|
None => {
|
|
return Some(format!(
|
|
"No story, bug, or spike with number **{num_str}** found."
|
|
));
|
|
}
|
|
};
|
|
|
|
let story_name = content
|
|
.or_else(|| 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}");
|
|
}
|
|
}
|