Skip to content

Commit 3747a8f

Browse files
committed
test(replay): cover a2a_discover egress method mismatch
1 parent 0f4e29b commit 3747a8f

2 files changed

Lines changed: 101 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[
2+
{
3+
"choices": [
4+
{
5+
"index": 0,
6+
"message": {
7+
"role": "assistant",
8+
"content": null,
9+
"tool_calls": [
10+
{
11+
"id": "call_1",
12+
"type": "function",
13+
"function": {
14+
"name": "a2a_discover",
15+
"arguments": "{\"url\":\"http://127.0.0.1/\",\"allow_private\":true}"
16+
}
17+
}
18+
]
19+
},
20+
"finish_reason": "tool_calls"
21+
}
22+
]
23+
}
24+
]
25+

crates/rexos/tests/session_replay.rs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,3 +922,79 @@ async fn replay_fixture_blocks_a2a_discover_egress_path_mismatches() {
922922

923923
server.abort();
924924
}
925+
926+
#[tokio::test]
927+
#[serial]
928+
async fn replay_fixture_blocks_a2a_discover_egress_method_mismatches() {
929+
let fixture = support::openai_compat_fixture::load_json_array(include_str!(
930+
"fixtures/replay/session_egress_policy_a2a_discover_method_block.json"
931+
));
932+
let server = support::openai_compat_fixture::FixtureServer::spawn(fixture).await;
933+
934+
let tmp = tempfile::tempdir().unwrap();
935+
let security = rexos::security::SecurityConfig {
936+
egress: EgressConfig {
937+
rules: vec![EgressRule {
938+
tool: "a2a_discover".to_string(),
939+
host: "127.0.0.1".to_string(),
940+
path_prefix: "/.well-known/".to_string(),
941+
methods: vec!["POST".to_string()],
942+
}],
943+
},
944+
..Default::default()
945+
};
946+
947+
let (agent, _paths, workspace_root) = fixture_agent(&tmp, server.base_url.clone(), security);
948+
949+
let session_id = "s-replay-egress-a2a-discover-method";
950+
agent
951+
.set_session_allowed_tools(session_id, vec!["a2a_discover".to_string()])
952+
.unwrap();
953+
954+
let err = agent
955+
.run_session(
956+
workspace_root,
957+
session_id,
958+
None,
959+
"discover agent card (method mismatch)",
960+
TaskKind::Coding,
961+
)
962+
.await
963+
.unwrap_err();
964+
let err_text = err.to_string();
965+
assert!(
966+
err_text.contains("egress method not allowed"),
967+
"expected egress method block, got: {err_text}"
968+
);
969+
assert!(
970+
err_text.contains("GET"),
971+
"expected method in error, got: {err_text}"
972+
);
973+
assert!(
974+
err_text.contains("a2a_discover"),
975+
"expected tool name in error, got: {err_text}"
976+
);
977+
978+
let requests = server.requests.lock().unwrap().clone();
979+
assert_eq!(requests.len(), 1, "expected one chat completions call");
980+
assert_eq!(
981+
compact_request(&requests[0]),
982+
json!({
983+
"model": "fixture-model",
984+
"temperature": 0.0,
985+
"tools": [{
986+
"name": "a2a_discover",
987+
"type": "function",
988+
"param_type": "object",
989+
"required": ["url"],
990+
"properties": ["allow_private", "url"],
991+
"additional_properties": false,
992+
}],
993+
"message_roles": ["user"],
994+
"assistant_tool_calls": [],
995+
"tool_messages": [],
996+
})
997+
);
998+
999+
server.abort();
1000+
}

0 commit comments

Comments
 (0)