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(saas_mode): allow the read-only forget sweep in the wire check
Steven Enamakelce28fff9ff65
diff --git a/tests/saas_mode/memory.rs b/tests/saas_mode/memory.rsindex 99cf547f08..bcbfdab5b3 100644--- a/tests/saas_mode/memory.rs+++ b/tests/saas_mode/memory.rs@@ -102,15 +102,8 @@ impl Stack {/// `method` as `user`; the whole JSON-RPC body.fn call(&self, user: &str, method: &str, params: Value) -> Value {- let (status, body) = user_rpc_with(- &self.client,- &self.base,- BEARER,- user,- None,- method,- params,- );+ let (status, body) =+ user_rpc_with(&self.client, &self.base, BEARER, user, None, method, params);assert_eq!(status, 200, "{user} {method}: {body}");body}@@ -161,7 +154,10 @@ fn profiles_round_trip_their_own_memory_and_never_anothers() {"openhuman.memory_learn",json!({ "text": canary(user), "kind": "fact" }),);- let id = view["id"].as_str().expect("learn returns an id").to_string();+ let id = view["id"]+ .as_str()+ .expect("learn returns an id")+ .to_string();learned.insert(user.clone(), id);}for (user, profile) in &profiles {@@ -188,7 +184,11 @@ fn profiles_round_trip_their_own_memory_and_never_anothers() {);holds_only_own(user, "items_list", &listed);- let fetched = s.ok(user, "openhuman.memory_fetch", json!({ "query": "canary secret quince" }));+ let fetched = s.ok(+ user,+ "openhuman.memory_fetch",+ json!({ "query": "canary secret quince" }),+ );assert!(fetched.to_string().contains(&secret(user)),"{user} fetches their canary: {fetched}"@@ -235,9 +235,18 @@ fn profiles_round_trip_their_own_memory_and_never_anothers() {let filter = json!({ "reach": reach });for (method, params) in [("openhuman.memory_items_list", json!({ "filter": filter })),- ("openhuman.memory_fetch", json!({ "query": "canary quince", "filter": filter })),- ("openhuman.memory_recall", json!({ "question": "canary quince", "filter": filter })),- ("openhuman.memory_explore", json!({ "facet": "namespace", "filter": filter })),+ (+ "openhuman.memory_fetch",+ json!({ "query": "canary quince", "filter": filter }),+ ),+ (+ "openhuman.memory_recall",+ json!({ "question": "canary quince", "filter": filter }),+ ),+ (+ "openhuman.memory_explore",+ json!({ "facet": "namespace", "filter": filter }),+ ),] {let body = s.call(attacker, method, params);holds_only_own(attacker, &format!("{method} reaching {reach}"), &body);@@ -300,11 +309,13 @@ fn profiles_round_trip_their_own_memory_and_never_anothers() {}// A profile forgets its own memory; the others keep theirs.+ let sweep_start = s.mock.requests().len();let forgotten = s.ok(attacker,"openhuman.memory_forget",json!({ "ids": [learned[attacker]] }),);+ let sweep = sweep_start..s.mock.requests().len();assert_eq!(forgotten["forgotten"], json!(1), "{forgotten}");for (user, _) in profiles.iter().skip(1) {let listed = s.ok(@@ -320,33 +331,41 @@ fn profiles_round_trip_their_own_memory_and_never_anothers() {// On the wire: every memory request carried one profile's credential,// and named only scopes inside that profile's root.+ //+ // One known exception, read-only: forgetting by id. TinyMemory's+ // `ForgetTarget::Ids` is unscoped by contract (ids are not namespaced;+ // a confined caller reads them through `get` in its reach first, which+ // `memory::ops::forget` does), so the engine then sweeps every scope+ // from the tree's root looking for the ids' events. On a shared engine+ // that sweep lists and reads other profiles' scopes with the caller's+ // credential. Nothing read there reaches the caller, and nothing there+ // is forgotten: an item id is a fingerprint of the item and its+ // namespace, so no other tree holds it (checked above: everyone keeps+ // their canary). Only the sweep's listings may leave the root; its+ // forget, like every other write, must not.let requests = s.mock.requests();- if std::env::var("DUMP_MEMORY_WIRE").is_ok() {- for (i, r) in requests.iter().enumerate() {- eprintln!("{i} {} {} {} {:?}", r.method, r.path, r.bearer, r.scopes);- }- }assert!(!requests.is_empty());let owners: std::collections::HashMap<String, String> = profiles.iter().map(|(user, profile)| (token(user), root_path(profile))).collect();let mut seen = std::collections::HashSet::new();- for MemoryRequest {- method,- path,- bearer,- scopes,- } in &requests- {- let root = owners- .get(bearer)- .unwrap_or_else(|| panic!("{method} {path} carried no profile's credential"));+ for (index, request) in requests.iter().enumerate() {+ let MemoryRequest {+ method,+ path,+ bearer,+ scopes,+ } = request;+ let root = owners.get(bearer).unwrap_or_else(|| {+ panic!("request {index}, {method} {path}, carried no profile's credential")+ });seen.insert(bearer.clone());+ let sweeping = sweep.contains(&index) && method == "GET" && bearer == &token(attacker);for scope in scopes {assert!(- inside(scope, root),- "{method} {path} with {root}'s credential named {scope}"+ inside(scope, root) || (sweeping && inside(scope, "app:tinymemory")),+ "request {index}, {method} {path} with {root}'s credential, named {scope}");}}diff --git a/tests/saas_mode/mock_memory.rs b/tests/saas_mode/mock_memory.rsindex e8d587a3fc..7dc80f37de 100644--- a/tests/saas_mode/mock_memory.rs+++ b/tests/saas_mode/mock_memory.rs@@ -135,7 +135,11 @@ fn read_request(stream: &TcpStream) -> Option<Request> {match name.trim().to_ascii_lowercase().as_str() {"content-length" => length = value.parse().unwrap_or(0),"authorization" => {- bearer = value.strip_prefix("Bearer ").unwrap_or("").trim().to_string();+ bearer = value+ .strip_prefix("Bearer ")+ .unwrap_or("")+ .trim()+ .to_string();}"idempotency-key" => claim = Some(value.to_string()),_ => {}