use super::{chat, child, commit, step, steps};
use crate::rail::build;
#[test]
fn a_card_needs_a_notch_and_a_birth() {
let no_steps = build(
"root",
&[commit("aaaa1111", 10)],
&steps(vec![]),
&chat(0),
&[child("mole", vec![commit("ffff9999", 20)])],
);
assert!(no_steps.cards.is_empty());
let no_commits = build(
"root",
&[commit("aaaa1111", 10)],
&steps(vec![step("001", Some("aaaa1111"), 0)]),
&chat(1),
&[child("mole", vec![])],
);
assert!(no_commits.cards.is_empty());
}
#[test]
fn a_notch_commit_off_the_branch_anchors_nothing() {
let rail = build(
"storeroom",
&[commit("aaaa1111", 10)],
&steps(vec![
step("001", Some("aaaa1111"), 0),
step("002", Some("9999zzzz"), 0),
]),
&chat(2),
&[child(
"hare",
vec![commit("aaaa1111", 10), commit("cccc3333", 30)],
)],
);
let card = rail.cards.first().expect("the fork has a card");
assert_eq!(card.provenance_notch, 0);
}
#[test]
fn the_card_tail_is_the_last_lines_of_in_flight_text() {
let base = || {
vec![
step("001", Some("aaaa1111"), 0),
step("002", Some("bbbb2222"), 0),
]
};
let parent = || vec![commit("aaaa1111", 10), commit("bbbb2222", 20)];
let mut talking = child("mole", vec![commit("ffff9999", 25)]);
talking.streaming_text = Some("one\n\ntwo\nthree\n".to_owned());
let rail = build("storeroom", &parent(), &steps(base()), &chat(0), &[talking]);
assert_eq!(
rail.cards.first().and_then(|c| c.tail.clone()),
Some("two three".to_owned())
);
let mut blank = child("mole", vec![commit("ffff9999", 25)]);
blank.streaming_text = Some(" \n\n".to_owned());
let quiet = build("storeroom", &parent(), &steps(base()), &chat(0), &[blank]);
assert_eq!(quiet.cards.first().and_then(|c| c.tail.clone()), None);
let mut long = child("mole", vec![commit("ffff9999", 25)]);
long.streaming_text = Some("x".repeat(400));
let clipped = build("storeroom", &parent(), &steps(base()), &chat(0), &[long]);
assert_eq!(
clipped
.cards
.first()
.and_then(|c| c.tail.as_ref())
.map(|t| t.chars().count()),
Some(140)
);
}
#[test]
fn the_card_carries_the_childs_own_id_and_spend() {
let mut spent = child("mole", vec![commit("ffff9999", 25)]);
spent.tokens = 4242;
let rail = build(
"storeroom",
&[commit("aaaa1111", 10), commit("bbbb2222", 20)],
&steps(vec![
step("001", Some("aaaa1111"), 0),
step("002", Some("bbbb2222"), 0),
]),
&chat(2),
&[spent],
);
let card = rail.cards.first().expect("a card");
assert_eq!(card.agent_id, "root-mole");
assert_eq!(card.name, "mole");
assert_eq!(card.tokens, 4242);
}
#[test]
fn a_procedure_childs_card_names_its_binding_its_role_and_what_it_landed() {
let mut titler = child("titler", vec![commit("ffff9999", 25)]);
titler.procedure = Some("user_message".into());
titler.role = Some("titler".into());
let mut landing = commit("cccc3333", 30);
landing.subject = "landing: title [root-titler]".into();
let rail = build(
"storeroom",
&[commit("aaaa1111", 10), commit("bbbb2222", 20), landing],
&steps(vec![
step("001", Some("aaaa1111"), 0),
step("002", Some("bbbb2222"), 0),
]),
&chat(2),
&[titler, child("mole", vec![commit("eeee8888", 26)])],
);
let [run, sub] = rail.cards.as_slice() else {
panic!("two cards: {:?}", rail.cards);
};
assert_eq!(run.procedure.as_deref(), Some("user_message"));
assert_eq!(run.role.as_deref(), Some("titler"));
assert_eq!(run.landed.as_deref(), Some("title"));
assert_eq!(
(
sub.procedure.as_deref(),
sub.role.as_deref(),
sub.landed.as_deref()
),
(None, None, None)
);
}