Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

Merge remote-tracking branch 'upstream/main' into saas-phase6

Steven Enamakel7947abbdea1e
diff --cc crates/openhuman-core/src/user_agents/host_tests.rs
index 804ae527f1,73487ed0f8..5db1a50f2f
--- a/crates/openhuman-core/src/user_agents/host_tests.rs
+++ b/crates/openhuman-core/src/user_agents/host_tests.rs
@@@ -161,26 -161,49 +161,73 @@@ fn a_reprovisioned_agent_does_not_inher
);
}
+#[test]
+fn the_first_open_settles_a_previous_process_once() {
+ let tmp = tempfile::tempdir().unwrap();
+ let host = host(&tmp, 4, 0);
+ let id = agent(&format!("recover-{}", uuid::Uuid::new_v4()));
+ host.provision(&id).unwrap();
+ drop(host.open(&id).unwrap());
+ assert!(host.recovered.lock().unwrap().contains(&id));
+ host.evict_idle();
+ drop(host.open(&id).unwrap());
+ assert_eq!(
+ host.recovered.lock().unwrap().len(),
+ 1,
+ "a re-open after eviction does not sweep again"
+ );
+}
+
+#[test]
+fn recovery_of_an_empty_workspace_is_a_no_op() {
+ let tmp = tempfile::tempdir().unwrap();
+ let id = agent("empty");
+ recover_workspace(&id, tmp.path());
+}
++
+ #[test]
+ fn an_agent_in_use_is_not_archived_from_under_it() {
+ let tmp = tempfile::tempdir().unwrap();
+ let host = host(&tmp, 4, 60);
+ let id = agent("alice");
+ host.provision(&id).unwrap();
+ let state = host.open(&id).unwrap();
+ let err = host.deprovision(&id).unwrap_err();
+ assert!(err.contains("in use"), "{err}");
+ assert!(host.is_open(&id), "a refused deprovision leaves it open");
+ drop(state);
+ assert!(host.deprovision(&id).unwrap());
+ assert!(!host.is_open(&id));
+ }
+
+ #[test]
+ fn deprovisioning_twice_in_a_second_archives_twice() {
+ let tmp = tempfile::tempdir().unwrap();
+ let host = host(&tmp, 4, 60);
+ let id = agent("alice");
+ for _ in 0..2 {
+ host.provision(&id).unwrap();
+ assert!(host.deprovision(&id).unwrap());
+ }
+ let archived = std::fs::read_dir(layout::archive_dir(tmp.path()))
+ .unwrap()
+ .count();
+ assert_eq!(archived, 2);
+ }
+
+ #[test]
+ fn opening_an_open_agent_sweeps_the_idle_ones() {
+ let tmp = tempfile::tempdir().unwrap();
+ // Everything is idle the moment it is released.
+ let host = host(&tmp, 4, 0);
+ let (a, b) = (agent("alice"), agent("bob"));
+ host.provision(&a).unwrap();
+ host.provision(&b).unwrap();
+ drop(host.open(&a).unwrap());
+ let held = host.open(&b).unwrap();
+ // Re-opening bob (already open) closes idle alice.
+ let again = host.open(&b).unwrap();
+ assert!(!host.is_open(&a), "alice was idle and is closed");
+ assert!(host.is_open(&b), "bob is in use and stays");
+ drop((held, again));
+ }