use std::time::Duration; use app_feeder_distributor::control::runtime::{ControlRuntimeStore, UnitRuntimeState}; use uuid::Uuid; #[tokio::test] async fn runtime_store_exposes_shared_runtime_surface() { let unit_id = Uuid::new_v4(); let store = ControlRuntimeStore::new(); let initial = store.get_or_init(unit_id).await; assert_eq!(initial.unit_id, unit_id); assert_eq!(initial.state, UnitRuntimeState::Stopped); assert!(!initial.auto_enabled); assert_eq!( serde_json::to_string(&UnitRuntimeState::Stopped).unwrap(), "\"stopped\"" ); let notify = store.get_or_create_notify(unit_id).await; let waiter = tokio::spawn(async move { tokio::time::timeout(Duration::from_millis(50), notify.notified()).await }); let mut updated = initial.clone(); updated.auto_enabled = true; updated.state = UnitRuntimeState::Running; store.upsert(updated.clone()).await; store.notify_unit(unit_id).await; let notified = waiter.await.unwrap(); assert!(notified.is_ok(), "unit notifier should wake waiters"); let persisted = store.get(unit_id).await.expect("runtime should exist"); assert_eq!(persisted.state, UnitRuntimeState::Running); assert!(persisted.auto_enabled); }