Skip to content

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

test(saas): cover per-user thread isolation end to end

Steven Enamakel6676b48dad2b
diff --git a/tests/saas_mode_e2e.rs b/tests/saas_mode_e2e.rs
index 62c4d2207d..32d130d62a 100644
--- a/tests/saas_mode_e2e.rs
+++ b/tests/saas_mode_e2e.rs
@@ -289,6 +289,18 @@ fn user_rpc(
user: &str,
sig: Option<&str>,
method: &str,
+) -> (u16, Value) {
+ user_rpc_with(client, base, bearer, user, sig, method, json!({}))
+}
+
+fn user_rpc_with(
+ client: &reqwest::blocking::Client,
+ base: &str,
+ bearer: &str,
+ user: &str,
+ sig: Option<&str>,
+ method: &str,
+ params: Value,
) -> (u16, Value) {
use openhuman_core::user_agents::gateway::{sign, USER_HEADER, USER_SIG_HEADER};
let signature = sig
@@ -299,7 +311,7 @@ fn user_rpc(
.bearer_auth(bearer)
.header(USER_HEADER, user)
.header(USER_SIG_HEADER, signature)
- .json(&json!({ "jsonrpc": "2.0", "id": 1, "method": method, "params": {} }))
+ .json(&json!({ "jsonrpc": "2.0", "id": 1, "method": method, "params": params }))
.send()
.expect("POST /rpc");
let status = response.status().as_u16();
@@ -409,3 +421,83 @@ fn gateway_requests_run_under_the_named_users_agent() {
);
drop(server);
}
+
+fn provision(client: &reqwest::blocking::Client, base: &str, user: &str) -> String {
+ let (_, body) = rpc_with(
+ client,
+ base,
+ Some(BEARER),
+ "openhuman.user_agents_provision",
+ json!({ "user_id": user }),
+ );
+ assert!(body.get("result").is_some(), "provision {user}: {body}");
+ openhuman_core::user_agents::UserAgentId::for_user(user)
+ .unwrap()
+ .to_string()
+}
+
+fn thread_ids(body: &Value) -> Vec<String> {
+ let text = body.to_string();
+ let mut ids = Vec::new();
+ for part in text.split("\"id\":\"").skip(1) {
+ if let Some(end) = part.find('"') {
+ ids.push(part[..end].to_string());
+ }
+ }
+ ids
+}
+
+#[test]
+fn each_user_sees_only_their_own_threads() {
+ let d = deployment(true);
+ let (server, base, client) = start(&d);
+ let alice = provision(&client, &base, "alice");
+ let bob = provision(&client, &base, "bob");
+ let call = |user: &str, method: &str, params: Value| {
+ user_rpc_with(&client, &base, BEARER, user, None, method, params)
+ };
+
+ let (status, body) = call("alice", "openhuman.threads_create_new", json!({}));
+ assert_eq!(status, 200, "{body}");
+ assert!(body.get("result").is_some(), "{body}");
+
+ // The same caller-chosen id in two users' scopes is two threads.
+ for user in ["alice", "bob"] {
+ let (_, body) = call(
+ user,
+ "openhuman.threads_upsert",
+ json!({ "id": "shared-id", "title": format!("{user}'s"), "created_at": "2026-10-07T00:00:00Z" }),
+ );
+ assert!(body.get("result").is_some(), "{user} upsert: {body}");
+ }
+
+ let (_, alice_list) = call("alice", "openhuman.threads_list", json!({}));
+ let (_, bob_list) = call("bob", "openhuman.threads_list", json!({}));
+ let alice_ids = thread_ids(&alice_list);
+ let bob_ids = thread_ids(&bob_list);
+ assert_eq!(alice_ids.len(), 2, "alice: {alice_list}");
+ assert_eq!(bob_ids, vec!["shared-id".to_string()], "bob: {bob_list}");
+ assert!(bob_list.to_string().contains("bob's"), "{bob_list}");
+ assert!(!bob_list.to_string().contains("alice's"), "{bob_list}");
+
+ // Each user's threads live in their own workspace.
+ for (agent, owner) in [(&alice, "alice"), (&bob, "bob")] {
+ let threads = d.root.join("agents").join(agent).join("workspace");
+ assert!(threads.is_dir(), "{owner}'s workspace");
+ }
+ assert!(!d.root.join("operator").join("workspace").join("memory").join("conversations").join("threads.jsonl").exists(),
+ "no user thread lands in the operator workspace");
+
+ // Reserved and path-like ids are refused; turn-starting methods are closed.
+ for id in ["channel:telegram/1", "../escape"] {
+ let (_, body) = call(
+ "alice",
+ "openhuman.threads_upsert",
+ json!({ "id": id, "title": "x", "created_at": "2026-10-07T00:00:00Z" }),
+ );
+ assert!(body.get("error").is_some(), "{id}: {body}");
+ }
+ let (_, body) = call("alice", "openhuman.threads_regenerate", json!({}));
+ assert!(body.get("error").is_some(), "{body}");
+ drop(server);
+}