use super::fixture::{fake_lernie, seed_world, world};
use super::screen::{Screen, press};
use crate::start::Prepared;
use crate::test_support::spawn_guard;
use tempfile::tempdir;
#[test]
fn a_raise_focuses_its_sphere_and_opens_no_second_goal_box() {
let bin = tempdir().unwrap();
let mut world = world();
seed_world(&world);
let _g = spawn_guard();
let screen = Screen::with_lernie(fake_lernie(bin.path()));
screen.idle(&mut world);
screen.release(&mut world);
screen.frame(&mut world, vec![press(egui::Key::W, egui::Modifiers::NONE)]);
world.state.new_ws.typed = "ops".to_owned();
screen.frame(
&mut world,
vec![press(egui::Key::Enter, egui::Modifiers::NONE)],
);
assert!(!world.state.new_ws.open, "Enter submitted the name form");
let focused = world
.model
.focused_workspace()
.expect("the raise focused what it raised (§3.4)");
assert!(
focused.ends_with("ops") && focused.join("repo.git").is_dir(),
"and the sphere is really on disk at {}",
focused.display()
);
assert!(
world.state.start.pending.is_none(),
"the raise's contract is focus + the composer — no start draft"
);
let out = screen.text(&mut world);
assert!(
!out.contains("Start goal →"),
"so no second box is painted:\n{out}"
);
assert!(
!out.contains("Send (detached prompt)"),
"and nothing offers to fire an empty goal:\n{out}"
);
assert_eq!(
out.matches("will be named ").count(),
1,
"exactly one name prediction, because there is exactly one goal box:\n{out}"
);
assert!(
out.contains("start a conversation"),
"and that box is the docked composer, aimed at the new sphere:\n{out}"
);
assert!(
screen.idle(&mut world),
"which holds the keyboard: the operator types their goal, no click"
);
}
#[test]
fn enter_on_a_blank_start_draft_fires_nothing_and_keeps_the_draft() {
let mut world = world();
let screen = Screen::new();
screen.idle(&mut world);
screen.release(&mut world);
let ws = world.ws.clone();
world.state.start.pending = Some(Prepared {
name: "ws".to_owned(),
workspace: ws.clone(),
cwd: ws,
goal: " \n\t ".to_owned(),
origin: crate::opslog::Origin::Conversation,
});
screen.frame(
&mut world,
vec![press(egui::Key::Enter, egui::Modifiers::NONE)],
);
world.converge();
assert!(
world.state.start.pending.is_some(),
"a blank goal does not spend the draft — the box stays for the typing"
);
assert!(
world
.model
.last_failure(crate::opslog::Origin::Conversation)
.is_none(),
"and nothing was dispatched: no `lernie prompt` on a blank payload"
);
}