mirror of
https://github.com/instructkr/claw-code.git
synced 2026-04-07 00:24:50 +08:00
feat(runtime): add tests and improve error handling across runtime crate
- Add 20 new tests for conversation, session, and SSE modules - Improve error paths in conversation.rs and session.rs - Add SSE event parsing tests - 126 runtime tests pass, clippy clean, fmt clean
This commit is contained in:
@@ -80,7 +80,11 @@ impl IncrementalSseParser {
|
||||
}
|
||||
|
||||
fn take_event(&mut self) -> Option<SseEvent> {
|
||||
if self.data_lines.is_empty() && self.event_name.is_none() && self.id.is_none() && self.retry.is_none() {
|
||||
if self.data_lines.is_empty()
|
||||
&& self.event_name.is_none()
|
||||
&& self.id.is_none()
|
||||
&& self.retry.is_none()
|
||||
{
|
||||
return None;
|
||||
}
|
||||
|
||||
@@ -102,8 +106,13 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn parses_streaming_events() {
|
||||
// given
|
||||
let mut parser = IncrementalSseParser::new();
|
||||
|
||||
// when
|
||||
let first = parser.push_chunk("event: message\ndata: hel");
|
||||
|
||||
// then
|
||||
assert!(first.is_empty());
|
||||
|
||||
let second = parser.push_chunk("lo\n\nid: 1\ndata: world\n\n");
|
||||
@@ -125,4 +134,25 @@ mod tests {
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn finish_flushes_a_trailing_event_without_separator() {
|
||||
// given
|
||||
let mut parser = IncrementalSseParser::new();
|
||||
parser.push_chunk("event: message\ndata: trailing");
|
||||
|
||||
// when
|
||||
let events = parser.finish();
|
||||
|
||||
// then
|
||||
assert_eq!(
|
||||
events,
|
||||
vec![SseEvent {
|
||||
event: Some("message".to_string()),
|
||||
data: "trailing".to_string(),
|
||||
id: None,
|
||||
retry: None,
|
||||
}]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user