use claude_codes::{assert_fully_wrapped, ClaudeOutput};
use serde_json::json;
#[test]
fn stream_event_carries_api_message_id_and_text_runs_joined() {
let frame = json!({
"type": "stream_event",
"event": {"type": "message_start", "message": {"id": "msg_01"}},
"parent_tool_use_id": null,
"api_message_id": "msg_01",
"text_runs_joined": true,
"uuid": "u1",
"session_id": "s1"
});
assert_fully_wrapped(&frame);
let ClaudeOutput::StreamEvent(ev) = serde_json::from_value(frame).unwrap() else {
panic!("expected StreamEvent");
};
assert_eq!(ev.api_message_id.as_deref(), Some("msg_01"));
assert_eq!(ev.text_runs_joined, Some(true));
}
#[test]
fn stream_event_api_message_id_without_text_runs_joined() {
let frame = json!({
"type": "stream_event",
"event": {"type": "content_block_delta", "index": 0, "delta": {"type": "text_delta", "text": "hi"}},
"parent_tool_use_id": null,
"api_message_id": "msg_01",
"uuid": "u2",
"session_id": "s1"
});
assert_fully_wrapped(&frame);
let ClaudeOutput::StreamEvent(ev) = serde_json::from_value(frame).unwrap() else {
panic!("expected StreamEvent");
};
assert_eq!(ev.api_message_id.as_deref(), Some("msg_01"));
assert_eq!(ev.text_runs_joined, None);
}
#[test]
fn status_carries_compact_output_chars() {
let frame = json!({
"type": "system",
"subtype": "status",
"status": "compacting",
"compact_output_chars": 1234,
"uuid": "u1",
"session_id": "s1"
});
assert_fully_wrapped(&frame);
let ClaudeOutput::System(sys) = serde_json::from_value(frame).unwrap() else {
panic!("expected System");
};
let status = sys.as_status().expect("status");
assert_eq!(status.compact_output_chars, Some(1234));
}