use std::{collections::HashMap, path::PathBuf, time::Duration};
use pretty_assertions::assert_eq;
use rho_protocol::{
AgentRuntime, Ask, ChildInfo, ChildRole, InputAsker, InputRequest, InputRequestId, JobId,
JobKind, JobLive, JobState, JobSummary, ModelRef, SessionId,
};
use super::started_session;
use crate::tui::agent_rail::RailState;
const NOW: u64 = 1_000;
fn job(state: JobState) -> JobSummary {
JobSummary {
id: JobId::new("job"),
kind: JobKind::Session,
state,
workspace: PathBuf::from("/work"),
parent: Some(JobId::new("parent")),
session: Some(SessionId::new("5054a7c5-68a7-4d13-8a3e-0f6d944aa81b")),
run: None,
workflow_run: None,
result_pending: false,
created_at: 0,
updated_at: NOW - 4,
error: None,
queue: None,
live: None,
grant: None,
grant_limit: None,
worktree: None,
worktree_stale: false,
child: Some(ChildInfo::new(ChildRole::Started).running_as("default", AgentRuntime::Rho)),
}
}
fn live(turn_ms: Option<u64>) -> JobLive {
JobLive {
title: Some("Bench the parser".into()),
model: ModelRef {
provider: "xai".into(),
model: "grok-fixture".into(),
},
turn_elapsed_ms: turn_ms,
usage: None,
inputs: Vec::new(),
}
}
#[test]
fn a_started_sessions_row_says_what_its_job_is_doing() {
let asked = JobLive {
inputs: vec![InputRequest {
id: InputRequestId(1),
ask: Ask::Unknown,
tool_call: None,
timeout: None,
asker: InputAsker::Subagent,
subagent: None,
told_starter: false,
}],
..live(Some(9_000))
};
let told = JobLive {
inputs: vec![InputRequest {
id: InputRequestId(2),
ask: Ask::Unknown,
tool_call: None,
timeout: None,
asker: InputAsker::Turn,
subagent: None,
told_starter: true,
}],
..live(Some(7_000))
};
let jobs = [
JobSummary {
live: Some(live(Some(12_000))),
..job(JobState::Running)
},
JobSummary {
live: Some(asked),
..job(JobState::Running)
},
job(JobState::Idle),
job(JobState::Queued),
JobSummary {
child: Some(
ChildInfo::new(ChildRole::Started)
.running_as("claude-cli", AgentRuntime::ClaudeCli),
),
..job(JobState::Failed)
},
job(JobState::Interrupted),
JobSummary {
live: Some(told),
..job(JobState::WaitingForInput)
},
JobSummary {
session: None,
..job(JobState::Running)
},
];
let mut times = HashMap::new();
let rows: Vec<_> = jobs
.iter()
.map(|job| {
started_session(job, &mut times, NOW)
.map(|row| (row.agent, row.title, row.state, row.elapsed))
})
.collect();
let row = |agent: Option<&str>, title: &str, state, secs: Option<u64>| {
Some((
agent.map(str::to_owned),
title.to_owned(),
state,
secs.map(Duration::from_secs),
))
};
assert_eq!(
rows,
[
row(None, "Bench the parser", RailState::Working, Some(12)),
row(None, "Bench the parser", RailState::NeedsInput, Some(9)),
row(None, "session 5054a7c5", RailState::Idle, Some(9)),
row(None, "session 5054a7c5", RailState::Queued, Some(4)),
row(
Some("Claude Code"),
"session 5054a7c5",
RailState::Failed,
Some(9)
),
row(None, "session 5054a7c5", RailState::Stopped, Some(9)),
row(None, "Bench the parser", RailState::AsksParent, Some(7)),
None,
]
);
}