use std::path::PathBuf;
use pretty_assertions::assert_eq;
use rho_protocol::{AgentRuntime, ChildInfo, ChildRole, JobId, JobKind, JobState, JobSummary};
use super::delegated_run;
use crate::tui::agent_rail::SubagentAttachTarget;
fn subagent(run: Option<&str>, child: Option<ChildInfo>) -> JobSummary {
JobSummary {
id: JobId::new("job"),
kind: JobKind::Subagent,
state: JobState::Running,
workspace: PathBuf::from("/w"),
parent: Some(JobId::new("parent")),
session: None,
run: run.map(str::to_owned),
workflow_run: None,
result_pending: false,
created_at: 0,
updated_at: 0,
error: None,
queue: None,
live: None,
grant: None,
grant_limit: None,
worktree: None,
worktree_stale: false,
child,
}
}
#[test]
fn only_a_delegated_subagent_opens_its_run() {
let delegated = ChildInfo::new(ChildRole::Delegated).running_as("worker", AgentRuntime::Rho);
let node = ChildInfo::new(ChildRole::WorkflowNode).running_as("worker", AgentRuntime::Rho);
let cases = [
(
"delegated",
subagent(Some("a1b2c3"), Some(delegated.clone())),
Some(SubagentAttachTarget {
run_id: "a1b2c3".into(),
agent_id: "worker".into(),
}),
),
("delegated, no run", subagent(None, Some(delegated)), None),
(
"workflow node",
subagent(Some("workflow:wf1:review:1"), Some(node)),
None,
),
("no child", subagent(Some("a1b2c3"), None), None),
];
for (case, job, want) in cases {
assert_eq!(delegated_run(&job), want, "{case}");
}
}