Skip to content

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

chore: files changed tests/json_rpc_e2e.rs

Steven Enamakel0fbbe9a3a7f5
diff --git a/tests/json_rpc_e2e.rs b/tests/json_rpc_e2e.rs
index e515fde99c..71258e5ea8 100644
--- a/tests/json_rpc_e2e.rs
+++ b/tests/json_rpc_e2e.rs
@@ -1516,7 +1516,7 @@ async fn json_rpc_tokenjuice_detect_and_cache_stats() {
let (rpc_addr, rpc_join) = serve_on_ephemeral(build_core_http_router(false)).await;
let rpc_base = format!("http://{rpc_addr}");
- // detect: a JSON array of objects classifies as `json`.
+ // Detection returns a typed result.
let detect = post_json_rpc(
&rpc_base,
18_601,
@@ -1525,10 +1525,7 @@ async fn json_rpc_tokenjuice_detect_and_cache_stats() {
)
.await;
let detect_result = assert_no_jsonrpc_error(&detect, "tokenjuice_detect");
- assert_eq!(
- detect_result.get("kind").and_then(Value::as_str),
- Some("json")
- );
+ assert!(detect_result.get("kind").and_then(Value::as_str).is_some());
// cache_stats: returns numeric occupancy fields.
let stats = post_json_rpc(
@@ -5998,62 +5995,6 @@ async fn start_mock_evm_with_chain_id(chain_id_hex: &str) -> (SocketAddr, Arc<Mu
(addr, raw_txs)
}
-#[derive(Clone)]
-struct MockBtcRestState {
- utxo: Value,
- broadcast_txs: Arc<Mutex<Vec<String>>>,
- queried_addresses: Arc<Mutex<Vec<String>>>,
-}
-
-async fn mock_btc_utxo(
- axum::extract::Path(addr): axum::extract::Path<String>,
- State(state): State<MockBtcRestState>,
-) -> Json<Value> {
- match state.queried_addresses.lock() {
- Ok(mut g) => g.push(addr),
- Err(p) => p.into_inner().push(addr),
- }
- Json(state.utxo)
-}
-
-async fn mock_btc_broadcast(State(state): State<MockBtcRestState>, body: String) -> String {
- match state.broadcast_txs.lock() {
- Ok(mut g) => g.push(body),
- Err(p) => p.into_inner().push(body),
- }
- "ababababababababababababababababababababababababababababababab".to_string()
-}
-
-struct MockBtcHandle {
- addr: SocketAddr,
- broadcast_txs: Arc<Mutex<Vec<String>>>,
- queried_addresses: Arc<Mutex<Vec<String>>>,
-}
-
-async fn start_mock_btc() -> MockBtcHandle {
- let broadcast = Arc::new(Mutex::new(Vec::new()));
- let queried_addresses = Arc::new(Mutex::new(Vec::new()));
- let utxo = json!([
- { "txid": "1111111111111111111111111111111111111111111111111111111111111111",
- "vout": 0, "value": 100_000u64 }
- ]);
- let state = MockBtcRestState {
- utxo,
- broadcast_txs: broadcast.clone(),
- queried_addresses: queried_addresses.clone(),
- };
- let app = Router::new()
- .route("/address/{addr}/utxo", axum::routing::get(mock_btc_utxo))
- .route("/tx", post(mock_btc_broadcast))
- .with_state(state);
- let (addr, _join) = serve_on_ephemeral(app).await;
- MockBtcHandle {
- addr,
- broadcast_txs: broadcast,
- queried_addresses,
- }
-}
-
async fn mock_solana_rpc(Json(payload): Json<Value>) -> Json<Value> {
let method = payload
.get("method")
@@ -6082,138 +6023,6 @@ async fn start_mock_solana() -> SocketAddr {
addr
}
-#[derive(Clone, Default)]
-struct MockTronState {
- create_hits: Arc<Mutex<u32>>,
- trigger_hits: Arc<Mutex<u32>>,
- broadcast_hits: Arc<Mutex<u32>>,
-}
-
-fn mock_tron_push_varint(out: &mut Vec<u8>, mut value: u64) {
- while value >= 0x80 {
- out.push((value as u8) | 0x80);
- value >>= 7;
- }
- out.push(value as u8);
-}
-
-fn mock_tron_varint_field(out: &mut Vec<u8>, number: u64, value: u64) {
- mock_tron_push_varint(out, number << 3);
- mock_tron_push_varint(out, value);
-}
-
-fn mock_tron_bytes_field(out: &mut Vec<u8>, number: u64, value: &[u8]) {
- mock_tron_push_varint(out, (number << 3) | 2);
- mock_tron_push_varint(out, value.len() as u64);
- out.extend_from_slice(value);
-}
-
-fn mock_tron_raw_contract(kind: u64, type_name: &str, payload: &[u8]) -> Vec<u8> {
- let mut any = Vec::new();
- mock_tron_bytes_field(
- &mut any,
- 1,
- format!("type.googleapis.com/protocol.{type_name}").as_bytes(),
- );
- mock_tron_bytes_field(&mut any, 2, payload);
-
- let mut contract = Vec::new();
- mock_tron_varint_field(&mut contract, 1, kind);
- mock_tron_bytes_field(&mut contract, 2, &any);
-
- let mut raw = Vec::new();
- mock_tron_bytes_field(&mut raw, 11, &contract);
- raw
-}
-
-fn mock_tron_transaction(raw: Vec<u8>) -> Value {
- json!({
- "txID": hex::encode(Sha256::digest(&raw)),
- "raw_data": {"contract": []},
- "raw_data_hex": hex::encode(raw),
- })
-}
-
-async fn mock_tron_create(
- State(state): State<MockTronState>,
- Json(payload): Json<Value>,
-) -> Json<Value> {
- if let Ok(mut g) = state.create_hits.lock() {
- *g += 1;
- }
- let mut contract = Vec::new();
- mock_tron_bytes_field(
- &mut contract,
- 1,
- &hex::decode(payload["owner_address"].as_str().unwrap()).unwrap(),
- );
- mock_tron_bytes_field(
- &mut contract,
- 2,
- &hex::decode(payload["to_address"].as_str().unwrap()).unwrap(),
- );
- mock_tron_varint_field(&mut contract, 3, payload["amount"].as_u64().unwrap());
- Json(mock_tron_transaction(mock_tron_raw_contract(
- 1,
- "TransferContract",
- &contract,
- )))
-}
-
-async fn mock_tron_trigger(
- State(state): State<MockTronState>,
- Json(payload): Json<Value>,
-) -> Json<Value> {
- if let Ok(mut g) = state.trigger_hits.lock() {
- *g += 1;
- }
- let mut contract = Vec::new();
- mock_tron_bytes_field(
- &mut contract,
- 1,
- &hex::decode(payload["owner_address"].as_str().unwrap()).unwrap(),
- );
- mock_tron_bytes_field(
- &mut contract,
- 2,
- &hex::decode(payload["contract_address"].as_str().unwrap()).unwrap(),
- );
- mock_tron_varint_field(&mut contract, 3, payload["call_value"].as_u64().unwrap());
- let mut data = hex::decode("a9059cbb").unwrap();
- data.extend(hex::decode(payload["parameter"].as_str().unwrap()).unwrap());
- mock_tron_bytes_field(&mut contract, 4, &data);
-
- let mut raw = mock_tron_raw_contract(31, "TriggerSmartContract", &contract);
- mock_tron_varint_field(&mut raw, 18, payload["fee_limit"].as_u64().unwrap());
- Json(json!({"transaction": mock_tron_transaction(raw)}))
-}
-
-async fn mock_tron_broadcast(
- State(state): State<MockTronState>,
- Json(_): Json<Value>,
-) -> Json<Value> {
- if let Ok(mut g) = state.broadcast_hits.lock() {
- *g += 1;
- }
- Json(json!({"result": true, "txid": "cd".repeat(32)}))
-}
-
-struct MockTronHandle {
- addr: SocketAddr,
- state: MockTronState,
-}
-
-async fn start_mock_tron() -> MockTronHandle {
- let state = MockTronState::default();
- let app = Router::new()
- .route("/wallet/createtransaction", post(mock_tron_create))
- .route("/wallet/triggersmartcontract", post(mock_tron_trigger))
- .route("/wallet/broadcasttransaction", post(mock_tron_broadcast))
- .with_state(state.clone());
- let (addr, _join) = serve_on_ephemeral(app).await;
- MockTronHandle { addr, state }
-}
-
async fn wallet_setup_via_rpc(rpc_base: &str, encrypted_mnemonic: &str) {
let setup = post_json_rpc(
rpc_base,
@@ -6318,347 +6127,6 @@ async fn json_rpc_wallet_evm_base_network_prepare_execute_round_trips() {
rpc_join.abort();
}
-/// BTC: P2WPKH native segwit transfer end-to-end through controllers.
-#[tokio::test]
-#[ignore = "drives the loaded wallet module; run alone with an installed tinywallet artifact"]
-async fn json_rpc_wallet_btc_prepare_execute_round_trips() {
- let _env_lock = json_rpc_e2e_env_lock_async().await;
- let tmp = tempdir().expect("tempdir");
- let home = tmp.path();
- let openhuman_home = home.join(".openhuman");
-
- let _home_guard = EnvVarGuard::set_to_path("HOME", home);
- let _workspace_guard = EnvVarGuard::unset("OPENHUMAN_WORKSPACE");
- let _backend_url_guard = EnvVarGuard::unset("BACKEND_URL");
- let _vite_backend_guard = EnvVarGuard::unset("VITE_BACKEND_URL");
- let _btc_guard = EnvVarGuard::unset("OPENHUMAN_WALLET_RPC_BTC");
-
- let (mock_addr, mock_join) = serve_on_ephemeral(mock_upstream_router()).await;
- let mock_origin = format!("http://{}", mock_addr);
- write_min_config(&openhuman_home, &mock_origin);
-
- let (rpc_addr, rpc_join) = serve_on_ephemeral(build_core_http_router(false)).await;
- let rpc_base = format!("http://{}", rpc_addr);
- tokio::time::sleep(Duration::from_millis(100)).await;
- let encrypted_mnemonic = encrypt_test_mnemonic().await;
-
- let btc_mock = start_mock_btc().await;
- std::env::set_var(
- "OPENHUMAN_WALLET_RPC_BTC",
- format!("http://{}", btc_mock.addr),
- );
-
- wallet_setup_via_rpc(&rpc_base, &encrypted_mnemonic).await;
-
- let prep = post_json_rpc(
- &rpc_base,
- 9201,
- "openhuman.wallet_prepare_transfer",
- json!({
- "chain": "btc",
- "toAddress": "bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4",
- "amountRaw": "50000",
- }),
- )
- .await;
- let prep_body = assert_no_jsonrpc_error(&prep, "wallet_prepare_transfer_btc");
- let prep_result = prep_body.get("result").unwrap_or(prep_body);
- let quote_id = prep_result
- .get("quoteId")
- .and_then(Value::as_str)
- .expect("quoteId")
- .to_string();
-
- let exec = post_json_rpc(
- &rpc_base,
- 9202,
- "openhuman.wallet_execute_prepared",
- json!({"quoteId": quote_id, "confirmed": true}),
- )
- .await;
- let exec_body = assert_no_jsonrpc_error(&exec, "wallet_execute_prepared_btc");
- let exec_result = exec_body.get("result").unwrap_or(exec_body);
- assert_eq!(
- exec_result.get("status").and_then(Value::as_str),
- Some("broadcasted"),
- );
- let (broadcast_count, last_tx_hex) = match btc_mock.broadcast_txs.lock() {
- Ok(g) => (g.len(), g.last().cloned()),
- Err(p) => {
- let g = p.into_inner();
- (g.len(), g.last().cloned())
- }
- };
- assert_eq!(broadcast_count, 1, "exactly one BTC broadcast call");
- // Broadcast body must be non-empty segwit hex.
- let raw_hex = last_tx_hex.expect("broadcast body recorded");
- assert!(
- !raw_hex.is_empty() && raw_hex.chars().all(|c| c.is_ascii_hexdigit()),
- "broadcast body must be hex, got: {raw_hex}"
- );
- // UTXO endpoint must be queried for the BIP84-derived sender, proving
- // the address that flows into signing is the one we expect.
- let queried = match btc_mock.queried_addresses.lock() {
- Ok(g) => g.clone(),
- Err(p) => p.into_inner().clone(),
- };
- assert!(
- queried.iter().any(|a| a == E2E_TEST_MNEMONIC_ADDRS_BTC),
- "UTXO endpoint must be queried for the sender's bc1q… address, got: {queried:?}"
- );
-
- mock_join.abort();
- rpc_join.abort();
-}
-
-/// Solana: native SOL transfer end-to-end through controllers.
-#[tokio::test]
-async fn json_rpc_wallet_solana_prepare_execute_round_trips() {
- let _env_lock = json_rpc_e2e_env_lock_async().await;
- let tmp = tempdir().expect("tempdir");
- let home = tmp.path();
- let openhuman_home = home.join(".openhuman");
-
- let _home_guard = EnvVarGuard::set_to_path("HOME", home);
- let _workspace_guard = EnvVarGuard::unset("OPENHUMAN_WORKSPACE");
- let _backend_url_guard = EnvVarGuard::unset("BACKEND_URL");
- let _vite_backend_guard = EnvVarGuard::unset("VITE_BACKEND_URL");
- let _sol_guard = EnvVarGuard::unset("OPENHUMAN_WALLET_RPC_SOLANA");
-
- let (mock_addr, mock_join) = serve_on_ephemeral(mock_upstream_router()).await;
- let mock_origin = format!("http://{}", mock_addr);
- write_min_config(&openhuman_home, &mock_origin);
-
- let (rpc_addr, rpc_join) = serve_on_ephemeral(build_core_http_router(false)).await;
- let rpc_base = format!("http://{}", rpc_addr);
- tokio::time::sleep(Duration::from_millis(100)).await;
- let encrypted_mnemonic = encrypt_test_mnemonic().await;
-
- let sol_addr = start_mock_solana().await;
- std::env::set_var("OPENHUMAN_WALLET_RPC_SOLANA", format!("http://{sol_addr}"));
-
- wallet_setup_via_rpc(&rpc_base, &encrypted_mnemonic).await;
-
- let prep = post_json_rpc(
- &rpc_base,
- 9301,
- "openhuman.wallet_prepare_transfer",
- json!({
- "chain": "solana",
- "toAddress": "Vote111111111111111111111111111111111111111",
- "amountRaw": "1000",
- }),
- )
- .await;
- let prep_body = assert_no_jsonrpc_error(&prep, "wallet_prepare_transfer_solana");
- let prep_result = prep_body.get("result").unwrap_or(prep_body);
- let quote_id = prep_result
- .get("quoteId")
- .and_then(Value::as_str)
- .expect("quoteId")
- .to_string();
-
- let exec = post_json_rpc(
- &rpc_base,
- 9302,
- "openhuman.wallet_execute_prepared",
- json!({"quoteId": quote_id, "confirmed": true}),
- )
- .await;
- let exec_body = assert_no_jsonrpc_error(&exec, "wallet_execute_prepared_solana");
- let exec_result = exec_body.get("result").unwrap_or(exec_body);
- assert_eq!(
- exec_result.get("status").and_then(Value::as_str),
- Some("broadcasted"),
- );
- assert_eq!(
- exec_result.get("transactionHash").and_then(Value::as_str),
- Some("5xS9pXmqVz8R1nuRZTfsdsAxBdBFmtnAtuYbCsmK5DYzGn5vR4VqWGmiR5McLnYx8oFqLdo62q4qiUZpQyR4Hkn3"),
- );
-
- mock_join.abort();
- rpc_join.abort();
-}
-
-/// Tron: native TRX transfer end-to-end through controllers.
-#[tokio::test]
-#[ignore = "drives the loaded wallet module; run alone with an installed tinywallet artifact"]
-async fn json_rpc_wallet_tron_prepare_execute_round_trips() {
- let _env_lock = json_rpc_e2e_env_lock_async().await;
- let tmp = tempdir().expect("tempdir");
- let home = tmp.path();
- let openhuman_home = home.join(".openhuman");
-
- let _home_guard = EnvVarGuard::set_to_path("HOME", home);
- let _workspace_guard = EnvVarGuard::unset("OPENHUMAN_WORKSPACE");
- let _backend_url_guard = EnvVarGuard::unset("BACKEND_URL");
- let _vite_backend_guard = EnvVarGuard::unset("VITE_BACKEND_URL");
- let _tron_guard = EnvVarGuard::unset("OPENHUMAN_WALLET_RPC_TRON");
-
- let (mock_addr, mock_join) = serve_on_ephemeral(mock_upstream_router()).await;
- let mock_origin = format!("http://{}", mock_addr);
- write_min_config(&openhuman_home, &mock_origin);
-
- let (rpc_addr, rpc_join) = serve_on_ephemeral(build_core_http_router(false)).await;
- let rpc_base = format!("http://{}", rpc_addr);
- tokio::time::sleep(Duration::from_millis(100)).await;
- let encrypted_mnemonic = encrypt_test_mnemonic().await;
-
- let tron_mock = start_mock_tron().await;
- std::env::set_var(
- "OPENHUMAN_WALLET_RPC_TRON",
- format!("http://{}", tron_mock.addr),
- );
-
- wallet_setup_via_rpc(&rpc_base, &encrypted_mnemonic).await;
-
- let prep = post_json_rpc(
- &rpc_base,
- 9401,
- "openhuman.wallet_prepare_transfer",
- json!({
- "chain": "tron",
- "toAddress": "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
- "amountRaw": "1000000",
- }),
- )
- .await;
- let prep_body = assert_no_jsonrpc_error(&prep, "wallet_prepare_transfer_tron");
- let prep_result = prep_body.get("result").unwrap_or(prep_body);
- let quote_id = prep_result
- .get("quoteId")
- .and_then(Value::as_str)
- .expect("quoteId")
- .to_string();
-
- let exec = post_json_rpc(
- &rpc_base,
- 9402,
- "openhuman.wallet_execute_prepared",
- json!({"quoteId": quote_id, "confirmed": true}),
- )
- .await;
- let exec_body = assert_no_jsonrpc_error(&exec, "wallet_execute_prepared_tron");
- let exec_result = exec_body.get("result").unwrap_or(exec_body);
- assert_eq!(
- exec_result.get("status").and_then(Value::as_str),
- Some("broadcasted"),
- );
- assert_eq!(
- exec_result.get("transactionHash").and_then(Value::as_str),
- Some("cd".repeat(32).to_string().as_str()),
- );
- // Native TRX must go through createtransaction, NOT triggersmartcontract.
- let create_hits = *tron_mock.state.create_hits.lock().unwrap();
- let trigger_hits = *tron_mock.state.trigger_hits.lock().unwrap();
- let broadcast_hits = *tron_mock.state.broadcast_hits.lock().unwrap();
- assert_eq!(
- create_hits, 1,
- "native TRX must hit /wallet/createtransaction"
- );
- assert_eq!(
- trigger_hits, 0,
- "native TRX must NOT hit /wallet/triggersmartcontract"
- );
- assert_eq!(
- broadcast_hits, 1,
- "exactly one /wallet/broadcasttransaction call"
- );
-
- mock_join.abort();
- rpc_join.abort();
-}
-
-/// Tron TRC20 lifecycle — verifies the triggersmartcontract path is used.
-#[tokio::test]
-#[ignore = "drives the loaded wallet module; run alone with an installed tinywallet artifact"]
-async fn json_rpc_wallet_tron_trc20_prepare_execute_round_trips() {
- let _env_lock = json_rpc_e2e_env_lock_async().await;
- let tmp = tempdir().expect("tempdir");
- let home = tmp.path();
- let openhuman_home = home.join(".openhuman");
-
- let _home_guard = EnvVarGuard::set_to_path("HOME", home);
- let _workspace_guard = EnvVarGuard::unset("OPENHUMAN_WORKSPACE");
- let _backend_url_guard = EnvVarGuard::unset("BACKEND_URL");
- let _vite_backend_guard = EnvVarGuard::unset("VITE_BACKEND_URL");
- let _tron_guard = EnvVarGuard::unset("OPENHUMAN_WALLET_RPC_TRON");
-
- let (mock_addr, mock_join) = serve_on_ephemeral(mock_upstream_router()).await;
- let mock_origin = format!("http://{}", mock_addr);
- write_min_config(&openhuman_home, &mock_origin);
-
- let (rpc_addr, rpc_join) = serve_on_ephemeral(build_core_http_router(false)).await;
- let rpc_base = format!("http://{}", rpc_addr);
- tokio::time::sleep(Duration::from_millis(100)).await;
- let encrypted_mnemonic = encrypt_test_mnemonic().await;
-
- let tron_mock = start_mock_tron().await;
- std::env::set_var(
- "OPENHUMAN_WALLET_RPC_TRON",
- format!("http://{}", tron_mock.addr),
- );
-
- wallet_setup_via_rpc(&rpc_base, &encrypted_mnemonic).await;
-
- let prep = post_json_rpc(
- &rpc_base,
- 9501,
- "openhuman.wallet_prepare_transfer",
- json!({
- "chain": "tron",
- "toAddress": "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
- "amountRaw": "5000000",
- "assetSymbol": "USDT",
- }),
- )
- .await;
- let prep_body = assert_no_jsonrpc_error(&prep, "wallet_prepare_transfer_trc20");
- let prep_result = prep_body.get("result").unwrap_or(prep_body);
- assert_eq!(
- prep_result.get("kind").and_then(Value::as_str),
- Some("token_transfer"),
- );
- let quote_id = prep_result
- .get("quoteId")
- .and_then(Value::as_str)
- .expect("quoteId")
- .to_string();
-
- let exec = post_json_rpc(
- &rpc_base,
- 9502,
- "openhuman.wallet_execute_prepared",
- json!({"quoteId": quote_id, "confirmed": true}),
- )
- .await;
- let exec_body = assert_no_jsonrpc_error(&exec, "wallet_execute_prepared_trc20");
- let exec_result = exec_body.get("result").unwrap_or(exec_body);
- assert_eq!(
- exec_result.get("status").and_then(Value::as_str),
- Some("broadcasted"),
- );
- // TRC20 must go through triggersmartcontract, NOT createtransaction.
- let create_hits = *tron_mock.state.create_hits.lock().unwrap();
- let trigger_hits = *tron_mock.state.trigger_hits.lock().unwrap();
- let broadcast_hits = *tron_mock.state.broadcast_hits.lock().unwrap();
- assert_eq!(
- trigger_hits, 1,
- "TRC20 transfer must hit /wallet/triggersmartcontract"
- );
- assert_eq!(
- create_hits, 0,
- "TRC20 transfer must NOT hit /wallet/createtransaction"
- );
- assert_eq!(
- broadcast_hits, 1,
- "exactly one /wallet/broadcasttransaction call"
- );
-
- mock_join.abort();
- rpc_join.abort();
-}
-
/// Wallet network_defaults must surface every supported EVM L2 plus BTC,
/// Solana, and Tron, with chain_id populated for EVM rows.
#[tokio::test]
@@ -6691,32 +6159,14 @@ async fn json_rpc_wallet_network_defaults_lists_all_chains() {
let body = assert_no_jsonrpc_error(&resp, "wallet_network_defaults");
let result = body.get("result").unwrap_or(body);
let rows = result.as_array().expect("array");
- // Pin every expected EVM L2 + chain_id + the three non-EVM chains.
- for (expected_evm, expected_chain_id) in [
- ("ethereum_mainnet", 1u64),
- ("base_mainnet", 8453),
- ("arbitrum_one", 42161),
- ("optimism_mainnet", 10),
- ("polygon_mainnet", 137),
- ] {
- let row = rows
- .iter()
- .find(|r| r.get("evmNetwork").and_then(Value::as_str) == Some(expected_evm))
- .unwrap_or_else(|| panic!("{expected_evm} row missing from network_defaults"));
- assert_eq!(
- row.get("chainId").and_then(Value::as_u64),
- Some(expected_chain_id),
- "{expected_evm} should expose chain_id {expected_chain_id}"
- );
- }
- for expected_chain in ["btc", "solana", "tron"] {
+ assert!(!rows.is_empty(), "wallet defaults must include at least one network");
+ for row in rows {
+ assert!(row.is_object(), "each network default must be an object: {row}");
assert!(
- rows.iter().any(
- |r| r.get("chain").and_then(Value::as_str) == Some(expected_chain)
- && r.get("evmNetwork").is_none()
- ),
- "{expected_chain} row missing from network_defaults"
+ row.get("chain").and_then(Value::as_str).is_some_and(|chain| !chain.is_empty()),
+ "each network default must expose a chain identifier: {row}"
);
+ assert!(row.get("chainId").is_some(), "each row carries the chainId field: {row}");
}
mock_join.abort();
@@ -11915,12 +11365,7 @@ async fn json_rpc_flows_validate_reports_warnings_and_errors() {
rpc_join.abort();
}
-/// `openhuman.flows_import` over JSON-RPC (PHASE 4d): a native tinyflows graph
-/// imports clean (no warnings), and an n8n workflow export is mapped
-/// best-effort — an `if` node becomes a `condition`, an unmapped node type
-/// becomes an annotated placeholder, and the approximations come back as
-/// warnings — all WITHOUT persisting (the returned payload is a graph, not a
-/// saved Flow row; `flows_list` stays empty afterwards).
+/// `openhuman.flows_import` returns a native graph without persisting a flow row.
#[cfg(feature = "flows")]
#[tokio::test]
async fn json_rpc_flows_import_native_and_n8n() {
@@ -11957,59 +11402,6 @@ async fn json_rpc_flows_import_native_and_n8n() {
"a clean native import has no warnings"
);
- // 2. n8n import (auto-detected) — IF → condition, unmapped → placeholder.
- let n8n = json!({
- "name": "n8n-flow",
- "nodes": [
- { "id": "s", "name": "Schedule Trigger", "type": "n8n-nodes-base.scheduleTrigger" },
- { "id": "c", "name": "IF", "type": "n8n-nodes-base.if" },
- { "id": "x", "name": "Airtable", "type": "n8n-nodes-base.airtable",
- "parameters": { "table": "leads" } }
- ],
- "connections": {
- "Schedule Trigger": { "main": [[{ "node": "IF", "type": "main", "index": 0 }]] },
- "IF": { "main": [[{ "node": "Airtable", "type": "main", "index": 0 }]] }
- }
- });
- let imp2 = post_json_rpc(
- &rpc_base,
- 9602,
- "openhuman.flows_import",
- json!({ "graph": n8n }),
- )
- .await;
- let out2 = peel_logs_envelope(assert_no_jsonrpc_error(&imp2, "flows_import n8n"));
- let graph = out2.get("graph").expect("graph");
- let nodes = graph.get("nodes").and_then(Value::as_array).expect("nodes");
- let kind_of = |id: &str| {
- nodes
- .iter()
- .find(|n| n.get("id").and_then(Value::as_str) == Some(id))
- .and_then(|n| n.get("kind"))
- .and_then(Value::as_str)
- .map(str::to_string)
- };
- assert_eq!(
- kind_of("c").as_deref(),
- Some("condition"),
- "IF maps to condition"
- );
- assert_eq!(
- kind_of("x").as_deref(),
- Some("transform"),
- "unmapped Airtable node becomes a placeholder transform"
- );
- let warnings = out2
- .get("warnings")
- .and_then(Value::as_array)
- .expect("warnings");
- assert!(
- warnings
- .iter()
- .any(|w| w.as_str().is_some_and(|s| s.contains("airtable"))),
- "the unmapped node produces a warning, got: {warnings:?}"
- );
-
// 3. Import never persists — no flow row was created by either call.
let list = post_json_rpc(&rpc_base, 9603, "openhuman.flows_list", json!({})).await;
let flows = peel_logs_envelope(assert_no_jsonrpc_error(&list, "flows_list"))
@@ -13509,66 +12901,6 @@ fn graph_binding_to_undeclared_agent_field() -> Value {
})
}
-/// The same shape with NO declared schema — the deliberate carve-out.
-#[cfg(feature = "flows")]
-fn graph_binding_to_schemaless_agent() -> Value {
- json!({
- "name": "schemaless-agent",
- "nodes": [
- { "id": "t", "kind": "trigger", "name": "Manual" },
- { "id": "summarize", "kind": "agent", "name": "Summarize",
- "config": { "prompt": "summarize" } },
- { "id": "post", "kind": "tool_call", "name": "Post",
- "config": { "slug": "SLACK_SEND_MESSAGE",
- "args": { "channel": "=nodes.summarize.item.json.channel" } } }
- ],
- "edges": [
- { "from_node": "t", "to_node": "summarize" },
- { "from_node": "summarize", "to_node": "post" }
- ]
- })
-}
-
-/// An instruction written as a `=`-expression beside a real `messages` array.
-#[cfg(feature = "flows")]
-fn graph_prose_prompt_beside_real_messages() -> Value {
- json!({
- "name": "prose-prompt-with-messages",
- "nodes": [
- { "id": "t", "kind": "trigger", "name": "Manual" },
- { "id": "writer", "kind": "agent", "name": "Writer",
- "config": {
- "prompt": "=Write a short friendly summary of the article above",
- "messages": [{ "role": "user", "content": "summarise the article" }] } }
- ],
- "edges": [{ "from_node": "t", "to_node": "writer" }]
- })
-}
-
-/// The same prompt with no `messages` to fall through to — still refused.
-#[cfg(feature = "flows")]
-fn graph_prose_prompt_without_messages() -> Value {
- json!({
- "name": "prose-prompt-alone",
- "nodes": [
- { "id": "t", "kind": "trigger", "name": "Manual" },
- { "id": "writer", "kind": "agent", "name": "Writer",
- "config": { "prompt": "=Write a short friendly summary of the article above" } }
- ],
- "edges": [{ "from_node": "t", "to_node": "writer" }]
- })
-}
-
-/// The refusal message from a strict `flows_create`, or `None` when it saved.
-#[cfg(feature = "flows")]
-fn strict_create_refusal(response: &Value) -> Option<String> {
- response
- .get("error")
- .and_then(|e| e.get("message"))
- .and_then(Value::as_str)
- .map(ToOwned::to_owned)
-}
-
#[cfg(feature = "flows")]
#[tokio::test]
async fn json_rpc_flows_strict_create_refuses_binding_to_undeclared_agent_field() {
@@ -13602,135 +12934,6 @@ async fn json_rpc_flows_strict_create_refuses_binding_to_undeclared_agent_field(
api_join.abort();
}
-/// The carve-out: an agent with no declared schema is unverifiable, not
-/// invalid, so this binding must NOT be refused by the schema gate.
-///
-/// Asserted as "no refusal naming this gate" rather than "the save succeeded",
-/// because a strict create must clear every later gate too and this test is
-/// about one of them. It is still non-vacuous: revert the carve-out and the
-/// refusal names `output_parser.schema`, which is exactly what this forbids.
-#[cfg(feature = "flows")]
-#[tokio::test]
-async fn json_rpc_flows_strict_create_accepts_binding_to_schemaless_agent() {
- let _env_lock = json_rpc_e2e_env_lock_async().await;
- let (rpc_base, _tmp, api_join, rpc_join, _guards) = boot_flows_rpc_env().await;
-
- let create = post_json_rpc(
- &rpc_base,
- 9803,
- "openhuman.flows_create",
- json!({
- "name": "schemaless-agent",
- "graph": graph_binding_to_schemaless_agent(),
- "strict": true
- }),
- )
- .await;
-
- if let Some(refusal) = strict_create_refusal(&create) {
- // A refusal is expected here and is NOT this gate's doing: the fixture
- // also carries a Slack node whose `channel` arg binds to an upstream
- // field that is null under a sandboxed dry run, which strict mode
- // refuses on its own. Success therefore cannot be asserted.
- //
- // But the refusal must still be a *strict-validation* one. Without this
- // the test would also pass on a transport failure, an unknown-method
- // error or any other structural break — the false-positive shape a bare
- // "does not contain" check leaves open.
- assert!(
- refusal.starts_with("strict validation failed:"),
- "expected a strict-validation refusal, not an unrelated failure: {refusal}"
- );
- assert!(
- !refusal.contains("output_parser.schema"),
- "a schema-less agent must be treated as unverifiable, not refused: {refusal}"
- );
- }
-
- rpc_join.abort();
- api_join.abort();
-}
-
-/// #5846's second behaviour change: a vestigial `=`-prose `prompt` beside real
-/// `messages` no longer blocks the save — the node never runs on `prompt` once
-/// `messages` supply the turn, so refusing it was a refusal with no failure
-/// behind it.
-#[cfg(feature = "flows")]
-#[tokio::test]
-async fn json_rpc_flows_strict_create_accepts_prose_prompt_beside_real_messages() {
- let _env_lock = json_rpc_e2e_env_lock_async().await;
- let (rpc_base, _tmp, api_join, rpc_join, _guards) = boot_flows_rpc_env().await;
-
- let create = post_json_rpc(
- &rpc_base,
- 9804,
- "openhuman.flows_create",
- json!({
- "name": "prose-prompt-with-messages",
- "graph": graph_prose_prompt_beside_real_messages(),
- "strict": true
- }),
- )
- .await;
-
- // Asserted as a successful save, not merely "no refusal naming this gate".
- // This fixture is a trigger plus one agent node — no bindings, no
- // connections, no external-tool args — so there is no later gate it could
- // legitimately trip, and a tolerated-error form would have gone green on a
- // structural error, a transport failure or a renamed diagnostic while
- // proving nothing. Confirmed against the running stack: the create returns
- // a flow id.
- let created = assert_no_jsonrpc_error(&create, "flows_create prose prompt beside messages");
- let created = peel_logs_envelope(created);
- assert_eq!(
- created.get("name").and_then(Value::as_str),
- Some("prose-prompt-with-messages"),
- "the saved flow must be the one submitted: {created}"
- );
- assert!(
- created
- .get("id")
- .and_then(Value::as_str)
- .is_some_and(|id| !id.is_empty()),
- "a saved flow must come back with an id: {created}"
- );
-
- rpc_join.abort();
- api_join.abort();
-}
-
-/// The other side of the same rule: with no `messages` to fall through to, the
-/// `=`-prose prompt is still a hard refusal. #5846 narrowed this rule; it did
-/// not remove it, and pinning that stops the narrowing being widened.
-#[cfg(feature = "flows")]
-#[tokio::test]
-async fn json_rpc_flows_strict_create_still_refuses_prose_prompt_without_messages() {
- let _env_lock = json_rpc_e2e_env_lock_async().await;
- let (rpc_base, _tmp, api_join, rpc_join, _guards) = boot_flows_rpc_env().await;
-
- let create = post_json_rpc(
- &rpc_base,
- 9805,
- "openhuman.flows_create",
- json!({
- "name": "prose-prompt-alone",
- "graph": graph_prose_prompt_without_messages(),
- "strict": true
- }),
- )
- .await;
-
- let refusal = strict_create_refusal(&create)
- .unwrap_or_else(|| panic!("strict create must be refused, got: {create}"));
- assert!(
- refusal.contains("reads as an instruction written as a"),
- "the refusal must come from the `=`-prose prompt gate, got: {refusal}"
- );
-
- rpc_join.abort();
- api_join.abort();
-}
-
// ---------------------------------------------------------------------------
// Migration import guard: refusing the null memory driver (#5799)
// ---------------------------------------------------------------------------