mod common;
use common::Sandbox;
fn how_many(vivacs: &str, kind: &str) -> usize {
vivacs.lines().filter(|l| l.contains(kind)).count()
}
#[test]
fn one_stop_per_turn_does_not_leave_one_stop_per_turn() {
let c = Sandbox::new_seeded("turns");
c.ok(&["push", "A goal", "--why", "it is needed"]);
for _ in 0..5 {
c.ok(&["session", "end", "--hook"]);
}
let v = c.ok(&["vivacs"]);
assert_eq!(how_many(&v, "auto"), 1, "one stop per turn:\n{v}");
}
#[test]
fn a_new_stop_once_something_changed() {
let c = Sandbox::new_seeded("change");
c.ok(&["push", "A goal", "--why", "it is needed"]);
c.ok(&["session", "end", "--hook"]);
c.ok(&["note", "1", "something happened"]);
c.ok(&["session", "end", "--hook"]);
let v = c.ok(&["vivacs"]);
assert_eq!(how_many(&v, "auto"), 2, "it swallowed the good stop:\n{v}");
}
#[test]
fn no_stack_no_stop() {
let c = Sandbox::new_seeded("nostack");
c.ok(&["session", "end", "--hook"]);
let v = c.ok(&["vivacs"]);
assert_eq!(how_many(&v, "auto"), 0, "it invented an empty stop:\n{v}");
}
#[test]
fn the_start_hook_travels_in_its_envelope() {
let c = Sandbox::new_seeded("envelope");
c.ok(&["push", "A goal", "--why", "it is needed"]);
let s = c.ok(&["session", "start", "--hook"]);
assert_eq!(s.lines().filter(|l| !l.trim().is_empty()).count(), 1);
assert!(s.contains("hookSpecificOutput"), "{s}");
assert!(s.contains("SessionStart"), "{s}");
assert!(s.contains("additionalContext"), "{s}");
assert!(s.contains("A goal"), "the envelope went out empty:\n{s}");
}
#[test]
fn they_stay_quiet_where_there_is_no_tree() {
let c = Sandbox::new_empty("notree");
for args in [["session", "start", "--hook"], ["session", "end", "--hook"]] {
let (s, code) = c.run(&args);
assert_eq!(code, 0, "{args:?} failed outside a tree:\n{s}");
assert_eq!(s.trim(), "", "{args:?} said too much:\n{s}");
}
}