Skip to content

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

test(config): pass storage backend by reference in source tests

Steven Enamakelc088d1ee6508
diff --git a/crates/openhuman-core/src/config/schema/load/source/concurrency_tests.rs b/crates/openhuman-core/src/config/schema/load/source/concurrency_tests.rs
index 57dce73845..f02194517e 100644
--- a/crates/openhuman-core/src/config/schema/load/source/concurrency_tests.rs
+++ b/crates/openhuman-core/src/config/schema/load/source/concurrency_tests.rs
@@ -7,7 +7,7 @@ async fn agent_registry_rpc_preserves_document_conflicts() {
let tmp = tempfile::tempdir().unwrap();
let storage = memory_backend();
let _forced = ForcedDocumentSource::new(
- scoped(&storage, "tenant-rpc"),
+ scoped(storage.as_ref(), "tenant-rpc"),
Scope::new("tenant-rpc").unwrap(),
keys(9),
);
@@ -50,7 +50,7 @@ async fn memory_engine_rpc_preserves_document_conflicts() {
let tmp = tempfile::tempdir().unwrap();
let storage = memory_backend();
let _forced = ForcedDocumentSource::new(
- scoped(&storage, "tenant-memory-rpc"),
+ scoped(storage.as_ref(), "tenant-memory-rpc"),
Scope::new("tenant-memory-rpc").unwrap(),
keys(10),
);
@@ -93,7 +93,7 @@ async fn sequential_config_rpcs_use_the_latest_context_snapshot() {
let tmp = tempfile::tempdir().unwrap();
let storage = memory_backend();
let _forced = ForcedDocumentSource::new(
- scoped(&storage, "tenant-sequential-config-rpc"),
+ scoped(storage.as_ref(), "tenant-sequential-config-rpc"),
Scope::new("tenant-sequential-config-rpc").unwrap(),
keys(11),
);
@@ -135,7 +135,7 @@ async fn external_config_conflict_refreshes_the_context_before_the_next_read() {
let tmp = tempfile::tempdir().unwrap();
let storage = memory_backend();
let _forced = ForcedDocumentSource::new(
- scoped(&storage, "tenant-refresh-config-rpc"),
+ scoped(storage.as_ref(), "tenant-refresh-config-rpc"),
Scope::new("tenant-refresh-config-rpc").unwrap(),
keys(13),
);
@@ -182,7 +182,7 @@ async fn external_config_conflict_refresh_keeps_derived_runtime_overrides() {
let tmp = tempfile::tempdir().unwrap();
let storage = memory_backend();
let _forced = ForcedDocumentSource::new(
- scoped(&storage, "tenant-refresh-overlay"),
+ scoped(storage.as_ref(), "tenant-refresh-overlay"),
Scope::new("tenant-refresh-overlay").unwrap(),
keys(14),
);
@@ -327,7 +327,7 @@ async fn nested_context_refresh_does_not_pin_a_previous_external_value() {
let tmp = tempfile::tempdir().unwrap();
let storage = memory_backend();
let _forced = ForcedDocumentSource::new(
- scoped(&storage, "tenant-refresh-nested-overlay"),
+ scoped(storage.as_ref(), "tenant-refresh-nested-overlay"),
Scope::new("tenant-refresh-nested-overlay").unwrap(),
keys(15),
);
@@ -420,7 +420,7 @@ async fn config_snapshot_cannot_be_saved_into_a_different_tenant_scope() {
let (from_tenant_a, tenant_a_version) = {
let _source = ForcedDocumentSource::new(
- scoped(&storage, "tenant-source-a"),
+ scoped(storage.as_ref(), "tenant-source-a"),
Scope::new("tenant-source-a").unwrap(),
keys(12),
);
@@ -439,7 +439,7 @@ async fn config_snapshot_cannot_be_saved_into_a_different_tenant_scope() {
let (tenant_b_version, tenant_b_model) = {
let _source = ForcedDocumentSource::new(
- scoped(&storage, "tenant-source-b"),
+ scoped(storage.as_ref(), "tenant-source-b"),
Scope::new("tenant-source-b").unwrap(),
keys(12),
);
@@ -453,7 +453,7 @@ async fn config_snapshot_cannot_be_saved_into_a_different_tenant_scope() {
.lock()
.unwrap()
.version;
- let docs = Arc::clone(scoped(&storage, "tenant-source-b").documents());
+ let docs = Arc::clone(scoped(storage.as_ref(), "tenant-source-b").documents());
let stored = docs
.get(
super::super::storage_schema::CONFIG_COLLECTION,
@@ -475,7 +475,7 @@ async fn config_snapshot_cannot_be_saved_into_a_different_tenant_scope() {
from_tenant_a.default_model = Some("must-not-cross-tenant-boundary".into());
let error = {
let _source = ForcedDocumentSource::new(
- scoped(&storage, "tenant-source-b"),
+ scoped(storage.as_ref(), "tenant-source-b"),
Scope::new("tenant-source-b").unwrap(),
keys(12),
);
@@ -492,7 +492,7 @@ async fn config_snapshot_cannot_be_saved_into_a_different_tenant_scope() {
let tenant_b = {
let _source = ForcedDocumentSource::new(
- scoped(&storage, "tenant-source-b"),
+ scoped(storage.as_ref(), "tenant-source-b"),
Scope::new("tenant-source-b").unwrap(),
keys(12),
);
@@ -601,7 +601,7 @@ async fn a_file_snapshot_can_seed_an_absent_document_after_storage_bootstrap() {
let storage = memory_backend();
let _source = ForcedDocumentSource::new(
- scoped(&storage, "tenant-file-bootstrap"),
+ scoped(storage.as_ref(), "tenant-file-bootstrap"),
Scope::new("tenant-file-bootstrap").unwrap(),
keys(15),
);
@@ -621,8 +621,8 @@ async fn document_source_write_uses_its_last_read_revision() {
let tmp = tempfile::tempdir().unwrap();
let storage = memory_backend();
let path = tmp.path().join("config.toml");
- let first = document_source(&storage, "tenant-source-cas", &path);
- let stale = document_source(&storage, "tenant-source-cas", &path);
+ let first = document_source(storage.as_ref(), "tenant-source-cas", &path);
+ let stale = document_source(storage.as_ref(), "tenant-source-cas", &path);
first.write("default_model = \"seed\"\n").await.unwrap();
first.read().await.unwrap();
@@ -641,8 +641,8 @@ async fn an_unobserved_document_source_write_is_create_only() {
let tmp = tempfile::tempdir().unwrap();
let storage = memory_backend();
let path = tmp.path().join("config.toml");
- let seed = document_source(&storage, "tenant-source-create-only", &path);
- let blind = document_source(&storage, "tenant-source-create-only", &path);
+ let seed = document_source(storage.as_ref(), "tenant-source-create-only", &path);
+ let blind = document_source(storage.as_ref(), "tenant-source-create-only", &path);
seed.write("default_model = \"seed\"\n").await.unwrap();
let error = blind
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.rs
index 2cb4c60d21..738b59ad2b 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
@@ -113,14 +113,14 @@ async fn a_document_holds_no_plaintext_and_no_bootstrap_tables() {
let tmp = tempfile::tempdir().unwrap();
let file = tmp.path().join("config.toml");
let storage = memory_backend();
- let source = document_source(&storage, "alice", &file);
+ let source = document_source(storage.as_ref(), "alice", &file);
source
.write("default_model = \"m\"\napi_key = \"sk-very-secret\"\n[storage]\nurl = \"mongodb://u:pw@db/x\"\n")
.await
.unwrap();
- let docs = Arc::clone(scoped(&storage, "alice").documents());
+ let docs = Arc::clone(scoped(storage.as_ref(), "alice").documents());
let stored = docs
.get("config.documents", "alice")
.await
@@ -141,23 +141,23 @@ async fn a_document_holds_no_plaintext_and_no_bootstrap_tables() {
async fn a_document_does_not_decrypt_under_another_scope_or_master_key() {
let tmp = tempfile::tempdir().unwrap();
let storage = memory_backend();
- let alice = document_source(&storage, "alice", &tmp.path().join("a.toml"));
+ let alice = document_source(storage.as_ref(), "alice", &tmp.path().join("a.toml"));
alice.write("default_model = \"m\"\n").await.unwrap();
// Another master key fails closed.
- let wrong_key = document_source_keyed(&storage, "alice", &tmp.path().join("a.toml"), keys(2));
+ let wrong_key = document_source_keyed(storage.as_ref(), "alice", &tmp.path().join("a.toml"), keys(2));
assert!(wrong_key.read().await.is_err());
// Another scope's data key cannot open alice's ciphertext even when the
// sealed value is copied across (per-scope key derivation).
- let docs = Arc::clone(scoped(&storage, "alice").documents());
+ let docs = Arc::clone(scoped(storage.as_ref(), "alice").documents());
let sealed = docs
.get("config.documents", "alice")
.await
.unwrap()
.unwrap()
.doc;
- let bob_docs = Arc::clone(scoped(&storage, "bob").documents());
+ let bob_docs = Arc::clone(scoped(storage.as_ref(), "bob").documents());
bob_docs
.put(
"config.documents",
@@ -167,7 +167,7 @@ async fn a_document_does_not_decrypt_under_another_scope_or_master_key() {
)
.await
.unwrap();
- let bob = document_source(&storage, "bob", &tmp.path().join("b.toml"));
+ let bob = document_source(storage.as_ref(), "bob", &tmp.path().join("b.toml"));
assert!(bob.read().await.is_err(), "copied ciphertext must not open");
}
@@ -176,7 +176,7 @@ async fn a_malformed_bootstrap_file_is_an_error_not_an_empty_one() {
let tmp = tempfile::tempdir().unwrap();
let file = tmp.path().join("config.toml");
let storage = memory_backend();
- let source = document_source(&storage, "alice", &file);
+ let source = document_source(storage.as_ref(), "alice", &file);
source.write("default_model = \"m\"\n").await.unwrap();
std::fs::write(&file, "[storage\n").unwrap();
assert!(source.read().await.is_err());
@@ -188,7 +188,7 @@ async fn a_document_read_takes_its_bootstrap_tables_from_the_file() {
let file = tmp.path().join("config.toml");
std::fs::write(&file, "[storage]\nurl = \"sqlite:/data\"\n").unwrap();
let storage = memory_backend();
- let source = document_source(&storage, "alice", &file);
+ let source = document_source(storage.as_ref(), "alice", &file);
source.write("default_model = \"m\"\n").await.unwrap();
let read = source.read().await.unwrap();
@@ -197,7 +197,7 @@ async fn a_document_read_takes_its_bootstrap_tables_from_the_file() {
assert_eq!(table["storage"]["url"].as_str(), Some("sqlite:/data"));
// Even a document that somehow carries a [storage] table is overruled.
- let docs = Arc::clone(scoped(&storage, "alice").documents());
+ let docs = Arc::clone(scoped(storage.as_ref(), "alice").documents());
let key = keys(1).data_key(&Scope::new("alice").unwrap()).unwrap();
let sealed = crypto::encrypt_enc2(&key, b"[storage]\nurl = \"evil\"\n").unwrap();
docs.put(
@@ -218,7 +218,7 @@ async fn without_a_document_the_source_reads_the_file() {
let tmp = tempfile::tempdir().unwrap();
let file = tmp.path().join("config.toml");
let storage = memory_backend();
- let source = document_source(&storage, "alice", &file);
+ let source = document_source(storage.as_ref(), "alice", &file);
assert!(!source.exists().await.unwrap());
std::fs::write(&file, "default_model = \"from-file\"\n").unwrap();
@@ -234,8 +234,8 @@ async fn without_a_document_the_source_reads_the_file() {
async fn two_scopes_keep_their_config_apart() {
let tmp = tempfile::tempdir().unwrap();
let storage = memory_backend();
- let alice = document_source(&storage, "alice", &tmp.path().join("a.toml"));
- let bob = document_source(&storage, "bob", &tmp.path().join("b.toml"));
+ let alice = document_source(storage.as_ref(), "alice", &tmp.path().join("a.toml"));
+ let bob = document_source(storage.as_ref(), "bob", &tmp.path().join("b.toml"));
alice
.write("default_model = \"alice-model\"\n")
@@ -260,7 +260,7 @@ async fn config_save_and_reload_use_the_document_on_a_shared_backend() {
let tmp = tempfile::tempdir().unwrap();
let storage = memory_backend();
let _forced = ForcedDocumentSource::new(
- scoped(&storage, "tenant-a"),
+ scoped(storage.as_ref(), "tenant-a"),
Scope::new("tenant-a").unwrap(),
keys(3),
);
@@ -291,7 +291,7 @@ async fn stale_document_config_snapshot_returns_conflict_instead_of_overwriting(
let tmp = tempfile::tempdir().unwrap();
let storage = memory_backend();
let _forced = ForcedDocumentSource::new(
- scoped(&storage, "tenant-a"),
+ scoped(storage.as_ref(), "tenant-a"),
Scope::new("tenant-a").unwrap(),
keys(3),
);
@@ -355,7 +355,7 @@ async fn a_document_backed_config_keeps_secrets_readable_on_reload() {
let tmp = tempfile::tempdir().unwrap();
let storage = memory_backend();
let _forced = ForcedDocumentSource::new(
- scoped(&storage, "tenant-a"),
+ scoped(storage.as_ref(), "tenant-a"),
Scope::new("tenant-a").unwrap(),
keys(3),
);
@@ -376,13 +376,13 @@ async fn a_document_backed_config_keeps_secrets_readable_on_reload() {
fn forced_sources_nest_and_restore() {
let storage = memory_backend();
let outer = ForcedDocumentSource::new(
- scoped(&storage, "outer"),
+ scoped(storage.as_ref(), "outer"),
Scope::new("outer").unwrap(),
keys(1),
);
{
let _inner = ForcedDocumentSource::new(
- scoped(&storage, "inner"),
+ scoped(storage.as_ref(), "inner"),
Scope::new("inner").unwrap(),
keys(1),
);
@@ -411,8 +411,8 @@ async fn a_present_but_malformed_document_is_an_error_not_absence() {
let file = tmp.path().join("config.toml");
std::fs::write(&file, "default_model = \"stale-file\"\n").unwrap();
let storage = memory_backend();
- let source = document_source(&storage, "alice", &file);
- let docs = Arc::clone(scoped(&storage, "alice").documents());
+ let source = document_source(storage.as_ref(), "alice", &file);
+ let docs = Arc::clone(scoped(storage.as_ref(), "alice").documents());
docs.put(
"config.documents",
"alice",
@@ -433,12 +433,12 @@ async fn a_document_that_does_not_parse_is_an_error_and_leaves_the_bootstrap_fil
let tmp = tempfile::tempdir().unwrap();
let storage = memory_backend();
let _forced = ForcedDocumentSource::new(
- scoped(&storage, "tenant-a"),
+ scoped(storage.as_ref(), "tenant-a"),
Scope::new("tenant-a").unwrap(),
keys(3),
);
let config = config_at(tmp.path(), "m");
- let docs = Arc::clone(scoped(&storage, "tenant-a").documents());
+ let docs = Arc::clone(scoped(storage.as_ref(), "tenant-a").documents());
let key = keys(3).data_key(&Scope::new("tenant-a").unwrap()).unwrap();
let sealed = crypto::encrypt_enc2(&key, b"default_model = 5\n").unwrap();
docs.put(
@@ -472,7 +472,7 @@ async fn a_read_reports_whether_its_text_is_a_document_body() {
let file = tmp.path().join("config.toml");
std::fs::write(&file, "default_model = \"from-file\"\n").unwrap();
let storage = memory_backend();
- let source = document_source(&storage, "alice", &file);
+ let source = document_source(storage.as_ref(), "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);
@@ -490,7 +490,7 @@ 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 = memory_backend();
- let source = document_source(&storage, "alice", &file);
+ let source = document_source(storage.as_ref(), "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();
@@ -507,7 +507,7 @@ async fn a_file_fallback_keeps_the_file_backup_recovery() {
let tmp = tempfile::tempdir().unwrap();
let storage = memory_backend();
let _forced = ForcedDocumentSource::new(
- scoped(&storage, "tenant-a"),
+ scoped(storage.as_ref(), "tenant-a"),
Scope::new("tenant-a").unwrap(),
keys(3),
);
@@ -530,7 +530,7 @@ async fn a_document_save_never_nests_process_key_ciphertext() {
let tmp = tempfile::tempdir().unwrap();
let storage = memory_backend();
let _forced = ForcedDocumentSource::new(
- scoped(&storage, "tenant-a"),
+ scoped(storage.as_ref(), "tenant-a"),
Scope::new("tenant-a").unwrap(),
keys(3),
);
@@ -545,7 +545,7 @@ async fn a_document_save_never_nests_process_key_ciphertext() {
config.api_key = Some(sealed);
config.save().await.unwrap();
- let body = document_source_keyed(&storage, "tenant-a", &config.config_path, keys(3))
+ let body = document_source_keyed(storage.as_ref(), "tenant-a", &config.config_path, keys(3))
.read()
.await
.unwrap()
@@ -560,7 +560,7 @@ async fn a_document_save_refuses_process_key_secrets_it_cannot_open() {
let other_node = tempfile::tempdir().unwrap();
let storage = memory_backend();
let _forced = ForcedDocumentSource::new(
- scoped(&storage, "tenant-a"),
+ scoped(storage.as_ref(), "tenant-a"),
Scope::new("tenant-a").unwrap(),
keys(3),
);
@@ -576,7 +576,7 @@ async fn a_document_save_refuses_process_key_secrets_it_cannot_open() {
format!("{error:#}").contains("could not be opened"),
"{error:#}"
);
- let docs = Arc::clone(scoped(&storage, "tenant-a").documents());
+ let docs = Arc::clone(scoped(storage.as_ref(), "tenant-a").documents());
docs.ensure_collection(&tinystoragedrivers::CollectionSpec::new("config.documents"))
.await
.unwrap();
@@ -594,7 +594,7 @@ async fn a_recovered_file_fallback_rewrites_the_bootstrap_file_too() {
let tmp = tempfile::tempdir().unwrap();
let storage = memory_backend();
let _forced = ForcedDocumentSource::new(
- scoped(&storage, "tenant-a"),
+ scoped(storage.as_ref(), "tenant-a"),
Scope::new("tenant-a").unwrap(),
keys(3),
);
diff --git a/crates/openhuman-core/src/config/schema/load/source/profile_refresh_tests.rs b/crates/openhuman-core/src/config/schema/load/source/profile_refresh_tests.rs
index 564a6d52ad..b726efb2d1 100644
--- a/crates/openhuman-core/src/config/schema/load/source/profile_refresh_tests.rs
+++ b/crates/openhuman-core/src/config/schema/load/source/profile_refresh_tests.rs
@@ -5,7 +5,7 @@ async fn profile_context_conflict_refresh_keeps_host_owned_restrictions() {
let tmp = tempfile::tempdir().unwrap();
let storage = memory_backend();
let _forced = ForcedDocumentSource::new(
- scoped(&storage, "tenant-profile-refresh"),
+ scoped(storage.as_ref(), "tenant-profile-refresh"),
Scope::new("tenant-profile-refresh").unwrap(),
keys(16),
);
diff --git a/crates/openhuman-core/src/config/schema/load/source/revision_loader_tests.rs b/crates/openhuman-core/src/config/schema/load/source/revision_loader_tests.rs
index 4c8f501180..6834ee2610 100644
--- a/crates/openhuman-core/src/config/schema/load/source/revision_loader_tests.rs
+++ b/crates/openhuman-core/src/config/schema/load/source/revision_loader_tests.rs
@@ -9,7 +9,7 @@ async fn discovered_parent_config_is_used_to_record_agent_overrides() {
let tmp = tempfile::tempdir().unwrap();
let storage = memory_backend();
let _forced = ForcedDocumentSource::new(
- scoped(&storage, "tenant-internal-boot-agent"),
+ scoped(storage.as_ref(), "tenant-internal-boot-agent"),
Scope::new("tenant-internal-boot-agent").unwrap(),
keys(18),
);
@@ -84,7 +84,7 @@ async fn proxy_config_tool_loads_a_versioned_document_before_saving() {
seed.proxy.http_proxy = Some("http://persisted-proxy.invalid:8080".into());
seed.save().await.unwrap();
let _forced = ForcedDocumentSource::new(
- scoped(&storage, "tenant-proxy-tool-revision"),
+ scoped(storage.as_ref(), "tenant-proxy-tool-revision"),
Scope::new("tenant-proxy-tool-revision").unwrap(),
keys(19),
);
@@ -156,7 +156,7 @@ async fn channel_allowlist_store_loads_a_versioned_document_before_saving() {
seed.save().await.unwrap();
let _forced = ForcedDocumentSource::new(
- scoped(&storage, "tenant-channel-allowlist-revision"),
+ scoped(storage.as_ref(), "tenant-channel-allowlist-revision"),
Scope::new("tenant-channel-allowlist-revision").unwrap(),
keys(20),
);
@@ -194,7 +194,7 @@ async fn recovery_restores_the_bootstrap_file_when_document_cas_conflicts() {
std::fs::rename(&recovered.config_path, &corrupted).unwrap();
let _forced = ForcedDocumentSource::new(
- scoped(&storage, "tenant-recovery-cas"),
+ scoped(storage.as_ref(), "tenant-recovery-cas"),
Scope::new("tenant-recovery-cas").unwrap(),
keys(21),
);