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(config): cover document source read and save behaviour
Steven Enamakelcf30aad4f40a
diff --git a/crates/openhuman-core/src/channels/bus/subscriber.rs b/crates/openhuman-core/src/channels/bus/subscriber.rsindex 1fafdf6f0d..307e15bf19 100644--- a/crates/openhuman-core/src/channels/bus/subscriber.rs+++ b/crates/openhuman-core/src/channels/bus/subscriber.rs@@ -67,7 +67,9 @@ impl EventHandler<DomainEvent> for ChannelInboundSubscriber {// If that contract is broken, the legacy channel-only key would let// different users share one chat session and its prepared wallet quote.if channel.split(':').next() == Some("discord")- && sender.as_deref().is_none_or(|value| value.trim().is_empty())+ && sender+ .as_deref()+ .is_none_or(|value| value.trim().is_empty()){tracing::warn!("[channel-inbound] dropping Discord message without sender id");return;diff --git a/crates/openhuman-core/src/config/schema/load/source/mod_tests.rs b/crates/openhuman-core/src/config/schema/load/source/mod_tests.rsindex a74caee709..2eae2f174e 100644--- a/crates/openhuman-core/src/config/schema/load/source/mod_tests.rs+++ b/crates/openhuman-core/src/config/schema/load/source/mod_tests.rs@@ -1,5 +1,5 @@-use super::*;use super::tests_support::ForcedDocumentSource;+use super::*;use crate::config::Config;use crate::storage::{MemoryStorage, Scope, ScopedStorage, StorageBackend};use std::sync::Arc;@@ -401,3 +401,91 @@ async fn a_document_that_does_not_parse_is_an_error_and_leaves_the_bootstrap_fil);assert!(!tmp.path().join("config.toml.bak").exists());}++#[tokio::test]+async fn a_read_reports_whether_its_text_is_a_document_body() {+ let tmp = tempfile::tempdir().unwrap();+ let file = tmp.path().join("config.toml");+ std::fs::write(&file, "default_model = \"from-file\"\n").unwrap();+ let storage = MemoryStorage::new();+ let source = document_source(&storage, "alice", &file);+ assert!(!source.read().await.unwrap().from_document, "file fallback");+ source.write("default_model = \"doc\"\n").await.unwrap();+ assert!(source.read().await.unwrap().from_document);+ assert!(+ !FileConfigSource::new(&file)+ .read()+ .await+ .unwrap()+ .from_document+ );+}++#[tokio::test]+async fn a_recovered_bootstrap_file_is_restored_beside_the_document() {+ let tmp = tempfile::tempdir().unwrap();+ let file = tmp.path().join("config.toml");+ let storage = MemoryStorage::new();+ let source = document_source(&storage, "alice", &file);+ source.write("default_model = \"m\"\n").await.unwrap();+ let bootstrap = "[storage]\nurl = \"sqlite:/b\"\n";+ std::fs::write(tmp.path().join("config.toml.bak"), bootstrap).unwrap();+ std::fs::write(&file, [0xff, 0xfe, 0x00, 0x80]).unwrap();++ let read = source.read().await.unwrap();+ assert!(read.contents.contains("sqlite:/b"), "{}", read.contents);+ assert!(!read.recovered, "the document body itself was intact");+ assert_eq!(std::fs::read_to_string(&file).unwrap(), bootstrap);+}++#[tokio::test]+async fn a_file_fallback_keeps_the_file_backup_recovery() {+ let tmp = tempfile::tempdir().unwrap();+ let storage = MemoryStorage::new();+ let _forced = ForcedDocumentSource::new(+ scoped(&storage, "tenant-a"),+ Scope::new("tenant-a").unwrap(),+ keys(3),+ );+ let config = config_at(tmp.path(), "unused");+ std::fs::write(&config.config_path, "default_model = 5\n").unwrap();+ std::fs::write(+ tmp.path().join("config.toml.bak"),+ "default_model = \"from-bak\"\n",+ )+ .unwrap();++ let reloaded = Config::load_from_config_path(&config.config_path, &config.workspace_dir)+ .await+ .unwrap();+ assert_eq!(reloaded.default_model.as_deref(), Some("from-bak"));+}++#[tokio::test]+async fn a_document_save_never_nests_process_key_ciphertext() {+ let tmp = tempfile::tempdir().unwrap();+ let storage = MemoryStorage::new();+ let _forced = ForcedDocumentSource::new(+ scoped(&storage, "tenant-a"),+ Scope::new("tenant-a").unwrap(),+ keys(3),+ );+ let mut config = config_at(tmp.path(), "m");+ assert!(config.secrets.encrypt);+ // A field still sealed under this node's key, as a file-seeded config+ // holds it before the load decrypts.+ let sealed = crate::security::keyring::SecretStore::new(tmp.path(), true)+ .encrypt("sk-node-local")+ .unwrap();+ assert!(sealed.starts_with("enc2:"));+ config.api_key = Some(sealed);+ config.save().await.unwrap();++ let body = document_source_keyed(&storage, "tenant-a", &config.config_path, keys(3))+ .read()+ .await+ .unwrap()+ .contents;+ assert!(body.contains("sk-node-local"), "{body}");+ assert!(!body.contains("enc2:"), "{body}");+}diff --git a/crates/openhuman-embed/examples/profiles.rs b/crates/openhuman-embed/examples/profiles.rsindex bcdd7d68d6..dfd1ecc2e5 100644--- a/crates/openhuman-embed/examples/profiles.rs+++ b/crates/openhuman-embed/examples/profiles.rs@@ -80,7 +80,10 @@ async fn run() -> anyhow::Result<()> {.await?;let handle = profiles.open(user).await?;let reply = handle.chat("t1", said).await?;- println!("\n[{user}] sent message to t1; got reply ({} bytes)", reply.text.len());+ println!(+ "\n[{user}] sent message to t1; got reply ({} bytes)",+ reply.text.len()+ );handles.push((user, handle));}diff --git a/crates/openhuman-embed/src/profiles.rs b/crates/openhuman-embed/src/profiles.rsindex 6b5a881a2e..7c9d9c2ad9 100644--- a/crates/openhuman-embed/src/profiles.rs+++ b/crates/openhuman-embed/src/profiles.rs@@ -356,7 +356,10 @@ fn ensure_service_token(path: &Path) -> Result<(), ProfileError> {// This ensures that if the write is interrupted, the target path is left in its original state.let parent = path.parent().unwrap_or_else(|| Path::new("."));let mut temp_path = parent.to_path_buf();- temp_path.push(format!(".service-token-tmp-{}", uuid::Uuid::new_v4().simple()));+ temp_path.push(format!(+ ".service-token-tmp-{}",+ uuid::Uuid::new_v4().simple()+ ));{let mut options = std::fs::OpenOptions::new();diff --git a/crates/openhuman-embed/tests/common/mod.rs b/crates/openhuman-embed/tests/common/mod.rsindex 7cf4f2939e..5735e5ba51 100644--- a/crates/openhuman-embed/tests/common/mod.rs+++ b/crates/openhuman-embed/tests/common/mod.rs@@ -246,12 +246,9 @@ impl openhuman_embed::BackendTransport for PointedTransport {) -> Result<serde_json::Value, openhuman_embed::BackendTransportError> {// Forward inference requests to the pointed mock endpoint.// This uses the same HTTP client as a real transport would.- let url = format!(- "{}/{}",- self.base_url,- req.path.trim_start_matches('/')- );- let resp = self.client+ let url = format!("{}/{}", self.base_url, req.path.trim_start_matches('/'));+ let resp = self+ .client.post(&url).json(&req.body).send()