rho-coding-agent 2.15.0

A fast Rust agent harness with a small footprint and opinionated defaults
use pretty_assertions::assert_eq;
use serde_json::json;

use super::{JsonScan, StreamedInputJson, EAGER_PARSE_CHARS};

// Covers: string contents, escapes, and nested values must not look like a
// top-level field boundary, or large bodies would re-parse on every fragment
// Owner: claude stream input_json scanner
#[test]
fn scan_reports_only_top_level_field_boundaries() {
    let cases = [
        (r#"{"a":"x,}y""#, false),
        (r#"{"a":"q\"," "#, false),
        (r#"{"a":"q\\","#, true),
        (r#"{"a":[1,2],"#, true),
        (r#"{"a":{"b":1,"c":2}"#, false),
        (r#"{"a":1}"#, true),
        (r#"{"a":1,"#, true),
    ];
    for (text, expected) in cases {
        assert_eq!(JsonScan::default().advance(text), expected, "{text}");
    }
}

// Covers: past the eager window, body fragments skip parsing but the
// fragment closing the object still produces the complete input
// Owner: claude stream input_json assembly
#[test]
fn large_body_parses_at_field_boundaries_only() {
    let body = "x".repeat(EAGER_PARSE_CHARS * 2);
    let mut streamed = StreamedInputJson::default();
    assert_eq!(
        streamed.push(r#"{"file_path":"a.rs""#),
        Some(json!({"file_path": "a.rs"}))
    );
    streamed.push(r#","content":""#);
    for chunk in body.as_bytes().chunks(100) {
        let fragment = std::str::from_utf8(chunk).expect("ascii chunk");
        let parsed = streamed.push(fragment);
        if streamed.len() > EAGER_PARSE_CHARS {
            assert_eq!(parsed, None, "parsed mid-body at {} bytes", streamed.len());
        }
    }
    assert_eq!(
        streamed.push(r#""}"#),
        Some(json!({"file_path": "a.rs", "content": body}))
    );
    // Closing the object releases the buffer; trailing fragments are ignored.
    assert_eq!(streamed.len(), 0);
    assert_eq!(streamed.push(r#"{"file_path":"b.rs"}"#), None);
}