Skip to content

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

test(browser): drop profile-claiming tests for removed helper

Steven Enamakel589aaf279980
diff --git a/crates/openhuman-core/src/modules/browser_task_tests.rs b/crates/openhuman-core/src/modules/browser_task_tests.rs
index 8a3b631ce0..d0d2af4b70 100644
--- a/crates/openhuman-core/src/modules/browser_task_tests.rs
+++ b/crates/openhuman-core/src/modules/browser_task_tests.rs
@@ -179,125 +179,13 @@ fn a_chrome_path_the_module_refuses_says_where_the_user_fixes_it() {
}
#[tokio::test]
-async fn a_task_keeps_the_persistent_profile_only_while_no_other_chrome_holds_it() {
- let mut config = Config::default();
- config.browser.profile_mode = "persistent".into();
- let profile =
- std::env::temp_dir().join(format!("openhuman-task-profile-{}", std::process::id()));
- let _ = std::fs::remove_dir_all(&profile);
- std::fs::create_dir_all(&profile).unwrap();
- config.browser.profile_path = Some(profile.to_string_lossy().into_owned());
-
- // Free: the task keeps it.
+async fn a_task_without_a_persistent_profile_claims_nothing() {
+ let config = Config::default();
let mut request = start_request(&config, &task());
- assert_eq!(
- claim_profile(&mut request, Duration::from_millis(50)).await,
- Some(profile.clone())
- );
- assert_eq!(
- request.constraints.browser_profile.as_deref(),
- config.browser.profile_path.as_deref()
- );
-
- // Held by a running Chrome (here, this process): a fresh profile instead.
- #[cfg(not(windows))]
- {
- let here = sysinfo::System::host_name().unwrap_or_default();
- std::os::unix::fs::symlink(
- format!("{here}-{}", std::process::id()),
- profile.join("SingletonLock"),
- )
- .unwrap();
- let mut request = start_request(&config, &task());
- assert_eq!(
- claim_profile(&mut request, Duration::from_millis(50)).await,
- None
- );
- assert!(request.constraints.browser_profile.is_none());
- }
- super::super::browser_profile::release(&profile);
- let _ = std::fs::remove_dir_all(&profile);
-
- // No persistent profile: nothing to wait for.
- let mut request = start_request(&Config::default(), &task());
- assert_eq!(
- claim_profile(&mut request, Duration::from_millis(50)).await,
- None
- );
+ assert_eq!(claim_profile(&config, &mut request, 50).await, None);
assert!(request.constraints.browser_profile.is_none());
}
-/// A config whose persistent profile is a fresh folder named `name`, with
-/// its workspace in `dir`.
-fn persistent_config(dir: &tempfile::TempDir, name: &str) -> (Config, PathBuf) {
- let profile = dir.path().join(name);
- std::fs::create_dir_all(&profile).unwrap();
- let mut config = Config::default();
- config.workspace_dir = dir.path().join("workspace");
- config.browser.profile_mode = "persistent".into();
- config.browser.profile_path = Some(profile.to_string_lossy().into_owned());
- (config, profile)
-}
-
-#[tokio::test]
-async fn of_two_tasks_starting_together_one_runs_in_a_fresh_profile() {
- // Neither one's Chrome has locked the folder when the other looks.
- let dir = tempfile::tempdir().unwrap();
- let (config, profile) = persistent_config(&dir, "together");
- let (mut first, mut second) = (
- start_request(&config, &task()),
- start_request(&config, &task()),
- );
- let (kept_first, kept_second) = tokio::join!(
- claim_profile(&mut first, Duration::from_millis(50)),
- claim_profile(&mut second, Duration::from_millis(50)),
- );
- let profiles = [
- first.constraints.browser_profile,
- second.constraints.browser_profile,
- ];
- assert_eq!(
- profiles.iter().filter(|kept| kept.is_some()).count(),
- 1,
- "{profiles:?}"
- );
- assert_eq!(kept_first.or(kept_second), Some(profile.clone()));
- super::super::browser_profile::release(&profile);
-}
-
-#[tokio::test]
-async fn a_task_the_module_did_not_start_gives_its_profile_back() {
- let dir = tempfile::tempdir().unwrap();
- let (config, profile) = persistent_config(&dir, "refused");
- let error = begin(&config, &task(), |_| {
- Box::pin(async { Err::<TaskView, _>("browser task StartTask failed: bus closed".into()) })
- })
- .await
- .unwrap_err();
- assert!(error.contains("bus closed"));
- assert!(
- super::super::browser_profile::claim_within(&profile, Duration::ZERO).await,
- "free for the next task at once"
- );
- super::super::browser_profile::release(&profile);
-
- // A task that started keeps its claim until its Chrome holds the folder.
- begin(&config, &task(), |request| {
- assert!(request.constraints.browser_profile.is_some());
- Box::pin(async {
- Ok(serde_json::from_value::<TaskView>(json!({
- "id": "t-claimed", "status": {"state": "running"},
- "summary": "", "progress": 0.0, "next": []
- }))
- .unwrap())
- })
- })
- .await
- .unwrap();
- assert!(!super::super::browser_profile::claim_within(&profile, Duration::ZERO).await);
- super::super::browser_profile::release(&profile);
-}
-
#[test]
fn a_saved_flow_is_run_instead_of_planned() {
let flow: tinycomputer_bus::Flow = serde_json::from_value(serde_json::json!({
diff --git a/crates/openhuman-core/src/modules/browser_tests.rs b/crates/openhuman-core/src/modules/browser_tests.rs
index a64b25afc9..b9a97cd439 100644
--- a/crates/openhuman-core/src/modules/browser_tests.rs
+++ b/crates/openhuman-core/src/modules/browser_tests.rs
@@ -189,46 +189,11 @@ fn tinycomputers_own_words_for_a_missing_or_unusable_chrome_get_the_users_fix()
}
#[tokio::test]
-async fn a_session_opens_in_a_fresh_profile_while_another_chrome_holds_it() {
- // Live, a second conversation's browser found the profile held by the
- // first's, and Chrome exited at once.
- let profile =
- std::env::temp_dir().join(format!("openhuman-session-profile-{}", std::process::id()));
- let _ = std::fs::remove_dir_all(&profile);
- std::fs::create_dir_all(&profile).unwrap();
- let held = profile.to_string_lossy().into_owned();
- let mut options = SessionOptions {
- user_data_dir: Some(held.clone()),
- ..SessionOptions::default()
- };
- let wait = std::time::Duration::from_millis(50);
- assert_eq!(
- claim_profile(&mut options, wait).await,
- Some(profile.clone())
- );
- assert_eq!(options.user_data_dir.as_deref(), Some(held.as_str()));
-
- // A second session while the first's browser is still starting.
- let mut second = SessionOptions {
- user_data_dir: Some(held.clone()),
- ..SessionOptions::default()
- };
- assert_eq!(claim_profile(&mut second, wait).await, None);
- assert!(second.user_data_dir.is_none());
- super::super::browser_profile::release(&profile);
-
- #[cfg(not(windows))]
- {
- let here = sysinfo::System::host_name().unwrap_or_default();
- std::os::unix::fs::symlink(
- format!("{here}-{}", std::process::id()),
- profile.join("SingletonLock"),
- )
- .unwrap();
- assert_eq!(claim_profile(&mut options, wait).await, None);
- assert!(options.user_data_dir.is_none());
- }
- let _ = std::fs::remove_dir_all(&profile);
+async fn a_session_without_a_persistent_profile_claims_nothing() {
+ let mut options = SessionOptions::default();
+ let config = Config::default();
+ assert_eq!(claim_profile(&config, &mut options, 50).await, None);
+ assert!(options.user_data_dir.is_none());
}
#[test]