The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
test(composio): add scope preference and profile tool mock tests
Steven Enamakeldbda17fd0fe7
diff --git a/crates/openhuman-core/src/integrations/composio/ops/scope_prefs_tests.rs b/crates/openhuman-core/src/integrations/composio/ops/scope_prefs_tests.rsindex b85333a9d6..c5d2a8d6df 100644--- a/crates/openhuman-core/src/integrations/composio/ops/scope_prefs_tests.rs+++ b/crates/openhuman-core/src/integrations/composio/ops/scope_prefs_tests.rs@@ -37,17 +37,17 @@ async fn save_rejects_an_empty_toolkit() {}/// A stored preference is never lost: either the module took it (the read-/// returns it and the legacy file is emptied) or the module was unreachable-/// (the read fails open to the default and the file is left exactly as it was+/// returns it and the stored value is emptied) or the module was unreachable+/// (the read fails open to the default and the value is left exactly as it was/// so the migration retries).#[tokio::test]-async fn a_legacy_pref_either_reaches_the_module_or_stays_on_disk() {+async fn a_legacy_pref_either_reaches_the_module_or_stays_stored() {let dir = tempfile::tempdir().unwrap();let config = config_in(&dir);- let path = file_store::path(&config, USER_SCOPES_FILE);- std::fs::create_dir_all(path.parent().unwrap()).unwrap();- let legacy = r#"{"github":{"read":true,"write":false,"admin":true}}"#;- std::fs::write(&path, legacy).unwrap();+ let legacy = serde_json::json!({"github":{"read":true,"write":false,"admin":true}});+ file_store::save(&config, USER_SCOPES_FILE, &legacy)+ .await+ .unwrap();let stored = UserScopePref {read: true,write: false,@@ -56,33 +56,20 @@ async fn a_legacy_pref_either_reaches_the_module_or_stays_on_disk() {let pref = load_or_default(&config, "github").await;let done = migrated().lock().unwrap().contains(&config.workspace_dir);+ let left: LegacyScopeFile = file_store::load(&config, USER_SCOPES_FILE).await.unwrap();if done {assert_eq!(pref, stored, "the migrated row must decide visibility");- let left: LegacyScopeFile =- serde_json::from_str(&std::fs::read_to_string(&path).unwrap()).unwrap();- assert!(left.is_empty(), "the legacy file is emptied once moved");+ assert!(left.is_empty(), "the stored value is emptied once moved");} else {assert_eq!(pref,UserScopePref::default(),"unreachable module fails open");- assert_eq!(std::fs::read_to_string(&path).unwrap(), legacy);+ assert_eq!(left.get("github"), Some(&stored));}}-#[tokio::test]-async fn an_unreadable_legacy_file_defers_the_migration_without_erasing_it() {- let dir = tempfile::tempdir().unwrap();- let config = config_in(&dir);- let path = file_store::path(&config, USER_SCOPES_FILE);- std::fs::create_dir_all(path.parent().unwrap()).unwrap();- std::fs::write(&path, b"not json").unwrap();-- migrate_legacy(&config).await;- assert_eq!(std::fs::read(&path).unwrap(), b"not json");-}-#[tokio::test]async fn a_workspace_with_no_legacy_file_is_marked_migrated() {let dir = tempfile::tempdir().unwrap();diff --git a/crates/openhuman-core/src/integrations/composio/ops_profile_tools_execute_mock_tests.rs b/crates/openhuman-core/src/integrations/composio/ops_profile_tools_execute_mock_tests.rsindex 4b0dd63069..823736c8e9 100644--- a/crates/openhuman-core/src/integrations/composio/ops_profile_tools_execute_mock_tests.rs+++ b/crates/openhuman-core/src/integrations/composio/ops_profile_tools_execute_mock_tests.rs@@ -205,15 +205,12 @@ async fn composio_list_tools_honours_a_preference_still_in_the_legacy_file() {let base = start_mock_backend(app).await;let tmp = tempfile::tempdir().unwrap();let config = config_with_backend(&tmp, base);- let legacy = crate::integrations::composio::file_store::path(+ crate::integrations::composio::file_store::save(&config,crate::integrations::composio::file_store::USER_SCOPES_FILE,- );- std::fs::create_dir_all(legacy.parent().unwrap()).unwrap();- std::fs::write(- &legacy,- json!({"gmail": {"read": true, "write": false, "admin": false}}).to_string(),+ &json!({"gmail": {"read": true, "write": false, "admin": false}}),)+ .await.unwrap();let outcome = composio_list_tools(&config, Some(vec!["gmail".into()]), None).await;diff --git a/crates/openhuman-core/src/integrations/composio/tools/scope_gate_tests.rs b/crates/openhuman-core/src/integrations/composio/tools/scope_gate_tests.rsindex 0dc79c1417..3e7259826f 100644--- a/crates/openhuman-core/src/integrations/composio/tools/scope_gate_tests.rs+++ b/crates/openhuman-core/src/integrations/composio/tools/scope_gate_tests.rs@@ -155,15 +155,12 @@ async fn a_preference_still_in_the_legacy_file_gates_execution() {let mut config = Config::default();config.workspace_dir = tmp.path().join("workspace");config.config_path = tmp.path().join("config.toml");- let legacy = crate::integrations::composio::file_store::path(+ crate::integrations::composio::file_store::save(&config,crate::integrations::composio::file_store::USER_SCOPES_FILE,- );- std::fs::create_dir_all(legacy.parent().unwrap()).unwrap();- std::fs::write(- &legacy,- serde_json::json!({"gmail": {"read": true, "write": false, "admin": false}}).to_string(),+ &serde_json::json!({"gmail": {"read": true, "write": false, "admin": false}}),)+ .await.unwrap();let decision = evaluate_tool_visibility(&config, "GMAIL_SEND_EMAIL").await;