Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

test(claude-code): assert the bytes, not that an event arrived\n\nBoth tests could pass on an implementation that breaks the guarantee this PR\nexists to make, as CodeRabbit pointed out:\n\n- `feed_bytes_still_replaces_genuinely_invalid_bytes` only counted events. An\n implementation that silently DROPPED the invalid byte emits one event too,\n and parses, so the count cannot tell replacement from deletion — while the\n test name claims it can. It now matches the `System` event and asserts the\n decoded `session_id` is U+FFFD.\n- `feed_bytes_preserves_a_character_split_across_chunks` asserted on\n `format!("{:?}", events[0])`. `ParseError` retains the original line, so the\n emoji appears in the Debug rendering even when parsing failed — the exact\n failure the test is meant to catch. It now matches `Assistant` and asserts\n `message["text"]` equals the fixture. The `!contains(U+FFFD)` assertion stays;\n it carries weight the variant match does not.\n

Nguyen Thanh Datbc8d69140d38
diff --git a/src/openhuman/inference/provider/claude_code/stream_parser_tests.rs b/src/openhuman/inference/provider/claude_code/stream_parser_tests.rs
index 92012799e1..36b6cdc4ae 100644
--- a/src/openhuman/inference/provider/claude_code/stream_parser_tests.rs
+++ b/src/openhuman/inference/provider/claude_code/stream_parser_tests.rs
@@ -189,6 +189,18 @@ fn feed_bytes_preserves_a_character_split_across_chunks() {
events.extend(p.feed_bytes(&bytes[split..]));
assert_eq!(events.len(), 1);
+
+ // `ParseError` carries the original line, so its Debug rendering contains
+ // the emoji too — matching the variant is what separates "decoded across
+ // the boundary" from "failed to parse and echoed the bytes back".
+ let ClaudeCodeEvent::Assistant { message } = &events[0] else {
+ panic!("expected an Assistant event, got {:?}", events[0]);
+ };
+ assert_eq!(
+ message["text"], "héllo 世界 🌍 tail",
+ "the character split across the two chunks must survive intact"
+ );
+
let rendered = format!("{:?}", events[0]);
assert!(
rendered.contains("héllo 世界 🌍 tail"),
@@ -214,4 +226,16 @@ fn feed_bytes_still_replaces_genuinely_invalid_bytes() {
1,
"the line must still be emitted, not withheld"
);
+
+ // Not just "an event arrived": the invalid byte has to have been REPLACED.
+ // Dropping it would also emit one event and would also parse, so the count
+ // alone cannot tell the two apart.
+ let ClaudeCodeEvent::System { session_id, .. } = &events[0] else {
+ panic!("expected a System event, got {:?}", events[0]);
+ };
+ assert_eq!(
+ session_id.as_deref(),
+ Some("\u{FFFD}"),
+ "0xFF must decode to the replacement character, not vanish"
+ );
}