use super::{acked, agent, nothing};
use crate::attention::*;
use crate::git_tree::AgentState;
use crate::ui_state::SeenKind;
const AUTH_SHAPED: &str = r#"{"type":"error","status":401,"message":"Unauthorized"}"#;
#[test]
fn a_raised_flag_is_attention_and_its_stamp_is_the_watermark() {
let mut ag = agent("a");
ag.flagged = Some(crate::monitor::Flag {
at: "7".into(),
reason: "please look at this one".into(),
});
let att = attention(&ag, &[], "ws", ¬hing);
assert!(att.flagged && att.any());
assert_eq!(att.kinds(), vec![AttentionKind::Flagged]);
assert_eq!(
evidence(&ag),
vec![(SeenKind::Flag, "7".to_string())],
"the raising row's stamp is what an acknowledgement records"
);
assert!(!attention(&ag, &[], "ws", &acked(SeenKind::Flag, "7")).flagged);
ag.flagged = Some(crate::monitor::Flag {
at: "8".into(),
reason: "and again".into(),
});
assert!(attention(&ag, &[], "ws", &acked(SeenKind::Flag, "7")).flagged);
assert!(attention(&ag, &[], "ws", &acked(SeenKind::Stopped, "8")).flagged);
}
#[test]
fn the_flagged_word_says_a_human_should_look() {
let said = AttentionKind::Flagged.says();
assert!(said.contains("flagged"), "{said}");
assert!(said.contains("reason"), "{said}");
}
#[test]
fn a_refused_rest_earns_the_refused_word_and_not_stoppeds() {
let mut ag = agent("a");
ag.state = AgentState::Stopped;
let mine = attention(&ag, &[], "ws", ¬hing);
assert_eq!(mine.kinds(), vec![AttentionKind::Stopped]);
ag.failure = Some(AUTH_SHAPED.to_owned());
let theirs = attention(&ag, &[], "ws", ¬hing);
assert_eq!(theirs.kinds(), vec![AttentionKind::Refused]);
assert_eq!(mine.any(), theirs.any());
assert!(theirs.stopped, "it is still rule 2 that fired");
}
#[test]
fn the_refused_word_names_the_act() {
let said = AttentionKind::Refused.says();
assert!(said.contains("refused at the provider"), "{said}");
assert!(said.contains("sign a provider in"), "{said}");
}
#[test]
fn an_acked_refused_rest_still_stirs_nothing() {
let mut ag = agent("a");
ag.state = AgentState::Stopped;
ag.failure = Some(AUTH_SHAPED.to_owned());
assert!(
attention(&ag, &[], "ws", &acked(SeenKind::Stopped, "tip-a"))
.kinds()
.is_empty()
);
}
#[test]
fn a_wounded_rest_does_not_say_it_came_to_rest() {
let clean = crate::attention::row_says(&[AttentionKind::Stopped], AgentState::Quiescent);
let wounded = crate::attention::row_says(&[AttentionKind::Stopped], AgentState::Stopped);
assert_eq!(clean, "came to rest — your turn");
assert_eq!(wounded, "stopped without finishing — your turn");
for state in [AgentState::Quiescent, AgentState::Stopped] {
assert_eq!(
crate::attention::row_says(&[AttentionKind::Mail], state),
AttentionKind::Mail.says()
);
}
assert_eq!(
crate::attention::row_says(
&[AttentionKind::Stopped, AttentionKind::Held],
AgentState::Stopped
),
format!(
"stopped without finishing — your turn; {}",
AttentionKind::Held.says()
)
);
}
#[test]
fn the_held_word_names_the_verb_that_releases_it() {
let said = AttentionKind::Held.says();
assert!(said.contains("/answer"), "{said}");
assert!(said.contains("pass"), "{said}");
assert!(said.contains("refuse"), "{said}");
assert!(!said.contains("bash"), "{said}");
}
#[test]
fn a_truncated_rest_earns_the_truncated_word_and_not_stoppeds() {
let mut ag = agent("a");
ag.state = AgentState::Stopped;
assert_eq!(
attention(&ag, &[], "ws", ¬hing).kinds(),
vec![AttentionKind::Stopped]
);
ag.truncated = true;
let cut = attention(&ag, &[], "ws", ¬hing);
assert_eq!(cut.kinds(), vec![AttentionKind::Truncated]);
assert!(cut.stopped, "it is still rule 2 that fired");
ag.failure = Some(AUTH_SHAPED.to_owned());
assert_eq!(
attention(&ag, &[], "ws", ¬hing).kinds(),
vec![AttentionKind::Refused]
);
}
#[test]
fn the_truncated_word_names_the_remedy_and_says_nothing_landed() {
let said = AttentionKind::Truncated.says();
assert!(said.contains("cut off at its output cap"), "{said}");
assert!(said.contains("nothing was committed"), "{said}");
assert!(said.contains("max_output_tokens"), "{said}");
}