use std::path::Path;
use apcore_toolkit::ScannedModule;
use apexe::a2a::A2aServerBuilder;
use apexe::output::YamlOutput;
use serde_json::json;
use tempfile::TempDir;
fn write_echo_binding(dir: &Path) {
let module = ScannedModule::new(
"cli.echo".to_string(),
"Echo a message".to_string(),
json!({
"type": "object",
"properties": { "message": { "type": "string" } },
"additionalProperties": false
}),
json!({ "type": "object" }),
vec!["cli".to_string()],
"exec:///bin/echo".to_string(),
);
YamlOutput::without_verification()
.write(&[module], dir, false)
.expect("binding should be written");
}
#[tokio::test]
async fn test_a2a_agent_card_exposes_scanned_skill() {
let dir = TempDir::new().unwrap();
write_echo_binding(dir.path());
let card = A2aServerBuilder::new()
.name("apexe-test")
.modules_dir(dir.path())
.agent_card()
.await
.expect("agent card should build from bindings");
let blob = serde_json::to_string(&card).unwrap();
assert!(
blob.contains("skills"),
"agent card should carry a skills list: {blob}"
);
assert!(
blob.contains("echo"),
"scanned echo module should be exposed as a skill: {blob}"
);
}
#[tokio::test]
async fn test_a2a_empty_registry_errors() {
let dir = TempDir::new().unwrap();
let result = A2aServerBuilder::new()
.modules_dir(dir.path())
.agent_card()
.await;
assert!(
result.is_err(),
"an empty registry must error, not build an empty agent"
);
}
#[tokio::test]
async fn test_a2a_serve_fails_fast_on_enable_approval_without_store() {
let dir = TempDir::new().unwrap();
write_echo_binding(dir.path());
let result = A2aServerBuilder::new()
.modules_dir(dir.path())
.enable_approval(true)
.agent_card()
.await;
assert!(
result.is_err(),
"enable_approval without a store must fail fast"
);
}