use harn_vm::agent_events::AgentEvent;
use super::tests::collect_notifications;
use crate::adapters::acp::schema::HARN_AGENT_EVENT_METHOD;
use crate::adapters::acp::HARN_AGENT_EVENT_KINDS;
#[tokio::test(flavor = "current_thread")]
async fn boundary_failure_reaches_acp_as_ext_event() {
let actual = collect_notifications(vec![AgentEvent::BoundaryFailure {
session_id: "session-1".to_string(),
boundary: harn_vm::boundary::BoundaryId::TextToolParse,
kind: harn_vm::boundary::BoundaryFailureKind::Unrecognized,
owner: "harness".to_string(),
detail: "the text tool-call parse boundary lost 1 span(s)".to_string(),
excerpt: Some("<tool>read_file({ path: \"a.rs\" })</tool>".to_string()),
dropped_count: 1,
dropped_bytes: 38,
unreported: false,
}])
.await;
let notification = &actual[0];
assert_eq!(notification["method"], HARN_AGENT_EVENT_METHOD);
let params = ¬ification["params"];
assert_eq!(params["kind"], "boundary_failure");
assert_eq!(params["failureKind"], "unrecognized");
assert_eq!(params["sessionId"], "session-1");
assert_eq!(params["boundary"], "text_tool_parse");
assert_eq!(params["owner"], "harness");
assert_eq!(params["droppedCount"], 1);
assert_eq!(params["droppedBytes"], 38);
assert_eq!(params["unreported"], false);
assert!(params["excerpt"]
.as_str()
.is_some_and(|text| text.contains("<tool>")));
assert!(
HARN_AGENT_EVENT_KINDS.contains(&"boundary_failure"),
"boundary_failure must be advertised so clients can subscribe"
);
}
#[tokio::test(flavor = "current_thread")]
async fn boundary_failure_omits_an_absent_excerpt() {
let actual = collect_notifications(vec![AgentEvent::BoundaryFailure {
session_id: "session-1".to_string(),
boundary: harn_vm::boundary::BoundaryId::ProviderAdmissionGate,
kind: harn_vm::boundary::BoundaryFailureKind::Capped,
owner: "policy".to_string(),
detail: "the governor gave up".to_string(),
excerpt: None,
dropped_count: 0,
dropped_bytes: 0,
unreported: false,
}])
.await;
let params = &actual[0]["params"];
assert_eq!(params["kind"], "boundary_failure");
assert_eq!(params["failureKind"], "capped");
assert_eq!(params["boundary"], "provider_admission_gate");
assert_eq!(params["owner"], "policy");
assert!(params["excerpt"].is_null());
}