use super::set_titles_support::{
delivered_titles, new_detached_session, remembered_title, set_global, title_capable_context,
};
use super::*;
async fn open_mode_tree(handler: &RequestHandler, attach_pid: u32) {
let commands = handler
.parse_control_commands("choose-tree -Zs")
.await
.expect("choose-tree parses");
handler
.execute_parsed_commands_for_test(attach_pid, commands)
.await
.expect("choose-tree activates");
assert!(
handler.mode_tree_active(attach_pid).await,
"the fixture needs an active mode-tree overlay"
);
}
async fn dismiss_mode_tree_and_refresh(handler: &RequestHandler, attach_pid: u32) {
let refreshed = handler
.dismiss_mode_tree(attach_pid)
.await
.expect("mode tree dismissal succeeds");
for session_name in refreshed {
handler.refresh_attached_session(&session_name).await;
}
}
#[tokio::test]
async fn a_title_discarded_by_an_overlay_barrier_reaches_the_successor_refresh() {
let handler = RequestHandler::new();
let alpha = session_name("alpha");
new_detached_session(&handler, &alpha).await;
let attach_pid = std::process::id();
let (control_tx, mut control_rx) = mpsc::unbounded_channel();
let _attach_id = handler
.register_attach_with_terminal_context(
attach_pid,
alpha.clone(),
control_tx,
title_capable_context(),
)
.await;
set_global(&handler, OptionName::SetTitlesString, "BEFORE").await;
set_global(&handler, OptionName::SetTitles, "on").await;
assert_eq!(
delivered_titles(&mut control_rx),
vec!["BEFORE".to_owned()],
"the client starts from a known delivered title"
);
open_mode_tree(&handler, attach_pid).await;
let _ = delivered_titles(&mut control_rx);
set_global(&handler, OptionName::SetTitlesString, "AFTER").await;
dismiss_mode_tree_and_refresh(&handler, attach_pid).await;
assert_eq!(
delivered_titles(&mut control_rx),
vec!["AFTER".to_owned()],
"the discarded title must be re-emitted by the successor refresh exactly once"
);
assert_eq!(
remembered_title(&handler, attach_pid).await.as_deref(),
Some("AFTER"),
"remembered state must equal what the wire actually carried"
);
}
#[tokio::test]
async fn a_title_surviving_its_overlay_barrier_is_not_re_emitted() {
let handler = RequestHandler::new();
let alpha = session_name("alpha");
new_detached_session(&handler, &alpha).await;
let attach_pid = std::process::id();
let (control_tx, mut control_rx) = mpsc::unbounded_channel();
let _attach_id = handler
.register_attach_with_terminal_context(
attach_pid,
alpha.clone(),
control_tx,
title_capable_context(),
)
.await;
set_global(&handler, OptionName::SetTitlesString, "STABLE").await;
set_global(&handler, OptionName::SetTitles, "on").await;
assert_eq!(delivered_titles(&mut control_rx), vec!["STABLE".to_owned()]);
open_mode_tree(&handler, attach_pid).await;
let _ = delivered_titles(&mut control_rx);
set_global(&handler, OptionName::SetTitlesString, "CHANGED").await;
set_global(&handler, OptionName::StatusInterval, "13").await;
assert_eq!(
delivered_titles(&mut control_rx),
vec!["CHANGED".to_owned()],
"an undiscarded title reaches the wire exactly once"
);
assert_eq!(
remembered_title(&handler, attach_pid).await.as_deref(),
Some("CHANGED"),
);
dismiss_mode_tree_and_refresh(&handler, attach_pid).await;
assert!(
delivered_titles(&mut control_rx).is_empty(),
"a title the terminal already shows must not be rewritten after a barrier"
);
}
#[tokio::test]
async fn an_unstamped_title_is_never_reverted_by_a_barrier() {
let handler = RequestHandler::new();
let alpha = session_name("alpha");
new_detached_session(&handler, &alpha).await;
let attach_pid = std::process::id();
let (control_tx, mut control_rx) = mpsc::unbounded_channel();
let _attach_id = handler
.register_attach_with_terminal_context(
attach_pid,
alpha.clone(),
control_tx,
title_capable_context(),
)
.await;
set_global(&handler, OptionName::SetTitlesString, "PLAIN").await;
set_global(&handler, OptionName::SetTitles, "on").await;
assert_eq!(delivered_titles(&mut control_rx), vec!["PLAIN".to_owned()]);
let refreshed = handler
.dismiss_mode_tree(attach_pid)
.await
.expect("dismissing nothing succeeds");
assert!(refreshed.is_empty());
set_global(&handler, OptionName::StatusInterval, "17").await;
assert!(
delivered_titles(&mut control_rx).is_empty(),
"an unchanged title must stay deduplicated across an unrelated redraw"
);
assert_eq!(
remembered_title(&handler, attach_pid).await.as_deref(),
Some("PLAIN"),
);
}