#[test]
fn test_snapshot_as_delta_single_large_delta_warns() {
use super::streaming_state::StreamingSession;
let mut session = StreamingSession::new();
session.on_message_start();
let large_delta = "x".repeat(201);
let show_prefix = session.on_text_delta(0, &large_delta);
assert!(show_prefix, "First large delta should show prefix");
assert_eq!(
session.get_accumulated(super::types::ContentType::Text, "0"),
Some(large_delta.as_str())
);
}
#[test]
fn test_many_tiny_deltas_work_correctly() {
use super::streaming_state::StreamingSession;
let mut session = StreamingSession::new();
session.on_message_start();
let mut expected_content = String::new();
for i in 0..20 {
let delta = format!("chunk{i}");
expected_content.push_str(&delta);
session.on_text_delta(0, &delta);
}
assert_eq!(
session.get_accumulated(super::types::ContentType::Text, "0"),
Some(expected_content.as_str())
);
}
#[test]
fn test_pattern_of_repeated_large_deltas_detected() {
use super::streaming_state::StreamingSession;
let mut session = StreamingSession::new();
session.on_message_start();
let large_snapshot = "x".repeat(201);
for _ in 0..3 {
session.on_text_delta(0, &large_snapshot);
}
let accumulated = session
.get_accumulated(super::types::ContentType::Text, "0")
.unwrap();
assert_eq!(accumulated.len(), large_snapshot.len());
let metrics = session.get_streaming_quality_metrics();
assert_eq!(metrics.large_delta_count, 3);
}
#[test]
fn test_mixed_small_and_large_deltas() {
use super::streaming_state::StreamingSession;
let mut session = StreamingSession::new();
session.on_message_start();
session.on_text_delta(0, "Hello ");
session.on_text_delta(0, "World ");
let large_delta = "x".repeat(201);
session.on_text_delta(0, &large_delta);
session.on_text_delta(0, " End");
let accumulated = session
.get_accumulated(super::types::ContentType::Text, "0")
.unwrap();
assert!(accumulated.contains("Hello"));
assert!(accumulated.contains("World"));
assert!(accumulated.ends_with(" End"));
}
#[test]
fn test_content_block_state_tracking() {
use crate::json_parser::streaming_state::StreamingSession;
let mut session = StreamingSession::new();
session.on_message_start();
assert!(!session.has_any_streamed_content());
let show_prefix = session.on_text_delta(0, "First");
assert!(show_prefix, "First delta should show prefix");
assert!(session.has_any_streamed_content());
session.on_content_block_start(1);
let show_prefix = session.on_text_delta(1, "Second");
assert!(show_prefix, "First delta in new block should show prefix");
assert_eq!(
session.get_accumulated(crate::json_parser::types::ContentType::Text, "0"),
Some("First"),
"Block 0 content should be PRESERVED after transitioning to block 1"
);
assert_eq!(
session.get_accumulated(crate::json_parser::types::ContentType::Text, "1"),
Some("Second")
);
}