#[cfg(test)]
#[test]
fn test_ccs_glm_duplicate_output_bug_fix() {
use std::io::Cursor;
let test_printer = Rc::new(RefCell::new(TestPrinter::new()));
let printer: SharedPrinter = test_printer.clone();
let mut parser =
ClaudeParser::with_printer(Colors { enabled: false }, Verbosity::Normal, printer)
.with_terminal_mode(TerminalMode::Full);
let input = r#"{"type":"stream_event","event":{"type":"message_start"}}
{"type":"stream_event","event":{"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}}}
{"type":"stream_event","event":{"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"First delta"}}}
{"type":"stream_event","event":{"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Second delta"}}}
{"type":"stream_event","event":{"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"First delta"}}}
{"type":"stream_event","event":{"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Second delta"}}}
{"type":"stream_event","event":{"type":"message_stop"}}"#;
let reader = Cursor::new(input);
parser
.parse_stream(reader, &MemoryWorkspace::new_test())
.unwrap();
let printer_ref = test_printer.borrow();
let output = printer_ref.get_output();
let first_count = output.matches("First delta").count();
let second_count = output.matches("Second delta").count();
assert_eq!(
first_count, 2,
"First delta should appear 2 times in append-only output. Found {first_count} occurrences. Output: {output:?}"
);
assert_eq!(
second_count, 2,
"Second delta should appear 2 times in append-only output. Found {second_count} occurrences. Output: {output:?}"
);
let render_count = output.matches("[Claude]").count();
assert_eq!(
render_count, 1,
"Prefix should appear once with append-only pattern. Found {render_count} prefixes. Output: {output:?}"
);
}
#[cfg(test)]
#[test]
fn test_ccs_glm_repeated_message_start_preserves_processed_deltas() {
use std::io::Cursor;
let test_printer = Rc::new(RefCell::new(TestPrinter::new()));
let printer: SharedPrinter = test_printer.clone();
let mut parser =
ClaudeParser::with_printer(Colors { enabled: false }, Verbosity::Normal, printer)
.with_terminal_mode(TerminalMode::Full);
let input_lines = vec![
r#"{"type":"stream_event","event":{"type":"message_start"}}"#.to_string(),
r#"{"type":"stream_event","event":{"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}}}"#.to_string(),
r#"{"type":"stream_event","event":{"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"First delta"}}}"#.to_string(),
r#"{"type":"stream_event","event":{"type":"message_start"}}"#.to_string(),
r#"{"type":"stream_event","event":{"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"First delta"}}}"#.to_string(),
r#"{"type":"stream_event","event":{"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Second delta"}}}"#.to_string(),
r#"{"type":"stream_event","event":{"type":"message_start"}}"#.to_string(),
r#"{"type":"stream_event","event":{"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"First delta"}}}"#.to_string(),
r#"{"type":"stream_event","event":{"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Second delta"}}}"#.to_string(),
r#"{"type":"stream_event","event":{"type":"message_stop"}}"#.to_string(),
];
let input = input_lines.join("\n");
let reader = Cursor::new(input);
parser
.parse_stream(reader, &MemoryWorkspace::new_test())
.unwrap();
let printer_ref = test_printer.borrow();
let output = printer_ref.get_output();
let first_count = output.matches("First delta").count();
let second_count = output.matches("Second delta").count();
assert_eq!(
first_count, 2,
"First delta should appear 2 times (first + accumulated with Second). Found {first_count} occurrences. Output: {output:?}"
);
assert_eq!(
second_count, 2,
"Second delta should appear 2 times (standalone + accumulated with First). Found {second_count} occurrences. Output: {output:?}"
);
}