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(keyring): cover recovery and quarantine edge cases
Steven Enamakelb3c6fb3f0d55
diff --git a/crates/openhuman-core/src/security/keyring/adapter_tests.rs b/crates/openhuman-core/src/security/keyring/adapter_tests.rsindex 350c0a41d6..dadac19dbc 100644--- a/crates/openhuman-core/src/security/keyring/adapter_tests.rs+++ b/crates/openhuman-core/src/security/keyring/adapter_tests.rs@@ -251,3 +251,27 @@ fn a_legacy_dev_keychain_is_imported_once() {assert!(dir.path().join("dev-keychain.json.migrated").exists());assert!(dir.path().join("secrets.enc").exists());}++#[test]+fn recovery_never_quarantines_a_file_that_is_not_confirmed_corrupt() {+ // The re-probe fails with an I/O error (the path is a directory), not a+ // crypto/serialization one: nothing says the contents are bad, so nothing+ // is moved and the error is surfaced.+ let dir = tempfile::tempdir().unwrap();+ let path = dir.path().join("secrets.enc");+ std::fs::create_dir(&path).unwrap();+ let cause = tinystoragedrivers::StorageError::crypto("earlier failure");+ let error = recover_corrupt_file(&path, &KEY, &cause).unwrap_err();+ assert!(matches!(error, KeyringError::Backend(_)), "{error:?}");+ assert!(path.is_dir(), "left in place");+}++#[test]+fn recovery_leaves_a_file_that_became_readable() {+ let dir = tempfile::tempdir().unwrap();+ let b = EncryptedFileBackend::new(dir.path());+ b.set_with_key(&KEY, "u:a", "1").unwrap();+ let cause = tinystoragedrivers::StorageError::crypto("stale failure");+ recover_corrupt_file(&dir.path().join("secrets.enc"), &KEY, &cause).unwrap();+ assert_eq!(b.get_with_key(&KEY, "u:a").unwrap().as_deref(), Some("1"));+}diff --git a/crates/openhuman-core/src/security/keyring/file_store_tests.rs b/crates/openhuman-core/src/security/keyring/file_store_tests.rsindex 342189a90e..b0632002d6 100644--- a/crates/openhuman-core/src/security/keyring/file_store_tests.rs+++ b/crates/openhuman-core/src/security/keyring/file_store_tests.rs@@ -172,3 +172,28 @@ fn quarantine_reports_none_when_there_is_nothing_to_move() {let dir = tempfile::TempDir::new().unwrap();assert!(quarantine_corrupt(&dir.path().join("absent.json"), "json").is_none());}++#[test]+fn two_quarantines_in_one_second_keep_both_files() {+ let dir = tempfile::TempDir::new().unwrap();+ let path = dir.path().join("secrets.enc");+ let mut moved = Vec::new();+ for body in [+ b"first".as_slice(),+ b"second".as_slice(),+ b"third".as_slice(),+ ] {+ std::fs::write(&path, body).unwrap();+ moved.push(quarantine_corrupt(&path, "enc").expect("moved aside"));+ }+ let mut names: Vec<_> = moved.iter().collect();+ names.sort();+ names.dedup();+ assert_eq!(names.len(), 3, "no quarantine reused a name: {moved:?}");+ let mut bodies: Vec<_> = moved.iter().map(|p| std::fs::read(p).unwrap()).collect();+ bodies.sort();+ assert_eq!(+ bodies,+ [b"first".to_vec(), b"second".to_vec(), b"third".to_vec()]+ );+}