fix(gui): a failed start can be tried again, and a close that was not whole stays on screen

The window retries a failed server start when the next tab opens or when the
person asks, says a server still starting is starting, tells the person which
wanted companies did not open, and when the close reports an incomplete last
backup or a bad exit it stays up with a Close anyway button. ViewerOwner only
forwards to AppHost now, and the format upgrade goes to the window's own server.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Fable 5.2 committed 2026-11-21 09:21:20 -07:00
1 parent acc17a7703
commit 9f3f292bf5
5 files changed
+417 -80

No files matched your search

+188 -6
View File
@@ -23,6 +23,12 @@
//! until the owner's close has returned; the owner is asked to close
//! once, however many times it is asked.
//! 6. A window with no owner that hosts a server asks nothing of any.
//! 7. A start that failed is tried again by the next tab that opens, or
//! by the person (`retry`); one still going is said to be starting.
//! 8. A company wanted at the start that the server did not open is a
//! notice, and its tab asks again when it opens.
//! 9. A close that says something was not whole keeps the window up,
//! showing it, until the person closes anyway.
//! ```
use egui_kittest::Harness;
@@ -109,6 +115,10 @@ struct Fake {
stop_says: Mutex<Option<String>>,
/// Why the server is gone, once it is.
exited: Mutex<Option<String>>,
/// How long starting takes.
start_takes: Mutex<Duration>,
/// The wanted companies the server did not open, and why.
not_open_says: Mutex<Vec<(String, String)>>,
}
impl Fake {
@@ -131,11 +141,15 @@ impl Owner for Fake {
}
fn serve_start(&self, open: &[String]) -> Result<(), String> {
self.note(format!("start {}", open.join(",")));
std::thread::sleep(*self.start_takes.lock().unwrap());
match self.start_says.lock().unwrap().clone() {
Some(why) => Err(why),
None => Ok(()),
}
}
fn serve_not_open(&self, _wanted: &[String]) -> Vec<(String, String)> {
std::mem::take(&mut *self.not_open_says.lock().unwrap())
}
fn serve_open(&self, book: &str) -> Result<Option<String>, String> {
self.note(format!("open {book}"));
match self.open_says.lock().unwrap().remove(book) {
@@ -329,7 +343,13 @@ fn a_refused_start_is_said_and_nothing_is_asked_of_the_server() {
app.open(&ctx, w.source("gamma"));
app.close(tab_of(&app, "alpha"));
a_while();
assert_eq!(owner.said(), vec!["start alpha".to_string()]);
// The next tab is a new try at the start (INVARIANT 7), which fails
// the same way; no company is asked to open or close in a server that
// isn't there.
assert_eq!(
owner.said(),
vec!["start alpha".to_string(), "start alpha,gamma".to_string()]
);
drop(app);
}
@@ -423,12 +443,12 @@ fn a_server_that_will_not_exit_is_left_closing_and_the_window_closes() {
until("started", || !owner.said().is_empty());
serving.begin_stop();
until("the close returned", || serving.is_closed());
// The wait ended with the owner's word; the window can close, and the
// person is told what is left.
let notices = serving.take_notices();
// The wait ended with the owner's word; the person is told what is
// left (the close's report, which the window shows, `close_report`).
let report = serving.close_report();
assert!(
notices.iter().any(|n| n.contains("still closing")),
"{notices:?}"
report.iter().any(|n| n.contains("still closing")),
"{report:?}"
);
drop(serving);
drop(w);
@@ -490,3 +510,165 @@ fn a_window_with_no_server_asks_nothing_of_any() {
);
assert!(!app.serving().is_on());
}
#[test]
fn a_failed_start_is_tried_again_when_the_next_tab_opens() {
let w = World::new(&["alpha", "gamma"]);
let owner = Fake::new();
*owner.start_says.lock().unwrap() = Some("Another program has these books open".into());
let ctx = egui::Context::default();
let mut app = w.start(&["alpha"], &owner);
until("the refusal is said", || {
app.notices()
.iter()
.any(|n| n.contains("Another program has these books open"))
});
until("the start is over", || !app.serving().is_starting());
assert!(app.serving().is_down(), "the window offers to try again");
// Whatever held the books has let go: the next tab is the next try.
*owner.start_says.lock().unwrap() = None;
app.open(&ctx, w.source("gamma"));
until("started again", || owner.said().len() == 2);
until("up", || !app.serving().is_starting());
a_while();
// The new start has every company wanted, so none is asked for twice.
assert_eq!(
owner.said(),
vec!["start alpha".to_string(), "start alpha,gamma".to_string()]
);
assert!(!app.serving().is_down());
// And it is up: a tab closing is asked of the server now.
app.close(tab_of(&app, "gamma"));
until("gamma closed", || {
owner.said().contains(&"close gamma".to_string())
});
drop(app);
}
#[test]
fn the_person_can_try_a_failed_start_again() {
let owner = Fake::new();
*owner.start_says.lock().unwrap() = Some("the books server stopped (exit status: 1)".into());
let serving = Serving::start(Some(owner.clone() as Arc<dyn Owner>), vec!["alpha".into()]);
until("down", || serving.is_down());
assert!(serving.retry(), "asked again, it starts again");
until("settled", || !serving.is_starting());
assert!(serving.is_down(), "failed again: it can be tried again");
*owner.start_says.lock().unwrap() = None;
assert!(serving.retry());
until("up", || !serving.is_starting() && !serving.is_down());
assert!(!serving.retry(), "a server that is up is not started again");
assert_eq!(
owner
.said()
.iter()
.filter(|s| s.starts_with("start"))
.count(),
3
);
let notices = serving.take_notices();
assert_eq!(notices.len(), 2, "each failure said once: {notices:?}");
}
#[test]
fn a_server_still_starting_is_said_to_be_starting() {
let owner = Fake::new();
*owner.start_takes.lock().unwrap() = Duration::from_millis(600);
let serving = Serving::start(Some(owner.clone() as Arc<dyn Owner>), vec!["alpha".into()]);
assert!(serving.is_starting());
assert!(!serving.is_down(), "waited for, not given up on");
until("up", || !serving.is_starting());
assert!(!serving.is_down());
assert!(serving.take_notices().is_empty());
}
#[test]
fn a_company_that_did_not_open_at_the_start_is_said_and_asked_for_again() {
let w = World::new(&["alpha", "beta"]);
let owner = Fake::new();
*owner.not_open_says.lock().unwrap() = vec![(
"beta".into(),
"beta couldn't be opened for your assistants: a damaged line.".into(),
)];
// The tabs are opened (and wanted) before the server says ready.
*owner.start_takes.lock().unwrap() = Duration::from_millis(300);
let ctx = egui::Context::default();
let mut app = w.start(&["alpha", "beta"], &owner);
until("the failed open is said", || {
app.notices().iter().any(|n| n.contains("a damaged line"))
});
assert!(!app.serving().wants("beta"), "not open in the server");
assert!(app.serving().wants("alpha"));
// Its tab closed and opened again asks the server again.
app.close(tab_of(&app, "beta"));
a_while();
assert!(
!owner.said().contains(&"close beta".to_string()),
"nothing to close: it was never open: {:?}",
owner.said()
);
app.open(&ctx, w.source("beta"));
until("beta asked for", || {
owner.said().contains(&"open beta".to_string())
});
drop(app);
}
#[test]
fn a_close_that_was_not_whole_keeps_the_window_up_until_the_person_closes_anyway() {
let w = World::new(&["alpha"]);
let owner = Fake::new();
*owner.stop_says.lock().unwrap() = Some(
"alpha is closed to your assistants, but its last backup wasn't whole: the folder is gone\nThe books server ended badly (exit status: 1)."
.into(),
);
let kept = w.kept(&["alpha"]);
let (root, fallback) = (w.root.clone(), w.source("alpha"));
let for_app: Arc<dyn Owner> = owner.clone();
let mut h = Harness::builder()
.with_size(egui::vec2(1000.0, 700.0))
.build_eframe(move |cc| {
App::start_with_owner(
&cc.egui_ctx,
&|k| kept.get(k).cloned(),
Start::Restore { root, fallback },
Some(for_app),
)
});
h.run_steps(3);
let ask_to_close = |h: &mut Harness<'_, App>| {
h.input_mut()
.viewports
.entry(egui::ViewportId::ROOT)
.or_default()
.events
.push(egui::ViewportEvent::Close);
h.run_steps(2);
};
ask_to_close(&mut h);
until("the close is done", || h.state().serving().is_closed());
h.run_steps(3);
// The close is over, and the window says what was not whole.
assert!(h.query_by_label_contains("did not close cleanly").is_some());
assert!(
h.query_by_label_contains("last backup wasn't whole")
.is_some()
);
assert!(h.query_by_label_contains("ended badly").is_some());
assert_eq!(h.state().serving().close_report().len(), 2);
// Asked to close again, it is not "close anyway": still up, still said.
ask_to_close(&mut h);
h.run_steps(2);
assert!(h.query_by_label_contains("did not close cleanly").is_some());
assert_eq!(h.state().serving().close_report().len(), 2);
// The button is.
h.get_by_label("Close anyway").click();
h.run_steps(3);
assert!(h.state().serving().close_report().is_empty());
assert_eq!(
owner.said().iter().filter(|s| *s == "stop").count(),
1,
"the owner closed the server once: {:?}",
owner.said()
);
}