use pretty_assertions::assert_eq;
use rho_protocol as wire;
use super::replay;
use crate::{
app::daemon_host::jobs::{JobState, TurnEnd},
run_artifacts::AttachmentEvent,
subagent::{RunState, RunStatus},
};
use rho_protocol::display::{ToolCard, ToolCardStatus, ToolFamily, ToolHeader};
#[test]
fn a_replayed_run_ends_as_its_job_or_status_did() {
let ended = |state: RunState, job: Option<TurnEnd>| {
let status = RunStatus {
state,
..RunStatus::default()
};
replay(&status, &[], wire::PermissionMode::Bypass, job)
.attach(crate::app::daemon_host::sessions::feed::ResumeFrom::default())
.job
};
let shown = |end: TurnEnd| wire::JobState::from(&JobState::Ended(end));
assert_eq!(
[
ended(RunState::Ok, None),
ended(RunState::Stopped, None),
ended(RunState::Running, None),
ended(RunState::Stopped, Some(TurnEnd::Interrupted)),
],
[
shown(TurnEnd::Completed),
shown(TurnEnd::Cancelled),
shown(TurnEnd::Interrupted),
shown(TurnEnd::Interrupted),
]
);
}
#[test]
fn a_replay_closes_the_calls_a_cut_off_journal_left_running() {
let calls = |end: Option<AttachmentEvent>| {
let status = RunStatus {
state: RunState::Running,
..RunStatus::default()
};
let card = ToolCard::new(
ToolCardStatus::Running,
ToolFamily::FileCommand,
ToolHeader::shell("$", Some("cargo test".into())),
);
let events: Vec<_> = [
AttachmentEvent::Prompt("Run the tests.".into()),
AttachmentEvent::ToolStarted {
key: Some("call-1".into()),
card,
},
]
.into_iter()
.chain(end)
.collect();
replay(
&status,
&events,
wire::PermissionMode::Bypass,
None,
)
.buffered_for_tests()
.into_iter()
.filter_map(|event| match event {
wire::SessionEvent::ToolCall(update) => update.status,
_ => None,
})
.collect::<Vec<_>>()
};
assert_eq!(
[calls( None), calls(Some(AttachmentEvent::Completed))],
[
vec![wire::ToolStatus::InProgress, wire::ToolStatus::Cancelled],
vec![wire::ToolStatus::InProgress, wire::ToolStatus::Completed],
]
);
}
#[test]
fn a_replayed_journal_shows_no_terminal_of_a_served_process() {
let status = RunStatus {
state: RunState::Ok,
..RunStatus::default()
};
let card = ToolCard::new(
ToolCardStatus::Running,
ToolFamily::FileCommand,
ToolHeader::shell("$", Some("cargo test".into())),
);
let started = wire::ToolContent::Text {
text: "process_id: p1".into(),
};
let events = [
AttachmentEvent::ToolStarted {
key: Some("call-1".into()),
card,
},
AttachmentEvent::ToolContent {
key: "call-1".into(),
content: vec![
started.clone(),
wire::ToolContent::Terminal {
process: "p1".into(),
},
],
},
];
let shown: Vec<_> = replay(
&status,
&events,
wire::PermissionMode::Bypass,
None,
)
.buffered_for_tests()
.into_iter()
.filter_map(|event| match event {
wire::SessionEvent::ToolCall(update) => update.content.clone(),
_ => None,
})
.collect();
assert_eq!(shown, vec![vec![started]]);
}
#[test]
fn a_replayed_journal_shows_a_steer_as_a_plain_user_message() {
let content = vec![wire::ContentBlock::Text {
text: "go left".into(),
}];
let events = [AttachmentEvent::Steered {
steer: wire::SteerId::new("acp-steer-1"),
content: content.clone(),
}];
let shown: Vec<_> = replay(
&RunStatus::default(),
&events,
wire::PermissionMode::Bypass,
None,
)
.buffered_for_tests()
.into_iter()
.filter_map(|event| match event {
wire::SessionEvent::UserMessage { content, steer, .. } => Some((content.clone(), steer)),
_ => None,
})
.collect();
assert_eq!(shown, vec![(content, None)]);
}