use std::cell::RefCell;
use newt_core::interaction_surface::SurfaceInteraction;
use newt_core::HumanQuestionOutcome;
struct AskSpy {
seen: RefCell<Vec<SurfaceInteraction>>,
}
impl AskSpy {
fn new() -> Self {
Self {
seen: RefCell::new(Vec::new()),
}
}
fn ask(&self, interaction: &SurfaceInteraction) -> HumanQuestionOutcome {
self.seen.borrow_mut().push(interaction.clone());
HumanQuestionOutcome::Cancelled
}
}
#[test]
fn a_settings_form_question_goes_to_the_injected_seam() {
let spy = AskSpy::new();
let ask = |interaction: &SurfaceInteraction| spy.ask(interaction);
let alive = super::dispatch_slash_with_ask("/settings", "/ws", false, false, false, Some(&ask))
.expect("dispatch succeeds");
assert!(alive, "a cancelled form keeps the session alive");
let seen = spy.seen.borrow();
assert_eq!(seen.len(), 1, "the field menu was asked exactly once");
assert!(
seen[0].is_blocking(),
"a form question blocks the session until answered"
);
}
#[test]
fn a_settings_deep_link_asks_through_the_same_seam() {
let spy = AskSpy::new();
let ask = |interaction: &SurfaceInteraction| spy.ask(interaction);
super::dispatch_slash_with_ask("/settings tenacity", "/ws", false, false, false, Some(&ask))
.expect("dispatch succeeds");
assert_eq!(
spy.seen.borrow().len(),
1,
"the value question went through the seam"
);
}
#[test]
fn the_fallback_ask_exists_for_terminal_owning_callers() {
let fallback: super::SlashAsk<'_> = &super::ask_on_this_terminal;
let _ = fallback;
}
#[test]
fn the_session_slash_call_site_passes_its_surface_seam() {
let chat = include_str!("../chat.rs").replace([' ', '\n'], "");
assert!(
chat.contains("dispatch_slash_with_ask(task,workspace,color,verbose,")
&& chat.contains("Some(&ask_surface),"),
"chat.rs must dispatch slash commands with the surface seam wired in"
);
let lib = include_str!("../lib.rs");
let arm = lib
.split("\"settings\" => {")
.nth(1)
.expect("the /settings dispatch arm exists");
let arm = &arm[..arm.find("\"crew\" =>").expect("the arm ends at /crew")];
assert!(
!arm.contains("suspend_for_prompt"),
"the /settings arm must ask through the seam, not its own terminal: {arm}"
);
}
#[test]
fn the_crew_form_asks_through_a_seam_rather_than_its_own_terminal() {
let form = include_str!("../crew_form/mod.rs");
assert!(
!form.contains("suspend_for_prompt"),
"crew_form must not acquire a prompt window of its own"
);
assert!(
form.contains("pub fn run_edit_with_ask("),
"the seam-taking entry point is what an in-session /crew edit calls"
);
let lib = include_str!("../lib.rs").replace([' ', '\n'], "");
assert!(
lib.contains("commands::crew::dispatch(arg1,arg2,color,verbose,ask.unwrap_or(&fallback))"),
"the /crew arm must forward the session's seam"
);
}
#[test]
fn a_panel_asks_the_surface_for_rows_before_it_draws() {
let chat = include_str!("../chat.rs").replace([' ', '\n'], "");
assert!(
chat.contains(
"letpanel_window=surface.open_panel(PanelMode::Inline(backend_panel::PANEL_HEIGHT));"
),
"the /backend arm must ask its surface for rows"
);
assert!(
chat.contains("backend_chooser::choose(&cfg,panel_window)"),
"the window must reach the chooser, not be dropped on the floor"
);
let panel = include_str!("../backend_panel.rs").replace([' ', '\n'], "");
assert!(
panel.contains("crate::panel::drive(&mutscreen,PANEL_HEIGHT,window.as_ref())"),
"the panel must hand its lent window to the driver"
);
let driver = include_str!("../panel.rs").replace([' ', '\n'], "");
assert!(
driver.contains("Some(window)=>window.terminal()?,")
&& driver.contains("None=>make_terminal(size.requested())?,")
&& driver.contains("letmutsize=ModalSize::new(height);"),
"a lent window wins over the stdout path, and only its absence falls back"
);
}
#[test]
fn psyche_panel_uses_the_surface_window() {
let chat = include_str!("../chat.rs").replace([' ', '\n'], "");
assert!(
chat.contains("surface.open_panel(PanelMode::Inline(config_panel::PANEL_HEIGHT))"),
"/psyche arm must ask its surface for rows before lending them to the panel"
);
assert!(
chat.contains("persist,panel_window,color,verbose,"),
"the window must reach run_psyche_panel, not be dropped on the floor"
);
let panel = include_str!("../config_panel.rs").replace([' ', '\n'], "");
assert!(
panel.contains("crate::panel::drive(&mutscreen,PANEL_HEIGHT,window.as_ref())"),
"config_panel::run must hand its lent window to the driver"
);
}