Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

test(config-sync): pin the report interval and the capture pair

vastsa0fb373daebe5
diff --git a/crates/host-core/src/config_sync/engine.rs b/crates/host-core/src/config_sync/engine.rs
index e25a21fab..6628e8870 100644
--- a/crates/host-core/src/config_sync/engine.rs
+++ b/crates/host-core/src/config_sync/engine.rs
@@ -1284,6 +1284,16 @@ mod tests {
.find(|progress| progress.phase == phase)
.copied()
}
+
+ fn all(&self, phase: SyncPhase) -> Vec<SyncProgress> {
+ self.0
+ .lock()
+ .unwrap_or_else(|error| error.into_inner())
+ .iter()
+ .filter(|progress| progress.phase == phase)
+ .copied()
+ .collect()
+ }
}
#[tokio::test]
@@ -1399,6 +1409,17 @@ mod tests {
let progress = RecordedProgress::default();
coordinator::sync_once(&device_a, &tx, &progress).await?;
let initial_a_state = get_state(device_a.clone()).await?;
+ let captures = progress.all(SyncPhase::Capture);
+ assert_eq!(
+ captures.len(),
+ 2,
+ "capture reports that it started and what it collected: {captures:?}"
+ );
+ assert_eq!(captures[0], SyncProgress::started(SyncPhase::Capture));
+ assert!(
+ captures[1].total > 0,
+ "capture counts what it collected: {captures:?}"
+ );
let phases = progress.phases();
assert_eq!(
phases.first(),
diff --git a/crates/host-core/src/config_sync/progress.rs b/crates/host-core/src/config_sync/progress.rs
index b039efa23..99611f4c1 100644
--- a/crates/host-core/src/config_sync/progress.rs
+++ b/crates/host-core/src/config_sync/progress.rs
@@ -204,6 +204,23 @@ mod tests {
}
}
+ /// The interval bounds how long a report may sit unsent, so a phase that
+ /// runs for minutes still moves. A larger constant would fail here.
+ #[test]
+ fn a_report_is_never_withheld_longer_than_the_interval() {
+ let (tx, rx) = mpsc::unbounded_channel();
+ let notifier = ProgressNotifier::new(tx);
+ notifier.report(SyncProgress::counted(SyncPhase::Upload, 1, 9, 1024, 9216));
+ std::thread::sleep(Duration::from_millis(250));
+ notifier.report(SyncProgress::counted(SyncPhase::Upload, 2, 9, 2048, 9216));
+ let lines = reports(rx);
+ assert_eq!(
+ lines.len(),
+ 2,
+ "a phase that keeps working keeps reporting: {lines:?}"
+ );
+ assert_eq!(lines[1]["params"]["done"], 2);
+ }
#[test]
fn a_phase_change_always_reports_and_the_rest_is_throttled() {
let (tx, rx) = mpsc::unbounded_channel();