From f2eab5492cda7d993d544cad37c22d1c3ee07657 Mon Sep 17 00:00:00 2001 From: Felix Martin Date: Tue, 26 May 2026 10:40:38 -0400 Subject: [PATCH] Fix persisted review startup --- src/main.rs | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 914542c..bee0124 100644 --- a/src/main.rs +++ b/src/main.rs @@ -173,8 +173,11 @@ impl App { fn new_with_event_log_path(event_log_path: impl AsRef) -> Result { let window_snapshot = window::get_snapshot(); let mut session_controller = SessionController::new(event_log_path)?; - if session_controller.runtime_state() == RuntimeState::Locked { - session_controller.enter_planning()?; + match session_controller.runtime_state() { + RuntimeState::Locked => session_controller.enter_planning()?, + // The rating screen is not durable enough to reconstruct after restart. + RuntimeState::Review => session_controller.return_to_planning_after_review()?, + _ => {} } let active_commitment = session_controller.active_commitment().cloned(); @@ -1642,6 +1645,52 @@ mod tests { let _ = fs::remove_file(path); } + #[test] + fn hydrated_review_session_returns_to_planning_and_can_start_next_commitment() { + let path = unique_event_log_path("hydrated-review-cycle"); + { + let mut app = App::new_with_event_log_path(&path).unwrap(); + app.user_intention = "write tests".to_string(); + app.user_success_condition = "tests pass".to_string(); + app.user_duration_str = "1".to_string(); + app.to_in_progress().unwrap(); + app.to_end().unwrap(); + assert_eq!(app.session_controller.runtime_state(), RuntimeState::Review); + } + + let mut app = App::new_with_event_log_path(&path).unwrap(); + + assert_eq!(app.state, State::InputIntention); + assert_eq!( + app.session_controller.runtime_state(), + RuntimeState::Planning + ); + + app.user_intention = "write next test".to_string(); + app.user_success_condition = "next test passes".to_string(); + app.user_duration_str = "1".to_string(); + app.to_in_progress().unwrap(); + + assert_eq!(app.state, State::InProgress); + assert_eq!(app.session_controller.runtime_state(), RuntimeState::Active); + assert_eq!( + app.session_controller + .active_commitment() + .unwrap() + .next_action, + "write next test" + ); + + let records = EventLog::open(&path).unwrap().records().unwrap(); + assert!(records.iter().any(|record| { + record.event_type == EventType::RuntimeTransition + && record.runtime_state == RuntimeState::Planning + && record.payload_json["action"] == "return_to_planning_after_review" + })); + + let _ = fs::remove_file(path); + } + #[test] fn hydrated_active_session_keeps_elapsed_time() { let path = unique_event_log_path("hydrated-active-timer");