diff --git a/crates/openhuman-core/src/modules/storage_grant_schemas.rs b/crates/openhuman-core/src/modules/storage_grant_schemas.rs index 18d8575b4ac..974bae47a67 100644 --- a/crates/openhuman-core/src/modules/storage_grant_schemas.rs +++ b/crates/openhuman-core/src/modules/storage_grant_schemas.rs @@ -166,6 +166,8 @@ pub(super) fn grant_for(module_id: &str) -> Option { fn read_collections(owner: &str) -> Vec { match owner { "connectors" => tinyconnectors_bus::storage::storage_needs().collections, + // TinyWallet's x402 ledger migrates its v1 budget holds on first open. + "wallet" => vec![tinywallet::LEGACY_BUDGET_COLLECTION.to_owned()], _ => Vec::new(), } } @@ -175,8 +177,12 @@ fn stream_prefixes(owner: &str) -> Vec { "mcp" => vec![tinymcp_bus::storage::AUDIT_STREAM.to_owned()], "connectors" => tinyconnectors_bus::storage::storage_needs().stream_prefixes, // TinyWallet's module still reads and appends this released ledger - // stream while its bus contract currently declares collections only. - "wallet" => vec!["wallet.payments".to_owned()], + // stream while its bus contract currently declares collections only, + // and its x402 ledger migration reads the v1 stream the importer fills. + "wallet" => vec![ + "wallet.payments".to_owned(), + tinywallet::PAYMENTS_STREAM.to_owned(), + ], _ => Vec::new(), } } @@ -210,6 +216,8 @@ pub(super) mod tinywallet { pub(crate) const MODULE_ID: &str = "tinywallet"; /// The v1 payments stream the importer writes. pub(crate) const PAYMENTS_STREAM: &str = "x402.payments"; + /// The v1 budget-hold collection the module's x402 ledger migration reads. + pub(crate) const LEGACY_BUDGET_COLLECTION: &str = "x402_budget"; } pub(super) mod tinybox { diff --git a/crates/openhuman-core/src/modules/storage_grant_schemas_tests.rs b/crates/openhuman-core/src/modules/storage_grant_schemas_tests.rs index 27eb785bfd2..b81d77bf162 100644 --- a/crates/openhuman-core/src/modules/storage_grant_schemas_tests.rs +++ b/crates/openhuman-core/src/modules/storage_grant_schemas_tests.rs @@ -206,6 +206,89 @@ fn non_document_grants_match_the_owner_contracts_without_broad_prefixes() { ); } +/// Every call TinyWallet's x402 ledger makes when it opens (its own migration, +/// `tinywallet-x402/src/ledger/schema.rs` `migrate`) and afterwards +/// (`ledger/persist.rs`). The migration runs on every first open, whether or +/// not a wallet exists and whether or not there is legacy data, so a target +/// missing here fails every `x402_fetch` with `target-not-granted`. +#[cfg(feature = "web3")] +#[test] +fn the_wallet_grant_covers_every_target_its_x402_ledger_opens_and_migrates() { + let wallet = declared(tinywallet::MODULE_ID).unwrap(); + let calls = [ + // Migration state. + ( + Object::Documents, + "Get", + json!({"collection": "wallet.migrations", "id": "x402"}), + ), + ( + Object::Documents, + "Put", + json!({"collection": "wallet.migrations", "id": "x402"}), + ), + // v1 budget holds, read and carried into `wallet.budgets`. + ( + Object::Documents, + "Get", + json!({"collection": "x402_budget", "id": "holds"}), + ), + ( + Object::Documents, + "Get", + json!({"collection": "wallet.budgets", "id": "holds"}), + ), + ( + Object::Documents, + "Put", + json!({"collection": "wallet.budgets", "id": "holds"}), + ), + // v1 payments (what the host importer writes), copied to `wallet.payments`. + (Object::Streams, "Len", json!({"stream": "x402.payments"})), + ( + Object::Streams, + "ReadWindow", + json!({"stream": "x402.payments"}), + ), + (Object::Streams, "Len", json!({"stream": "wallet.payments"})), + ( + Object::Streams, + "ReadWindow", + json!({"stream": "wallet.payments"}), + ), + ( + Object::Streams, + "AppendBatchIfOffset", + json!({"stream": "wallet.payments"}), + ), + ( + Object::Streams, + "Append", + json!({"stream": "wallet.payments"}), + ), + ]; + for (object, selector, request) in calls { + assert_eq!( + authorize(&wallet, object, selector, &request).map(|_| ()), + Ok(()), + "{object:?}.{selector} {request}" + ); + } + // The migration's own `ensure_collection` calls repeat the host's specs. + for name in ["wallet.budgets", "wallet.migrations"] { + let spec = serde_json::to_value(CollectionSpec::new(name)).unwrap(); + assert!(matches!( + authorize( + &wallet, + Object::Documents, + "EnsureCollection", + &json!({"spec": spec}) + ), + Ok(Plan::Answer(_)) + )); + } +} + #[test] fn connectors_may_read_the_v1_preferences_its_migration_moves() { let connectors = declared("tinyconnectors").unwrap(); diff --git a/scripts/ci/check-gated-test-allowlist.sh b/scripts/ci/check-gated-test-allowlist.sh index 8a2ec3e29cc..af6397ac249 100755 --- a/scripts/ci/check-gated-test-allowlist.sh +++ b/scripts/ci/check-gated-test-allowlist.sh @@ -106,6 +106,7 @@ integrations/composio/ops/mod.rs integrations/composio/client.rs mcp/server/resources_tests.rs modules/tinyflows.rs +modules/storage_grant_schemas_tests.rs doctor/checks/channels.rs doctor/checks/inference_tests.rs doctor/checks/mcp.rs