Skip to content

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

test(memory): hosted graph and folder sync end to end

Shanu81911fc405eb
diff --git a/tests/memory_hosted_surface_e2e.rs b/tests/memory_hosted_surface_e2e.rs
index d610e49d73..e82cefedc1 100644
--- a/tests/memory_hosted_surface_e2e.rs
+++ b/tests/memory_hosted_surface_e2e.rs
@@ -5,10 +5,14 @@
//! `memory_graph_roundtrip_e2e`, `memory_tree_health_e2e`) run on the local
//! module, whose engine serves every family. The hosted engine serves the
//! mandatory families, ingestion and answers, and goals, tool rules, documents,
-//! the source sink and maintenance (tinymemory's hosted-families spec); this
-//! suite holds it to what that means for a user: what it serves works, what it
-//! does not serve answers a clean refusal rather than failing some other way,
-//! auto-recall reaches the notes a user saved, and a refused lookup says why.
+//! the source sink, maintenance, retrieval, ingest, profile, episodic memory,
+//! scoring and a tree drawn from the server's understanding (tinymemory's
+//! hosted-families spec); local sources are synced by the host through its
+//! sink. This suite holds it to what that means for a user: what it serves
+//! works, what it does not serve answers a clean refusal rather than failing
+//! some other way, auto-recall reaches the notes a user saved, a refused lookup
+//! says why, the Brain graph draws what the server understood, and a synced
+//! folder reaches hosted memory.
//!
//! ```text
//! RUST_MIN_STACK=67108864 cargo test -p openhuman-cli \
@@ -138,6 +142,101 @@ fn sync_history_answers_from_the_host_log_on_an_engine_without_one() {
});
}
+/// The Brain graph on hosted memory is the server's understanding: a fact it
+/// derived from the user's notes is a node labelled by what it says, under
+/// the namespace it came from, named for what that holds.
+#[test]
+fn the_hosted_engine_draws_the_brain_graph_from_its_understanding() {
+ run_on_big_stack("hosted-graph", || async {
+ let fx = Fixture::new().await;
+ bind_hosted(&fx).await;
+ fx.hosted.layers.lock().unwrap().insert(
+ ("facts".to_string(), "tm:global".to_string()),
+ vec![json!({
+ "id": "fact_tea",
+ "scope": "tm:global",
+ "subject": { "type": "entity", "id": "ent_user", "name": "User" },
+ "predicate": "prefers",
+ "object": { "type": "literal", "datatype": "string", "value": "oolong tea" },
+ "supports": [],
+ "confidence": 0.9,
+ "valid_from": "2026-09-01T00:00:00Z",
+ "recorded_from": "2026-09-01T00:00:00Z",
+ })],
+ );
+ let v = fx
+ .call(
+ "openhuman.memory_tree_graph_export",
+ json!({ "mode": "tree" }),
+ )
+ .await;
+ let graph = result_of(&v, "graph export on hosted");
+ let labels: Vec<&str> = graph["nodes"]
+ .as_array()
+ .expect("nodes")
+ .iter()
+ .filter_map(|node| node["label"].as_str())
+ .collect();
+ assert!(labels.contains(&"User prefers oolong tea"), "{graph}");
+ assert!(
+ labels.contains(&"Memory"),
+ "the global namespace reads as what it holds: {graph}"
+ );
+ unbind(&fx).await;
+ });
+}
+
+/// A folder source on hosted memory is read by the host and sent through the
+/// engine's sink, and the run lands in Sync History like any other.
+#[test]
+fn a_local_folder_syncs_into_hosted_memory() {
+ run_on_big_stack("hosted-folder-sync", || async {
+ let fx = Fixture::new().await;
+ bind_hosted(&fx).await;
+ let folder = fx._tmp.path().join("notes");
+ std::fs::create_dir_all(&folder).expect("folder");
+ std::fs::write(folder.join("tea.md"), "# Tea\n\nOolong, always.").expect("note");
+ let v = fx
+ .call(
+ "openhuman.memory_sources_add",
+ json!({
+ "kind": "folder",
+ "label": "Notes",
+ "enabled": true,
+ "path": folder.to_string_lossy(),
+ }),
+ )
+ .await;
+ let source_id = result_of(&v, "add a folder source")["source"]["id"]
+ .as_str()
+ .expect("a source id")
+ .to_string();
+ let v = fx
+ .call(
+ "openhuman.memory_sources_sync",
+ json!({ "source_id": source_id }),
+ )
+ .await;
+ result_of(&v, "sync a folder on hosted");
+ let synced = fx.hosted.events.lock().unwrap().iter().any(|event| {
+ event["scope"] == "tm:sources/tm:documents"
+ && event["content"]["text"]
+ .as_str()
+ .is_some_and(|text| text.contains("Oolong, always."))
+ });
+ assert!(synced, "the note reaches the hosted documents namespace");
+ let v = fx
+ .call("openhuman.memory_sources_sync_audit_log", json!({}))
+ .await;
+ let history = result_of(&v, "sync history after a hosted folder sync");
+ assert!(
+ history["entries"].to_string().contains(&source_id),
+ "{history}"
+ );
+ unbind(&fx).await;
+ });
+}
+
/// The first `documentId` anywhere in `value`.
fn document_id(value: &serde_json::Value) -> Option<String> {
match value {
diff --git a/tests/support/memory_engine_fixture.rs b/tests/support/memory_engine_fixture.rs
index 7b7a9ffea8..44729d83ff 100644
--- a/tests/support/memory_engine_fixture.rs
+++ b/tests/support/memory_engine_fixture.rs
@@ -45,6 +45,9 @@ pub struct HostedState {
pub force_status: AtomicU16,
/// Milliseconds every `experience` write is delayed by (0 = none).
pub delay_ms: AtomicU64,
+ /// What `GET /memory/{facts,beliefs,understanding}` answers, by
+ /// `(layer, scope)`.
+ pub layers: Mutex<std::collections::HashMap<(String, String), Vec<Value>>>,
}
pub type Hosted = Arc<HostedState>;
@@ -201,12 +204,37 @@ pub async fn recall(
}
let scope = body["scope"].as_str().unwrap_or_default();
let query = body["query"].as_str().unwrap_or_default().to_lowercase();
+ // `descend` recalls the scope and everything under it.
+ let descend = body["view"].as_str() == Some("descend");
+ // A metadata label filter keeps an event carrying any one of the labels.
+ let wanted: Vec<&str> = body
+ .pointer("/filters/metadata/labels")
+ .and_then(Value::as_array)
+ .map(|labels| labels.iter().filter_map(Value::as_str).collect())
+ .unwrap_or_default();
+ let budget = body
+ .pointer("/budgets/per_layer_limits/events")
+ .and_then(Value::as_u64)
+ .map_or(usize::MAX, |limit| limit as usize);
let hits: Vec<Value> = state
.events
.lock()
.unwrap()
.iter()
- .filter(|e| e["scope"].as_str() == Some(scope))
+ .filter(|e| {
+ e["scope"].as_str().is_some_and(|held| {
+ held == scope || (descend && held.starts_with(&format!("{scope}/")))
+ })
+ })
+ .filter(|e| {
+ wanted.is_empty()
+ || e["context"]["labels"].as_array().is_some_and(|labels| {
+ labels
+ .iter()
+ .filter_map(Value::as_str)
+ .any(|label| wanted.contains(&label))
+ })
+ })
.filter(|e| {
query.is_empty()
|| e["content"]["text"]
@@ -220,6 +248,7 @@ pub async fn recall(
}
hit
})
+ .take(budget)
.collect();
ok(json!({ "pack_id": "pack_test", "layers": { "events": hits } }))
}
@@ -303,6 +332,33 @@ pub async fn forget(
ok(json!({ "deleted": { "events": deleted }, "requested": ids.len(), "matched": deleted }))
}
+/// One page of a derived layer: everything seeded for the scope, in one page.
+pub async fn layer(
+ State(state): State<Hosted>,
+ headers: HeaderMap,
+ uri: axum::http::Uri,
+ Query(params): Query<std::collections::BTreeMap<String, String>>,
+) -> (StatusCode, Json<Value>) {
+ if let Some(early) = gate(&state, &headers) {
+ return early;
+ }
+ let name = uri
+ .path()
+ .rsplit('/')
+ .next()
+ .unwrap_or_default()
+ .to_string();
+ let scope = params.get("scope").cloned().unwrap_or_default();
+ let items = state
+ .layers
+ .lock()
+ .unwrap()
+ .get(&(name, scope))
+ .cloned()
+ .unwrap_or_default();
+ ok(json!({ "items": items, "has_more": false }))
+}
+
pub async fn start_hosted() -> (String, Hosted) {
let state: Hosted = Arc::new(HostedState::default());
let app = Router::new()
@@ -312,6 +368,9 @@ pub async fn start_hosted() -> (String, Hosted) {
.route("/memory/recall", post(recall))
.route("/memory/forget", post(forget))
.route("/memory/scopes", get(scopes))
+ .route("/memory/facts", get(layer))
+ .route("/memory/beliefs", get(layer))
+ .route("/memory/understanding", get(layer))
.with_state(state.clone());
let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
let addr: SocketAddr = listener.local_addr().unwrap();