use super::super::hold::{Ending, hold};
use super::super::redial::redial;
use super::{advertised, aside, echo, entry_at, set};
use crate::channel::Channel;
use crate::channel::material::read_dir;
use crate::test_support::engine::Engine;
use crate::test_support::{Notices, Scratch, Waits, mint};
fn ahead(dir: &std::path::Path, dials: usize) -> Engine {
mint::material(dir);
Engine::start(
dir,
crate::corpus::PROTOCOL + 1,
vec![vec![advertised()]; dials],
)
}
#[test]
fn a_version_the_two_ends_do_not_share_is_over_and_not_the_wire() {
let scratch = Scratch::new();
let _engine = ahead(scratch.path(), 1);
let held = read_dir(scratch.path())
.expect("readable")
.expect("provisioned");
let mut channel = Channel::open(&held).expect("opened");
let Ending::Over(said) = hold(&mut channel, &set(), echo, &aside(), None) else {
panic!("a version this foot cannot speak is not worth another dial");
};
assert!(
said.contains(&format!(
"the engine speaks {}",
crate::corpus::PROTOCOL + 1
)),
"{said}"
);
assert!(said.contains("upgrade the older component"), "{said}");
}
#[test]
fn it_is_neither_waited_out_nor_dialled_again() {
let scratch = Scratch::new();
let _engine = ahead(scratch.path(), 2);
let (waits, pause) = Waits::new();
let (notices, sink) = Notices::new();
let said = redial(entry_at(scratch.path()).open(), &set(), echo, &sink, &pause);
assert!(said.contains("upgrade the older component"), "{said}");
assert_eq!(waits.heard(), [], "it waited to dial an engine again");
assert!(
!said.contains("Dialling this engine again"),
"a fact only a new binary can change is not something to wait on: {said}"
);
assert!(
!said.contains(".."),
"the redial suffix used to append a second full stop: {said}"
);
assert!(notices.heard().is_empty(), "nothing said in flight");
}