Skip to content

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

test(profiles): await async profile host calls in tests

Steven Enamakelde1468fa2e02
diff --git a/crates/openhuman-core/src/profiles/background_tests.rs b/crates/openhuman-core/src/profiles/background_tests.rs
index 9810762236..055113bc83 100644
--- a/crates/openhuman-core/src/profiles/background_tests.rs
+++ b/crates/openhuman-core/src/profiles/background_tests.rs
@@ -29,7 +29,7 @@ async fn nothing_to_do_does_nothing() {
crate::profiles::ProfileIdMode::Raw,
)
.unwrap();
- host.provision(&id).unwrap();
+ host.provision(&id).await.unwrap();
assert_eq!(tick(&host).await, TickReport::default());
assert!(
!host.is_open(&id),
@@ -51,8 +51,8 @@ async fn only_profiles_with_queued_memory_jobs_are_run() {
crate::profiles::ProfileIdMode::Raw,
)
.unwrap();
- host.provision(&busy).unwrap();
- host.provision(&quiet).unwrap();
+ host.provision(&busy).await.unwrap();
+ host.provision(&quiet).await.unwrap();
let config = profile_config(&host.layout_of(&busy), &busy);
crate::memory::test_fixtures::bind_reference(&config);
@@ -77,8 +77,8 @@ async fn a_tick_sweeps_idle_profiles() {
crate::profiles::ProfileIdMode::Raw,
)
.unwrap();
- host.provision(&id).unwrap();
- drop(host.open(&id).unwrap());
+ host.provision(&id).await.unwrap();
+ drop(host.open(&id).await.unwrap());
assert!(host.is_open(&id));
tick(&host).await;
assert!(!host.is_open(&id));
diff --git a/crates/openhuman-core/src/profiles/host_tests.rs b/crates/openhuman-core/src/profiles/host_tests.rs
index bd7319a7c4..1556f5b034 100644
--- a/crates/openhuman-core/src/profiles/host_tests.rs
+++ b/crates/openhuman-core/src/profiles/host_tests.rs
@@ -11,37 +11,37 @@ fn profile(name: &str) -> ProfileId {
ProfileId::for_user(name, crate::profiles::ProfileIdMode::Raw).unwrap()
}
-#[test]
-fn provisioning_creates_the_layout_once() {
+#[tokio::test]
+async fn provisioning_creates_the_layout_once() {
let tmp = tempfile::tempdir().unwrap();
let host = host(&tmp, 4, 60);
let id = profile("alice");
- assert!(host.provision(&id).unwrap());
- assert!(!host.provision(&id).unwrap(), "second provision is a no-op");
+ assert!(host.provision(&id).await.unwrap());
+ assert!(!host.provision(&id).await.unwrap(), "second provision is a no-op");
let layout = ProfileLayout::new(tmp.path(), &id);
assert!(layout.workspace_dir.is_dir() && layout.sandbox_dir.is_dir());
- let summary = host.summary(&id).unwrap().unwrap();
+ let summary = host.summary(&id).await.unwrap().unwrap();
assert_eq!(summary.profile_id, id);
assert!(!summary.open);
}
-#[test]
-fn only_provisioned_profiles_open() {
+#[tokio::test]
+async fn only_provisioned_profiles_open() {
let tmp = tempfile::tempdir().unwrap();
let host = host(&tmp, 4, 60);
- let err = host.open(&profile("nobody")).unwrap_err();
+ let err = host.open(&profile("nobody")).await.unwrap_err();
assert!(err.contains("not provisioned"), "{err}");
}
-#[test]
-fn an_open_profile_runs_under_its_own_scope() {
+#[tokio::test]
+async fn an_open_profile_runs_under_its_own_scope() {
let tmp = tempfile::tempdir().unwrap();
let host = host(&tmp, 4, 60);
let (a, b) = (profile("alice"), profile("bob"));
- host.provision(&a).unwrap();
- host.provision(&b).unwrap();
- let state_a = host.open(&a).unwrap();
- let state_b = host.open(&b).unwrap();
+ host.provision(&a).await.unwrap();
+ host.provision(&b).await.unwrap();
+ let state_a = host.open(&a).await.unwrap();
+ let state_b = host.open(&b).await.unwrap();
assert_eq!(state_a.context().session_agent(), Some(a.as_str()));
assert_eq!(state_b.context().session_agent(), Some(b.as_str()));
@@ -53,82 +53,82 @@ fn an_open_profile_runs_under_its_own_scope() {
assert!(!state_a.context().user_skill_roots());
// Re-opening hands back the same state.
- assert!(Arc::ptr_eq(&state_a, &host.open(&a).unwrap()));
+ assert!(Arc::ptr_eq(&state_a, &host.open(&a).await.unwrap()));
assert_eq!(host.open_count(), 2);
}
-#[test]
-fn a_full_host_evicts_the_least_recently_used_idle_profile() {
+#[tokio::test]
+async fn a_full_host_evicts_the_least_recently_used_idle_profile() {
let tmp = tempfile::tempdir().unwrap();
let host = host(&tmp, 2, 3600);
let ids: Vec<_> = ["a", "b", "c"].iter().map(|n| profile(n)).collect();
for id in &ids {
- host.provision(id).unwrap();
+ host.provision(id).await.unwrap();
}
- drop(host.open(&ids[0]).unwrap());
- drop(host.open(&ids[1]).unwrap());
- drop(host.open(&ids[2]).unwrap());
+ drop(host.open(&ids[0]).await.unwrap());
+ drop(host.open(&ids[1]).await.unwrap());
+ drop(host.open(&ids[2]).await.unwrap());
assert_eq!(host.open_count(), 2);
assert!(!host.is_open(&ids[0]), "the oldest idle agent made room");
assert!(host.is_open(&ids[1]) && host.is_open(&ids[2]));
}
-#[test]
-fn an_profile_in_use_is_never_evicted() {
+#[tokio::test]
+async fn an_profile_in_use_is_never_evicted() {
let tmp = tempfile::tempdir().unwrap();
let host = host(&tmp, 1, 0);
let (a, b) = (profile("a"), profile("b"));
- host.provision(&a).unwrap();
- host.provision(&b).unwrap();
- let held = host.open(&a).unwrap();
- host.evict_idle();
+ host.provision(&a).await.unwrap();
+ host.provision(&b).await.unwrap();
+ let held = host.open(&a).await.unwrap();
+ host.evict_idle().await;
assert!(host.is_open(&a), "held agents survive an idle sweep");
- let err = host.open(&b).unwrap_err();
+ let err = host.open(&b).await.unwrap_err();
assert!(err.contains("slots are in use"), "{err}");
drop(held);
- host.open(&b).unwrap();
+ host.open(&b).await.unwrap();
}
-#[test]
-fn idle_profiles_are_swept() {
+#[tokio::test]
+async fn idle_profiles_are_swept() {
let tmp = tempfile::tempdir().unwrap();
let host = host(&tmp, 4, 0);
let id = profile("a");
- host.provision(&id).unwrap();
- drop(host.open(&id).unwrap());
- host.evict_idle();
+ host.provision(&id).await.unwrap();
+ drop(host.open(&id).await.unwrap());
+ host.evict_idle().await;
assert_eq!(host.open_count(), 0);
}
-#[test]
-fn deprovisioning_archives_and_closes() {
+#[tokio::test]
+async fn deprovisioning_archives_and_closes() {
let tmp = tempfile::tempdir().unwrap();
let host = host(&tmp, 4, 60);
let id = profile("a");
- host.provision(&id).unwrap();
- drop(host.open(&id).unwrap());
- assert!(host.deprovision(&id).unwrap());
+ host.provision(&id).await.unwrap();
+ drop(host.open(&id).await.unwrap());
+ assert!(host.deprovision(&id).await.unwrap());
assert!(!host.is_open(&id));
- assert!(host.summary(&id).unwrap().is_none());
+ assert!(host.summary(&id).await.unwrap().is_none());
let archived: Vec<_> = std::fs::read_dir(layout::archive_dir(tmp.path()))
.unwrap()
.flatten()
.collect();
assert_eq!(archived.len(), 1, "state is archived, not deleted");
- assert!(!host.deprovision(&id).unwrap());
+ assert!(!host.deprovision(&id).await.unwrap());
}
-#[test]
-fn list_reports_provisioned_profiles_only() {
+#[tokio::test]
+async fn list_reports_provisioned_profiles_only() {
let tmp = tempfile::tempdir().unwrap();
let host = host(&tmp, 4, 60);
- assert!(host.list().unwrap().is_empty());
+ assert!(host.list().await.unwrap().is_empty());
let (a, b) = (profile("a"), profile("b"));
- host.provision(&a).unwrap();
- host.provision(&b).unwrap();
+ host.provision(&a).await.unwrap();
+ host.provision(&b).await.unwrap();
std::fs::create_dir_all(layout::users_dir(tmp.path()).join("not-an-agent")).unwrap();
- let _held = host.open(&b).unwrap();
- let listed = host.list().unwrap();
+ let _held = host.open(&b).await.unwrap();
+ let listed = host.list().await.unwrap();
assert_eq!(listed.len(), 2);
let open: Vec<_> = listed
.iter()
@@ -138,13 +138,13 @@ fn list_reports_provisioned_profiles_only() {
assert_eq!(open, vec![&b]);
}
-#[test]
-fn a_reprovisioned_profile_does_not_inherit_the_old_credential() {
+#[tokio::test]
+async fn a_reprovisioned_profile_does_not_inherit_the_old_credential() {
let tmp = tempfile::tempdir().unwrap();
let host = host(&tmp, 4, 60);
let id = profile(&format!("returning-{}", uuid::Uuid::new_v4()));
- host.provision(&id).unwrap();
- let config = host.open(&id).unwrap().config.clone();
+ host.provision(&id).await.unwrap();
+ let config = host.open(&id).await.unwrap().config.clone();
super::super::credentials::store(
&config,
super::super::credentials::UserCredentialKind::Session,
@@ -152,25 +152,25 @@ fn a_reprovisioned_profile_does_not_inherit_the_old_credential() {
None,
)
.unwrap();
- assert!(host.summary(&id).unwrap().unwrap().has_credential);
- host.deprovision(&id).unwrap();
- host.provision(&id).unwrap();
+ assert!(host.summary(&id).await.unwrap().unwrap().has_credential);
+ host.deprovision(&id).await.unwrap();
+ host.provision(&id).await.unwrap();
assert!(
- !host.summary(&id).unwrap().unwrap().has_credential,
+ !host.summary(&id).await.unwrap().unwrap().has_credential,
"deprovisioning must forget the credential"
);
}
-#[test]
-fn the_first_open_settles_a_previous_process_once() {
+#[tokio::test]
+async fn the_first_open_settles_a_previous_process_once() {
let tmp = tempfile::tempdir().unwrap();
let host = host(&tmp, 4, 0);
let id = profile(&format!("recover-{}", uuid::Uuid::new_v4()));
- host.provision(&id).unwrap();
- drop(host.open(&id).unwrap());
+ host.provision(&id).await.unwrap();
+ drop(host.open(&id).await.unwrap());
assert!(host.recovered.lock().unwrap().contains(&id));
- host.evict_idle();
- drop(host.open(&id).unwrap());
+ host.evict_idle().await;
+ drop(host.open(&id).await.unwrap());
assert_eq!(
host.recovered.lock().unwrap().len(),
1,
@@ -178,36 +178,36 @@ fn the_first_open_settles_a_previous_process_once() {
);
}
-#[test]
-fn recovery_of_an_empty_workspace_is_a_no_op() {
+#[tokio::test]
+async fn recovery_of_an_empty_workspace_is_a_no_op() {
let tmp = tempfile::tempdir().unwrap();
let id = profile("empty");
recover_workspace(&id, tmp.path());
}
-#[test]
-fn an_profile_in_use_is_not_archived_from_under_it() {
+#[tokio::test]
+async fn an_profile_in_use_is_not_archived_from_under_it() {
let tmp = tempfile::tempdir().unwrap();
let host = host(&tmp, 4, 60);
let id = profile("alice");
- host.provision(&id).unwrap();
- let state = host.open(&id).unwrap();
- let err = host.deprovision(&id).unwrap_err();
+ host.provision(&id).await.unwrap();
+ let state = host.open(&id).await.unwrap();
+ let err = host.deprovision(&id).await.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.deprovision(&id).await.unwrap());
assert!(!host.is_open(&id));
}
-#[test]
-fn deprovisioning_twice_in_a_second_archives_twice() {
+#[tokio::test]
+async fn deprovisioning_twice_in_a_second_archives_twice() {
let tmp = tempfile::tempdir().unwrap();
let host = host(&tmp, 4, 60);
let id = profile("alice");
for _ in 0..2 {
- host.provision(&id).unwrap();
- assert!(host.deprovision(&id).unwrap());
+ host.provision(&id).await.unwrap();
+ assert!(host.deprovision(&id).await.unwrap());
}
let archived = std::fs::read_dir(layout::archive_dir(tmp.path()))
.unwrap()
@@ -215,47 +215,47 @@ fn deprovisioning_twice_in_a_second_archives_twice() {
assert_eq!(archived, 2);
}
-#[test]
-fn opening_an_open_profile_sweeps_the_idle_ones() {
+#[tokio::test]
+async fn opening_an_open_profile_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) = (profile("alice"), profile("bob"));
- host.provision(&a).unwrap();
- host.provision(&b).unwrap();
- drop(host.open(&a).unwrap());
- let held = host.open(&b).unwrap();
+ host.provision(&a).await.unwrap();
+ host.provision(&b).await.unwrap();
+ drop(host.open(&a).await.unwrap());
+ let held = host.open(&b).await.unwrap();
// Re-opening bob (already open) closes idle alice.
- let again = host.open(&b).unwrap();
+ let again = host.open(&b).await.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));
}
-#[test]
-fn one_unreadable_profile_does_not_hide_the_rest() {
+#[tokio::test]
+async fn one_unreadable_profile_does_not_hide_the_rest() {
let tmp = tempfile::tempdir().unwrap();
let host = host(&tmp, 4, 60);
let (a, b) = (profile("alice"), profile("bob"));
- host.provision(&a).unwrap();
- host.provision(&b).unwrap();
+ host.provision(&a).await.unwrap();
+ host.provision(&b).await.unwrap();
std::fs::write(ProfileLayout::new(tmp.path(), &a).meta_path, "not toml = [").unwrap();
- let listed = host.list().unwrap();
+ let listed = host.list().await.unwrap();
assert_eq!(listed.len(), 1);
assert_eq!(listed[0].profile_id, b);
}
-#[test]
-fn a_provisioned_config_needs_no_profile_slot() {
+#[tokio::test]
+async fn a_provisioned_config_needs_no_profile_slot() {
let tmp = tempfile::tempdir().unwrap();
let host = host(&tmp, 1, 60);
let (a, b) = (profile("alice"), profile("bob"));
- host.provision(&a).unwrap();
- host.provision(&b).unwrap();
- let _held = host.open(&a).unwrap();
- assert!(host.open(&b).is_err(), "the only slot is taken");
- assert!(host.provisioned_config(&b).is_ok());
- assert!(host.provisioned_config(&profile("nobody")).is_err());
+ host.provision(&a).await.unwrap();
+ host.provision(&b).await.unwrap();
+ let _held = host.open(&a).await.unwrap();
+ assert!(host.open(&b).await.is_err(), "the only slot is taken");
+ assert!(host.provisioned_config(&b).await.is_ok());
+ assert!(host.provisioned_config(&profile("nobody")).await.is_err());
}
#[tokio::test]
@@ -263,8 +263,8 @@ async fn an_open_profile_is_gated_by_its_own_policy_not_the_operators() {
let tmp = tempfile::tempdir().unwrap();
let host = host(&tmp, 4, 60);
let id = profile("alice");
- host.provision(&id).unwrap();
- let state = host.open(&id).unwrap();
+ host.provision(&id).await.unwrap();
+ let state = host.open(&id).await.unwrap();
assert_eq!(state.context().profile(), Some(id.as_str()));
let own = state
@@ -289,26 +289,26 @@ async fn a_profile_with_a_live_turn_is_not_evicted() {
let tmp = tempfile::tempdir().unwrap();
let host = host(&tmp, 1, 0);
let (a, b) = (profile("a"), profile("b"));
- host.provision(&a).unwrap();
- host.provision(&b).unwrap();
+ host.provision(&a).await.unwrap();
+ host.provision(&b).await.unwrap();
// The request that started the turn has answered and let go of the
// state; the turn keeps running on a context derived from the profile's.
- let context = Arc::clone(host.open(&a).unwrap().context());
+ let context = Arc::clone(host.open(&a).await.unwrap().context());
let (release, released) = tokio::sync::oneshot::channel::<()>();
let turn = tokio::spawn(CoreContext::scope_with_turn_origin(context, None, async {
let _ = released.await;
}));
tokio::task::yield_now().await;
- host.evict_idle();
+ host.evict_idle().await;
assert!(host.is_open(&a), "a live turn keeps its profile open");
- let err = host.open(&b).unwrap_err();
+ let err = host.open(&b).await.unwrap_err();
assert!(err.contains("slots are in use"), "{err}");
- assert!(host.deprovision(&a).unwrap_err().contains("in use"));
+ assert!(host.deprovision(&a).await.unwrap_err().contains("in use"));
release.send(()).unwrap();
turn.await.unwrap();
- host.evict_idle();
+ host.evict_idle().await;
assert!(!host.is_open(&a), "evicted once the turn ended");
- host.open(&b).unwrap();
+ host.open(&b).await.unwrap();
}
diff --git a/crates/openhuman-core/src/profiles/ops_tests.rs b/crates/openhuman-core/src/profiles/ops_tests.rs
index 6874c8a871..0afd0f82d4 100644
--- a/crates/openhuman-core/src/profiles/ops_tests.rs
+++ b/crates/openhuman-core/src/profiles/ops_tests.rs
@@ -8,15 +8,15 @@ fn host(tmp: &tempfile::TempDir) -> ProfileHost {
)
}
-#[test]
-fn provision_derives_the_profile_and_never_echoes_the_user_id() {
+#[tokio::test]
+async fn provision_derives_the_profile_and_never_echoes_the_user_id() {
let tmp = tempfile::tempdir().unwrap();
let host = host(&tmp);
- let out = provision_on(&host, "[email protected]").unwrap();
+ let out = provision_on(&host, "[email protected]").await.unwrap();
let json = out.into_cli_compatible_json().unwrap().to_string();
assert!(!json.contains("alice"), "{json}");
assert!(json.contains("\"created\":true"), "{json}");
- let again = provision_on(&host, "[email protected]").unwrap();
+ let again = provision_on(&host, "[email protected]").await.unwrap();
assert!(again
.into_cli_compatible_json()
.unwrap()
@@ -24,25 +24,25 @@ fn provision_derives_the_profile_and_never_echoes_the_user_id() {
.contains("\"created\":false"));
}
-#[test]
-fn status_and_deprovision_take_profile_ids_only() {
+#[tokio::test]
+async fn status_and_deprovision_take_profile_ids_only() {
let tmp = tempfile::tempdir().unwrap();
let host = host(&tmp);
- assert!(status_on(&host, "[email protected]").is_err());
- assert!(deprovision_on(&host, "../operator").is_err());
+ assert!(status_on(&host, "[email protected]").await.is_err());
+ assert!(deprovision_on(&host, "../operator").await.is_err());
let id = ProfileId::for_user("alice", crate::profiles::ProfileIdMode::Raw).unwrap();
- assert!(status_on(&host, id.as_str())
+ assert!(status_on(&host, id.as_str()).await
.unwrap_err()
.contains("not provisioned"));
- provision_on(&host, "alice").unwrap();
- status_on(&host, id.as_str()).unwrap();
- deprovision_on(&host, id.as_str()).unwrap();
- assert!(status_on(&host, id.as_str()).is_err());
+ provision_on(&host, "alice").await.unwrap();
+ status_on(&host, id.as_str()).await.unwrap();
+ deprovision_on(&host, id.as_str()).await.unwrap();
+ assert!(status_on(&host, id.as_str()).await.is_err());
}
-#[test]
-fn credentials_are_set_and_cleared_per_profile_and_never_echoed() {
+#[tokio::test]
+async fn credentials_are_set_and_cleared_per_profile_and_never_echoed() {
let tmp = tempfile::tempdir().unwrap();
let host = host(&tmp);
// The keyring holding credential secrets is shared by every test here.
@@ -57,10 +57,11 @@ fn credentials_are_set_and_cleared_per_profile_and_never_echoed() {
"t",
None
)
+ .await
.unwrap_err()
.contains("not provisioned"));
- provision_on(&host, &alice_user).unwrap();
- provision_on(&host, &bob_user).unwrap();
+ provision_on(&host, &alice_user).await.unwrap();
+ provision_on(&host, &bob_user).await.unwrap();
let out = set_credential_on(
&host,
@@ -69,12 +70,13 @@ fn credentials_are_set_and_cleared_per_profile_and_never_echoed() {
"alice-secret-jwt",
None,
)
+ .await
.unwrap();
let json = out.into_cli_compatible_json().unwrap().to_string();
assert!(!json.contains("alice-secret-jwt"), "{json}");
- assert!(host.summary(&alice).unwrap().unwrap().has_credential);
- assert!(!host.summary(&bob).unwrap().unwrap().has_credential);
+ assert!(host.summary(&alice).await.unwrap().unwrap().has_credential);
+ assert!(!host.summary(&bob).await.unwrap().unwrap().has_credential);
- clear_credential_on(&host, alice.as_str()).unwrap();
- assert!(!host.summary(&alice).unwrap().unwrap().has_credential);
+ clear_credential_on(&host, alice.as_str()).await.unwrap();
+ assert!(!host.summary(&alice).await.unwrap().unwrap().has_credential);
}