diff --git a/src/integration_test.rs b/src/integration_test.rs index 605265f..35eab42 100644 --- a/src/integration_test.rs +++ b/src/integration_test.rs @@ -4716,6 +4716,89 @@ mod conversation_extended_tests { let id_b = registry.get_conversation_id(&room_b).await; assert_ne!(id_a, id_b, "Different rooms should have different conversation IDs"); } + + #[tokio::test] + async fn test_conversation_needs_compaction() { + let Some(api_key) = load_env() else { eprintln!("Skipping: no API key"); return; }; + let mistral = Arc::new( + mistralai_client::v1::client::Client::new(Some(api_key), None, None, None).unwrap(), + ); + let store = Arc::new(Store::open_memory().unwrap()); + // Set very low compaction threshold + let registry = ConversationRegistry::new("mistral-medium-latest".into(), 100, store); + + let room = format!("test-compact-{}", uuid::Uuid::new_v4()); + + // Should not need compaction before any messages + assert!(!registry.needs_compaction(&room).await); + + // Send a message (will create conversation and accumulate tokens) + let input = mistralai_client::v1::conversations::ConversationInput::Text( + "Tell me a long story about a dragon. Be very detailed and verbose.".into() + ); + registry.send_message(&room, input, true, &mistral, None).await.unwrap(); + + // With threshold=100, this should trigger compaction + let needs = registry.needs_compaction(&room).await; + // The response tokens likely exceed 100 + assert!(needs, "Should need compaction with low threshold"); + } + + #[tokio::test] + async fn test_conversation_set_agent_id() { + let store = Arc::new(Store::open_memory().unwrap()); + let registry = ConversationRegistry::new("mistral-medium-latest".into(), 118000, store); + + assert!(registry.get_agent_id().await.is_none()); + registry.set_agent_id("ag_test123".into()).await; + assert_eq!(registry.get_agent_id().await, Some("ag_test123".into())); + } + + #[tokio::test] + async fn test_conversation_reset_all() { + let Some(api_key) = load_env() else { eprintln!("Skipping: no API key"); return; }; + let mistral = Arc::new( + mistralai_client::v1::client::Client::new(Some(api_key), None, None, None).unwrap(), + ); + let store = Arc::new(Store::open_memory().unwrap()); + let registry = ConversationRegistry::new("mistral-medium-latest".into(), 118000, store); + + // Create conversations in two rooms + let room_a = format!("test-resetall-a-{}", uuid::Uuid::new_v4()); + let room_b = format!("test-resetall-b-{}", uuid::Uuid::new_v4()); + let input = mistralai_client::v1::conversations::ConversationInput::Text("hi".into()); + registry.send_message(&room_a, input.clone(), true, &mistral, None).await.unwrap(); + registry.send_message(&room_b, input, true, &mistral, None).await.unwrap(); + + assert!(registry.get_conversation_id(&room_a).await.is_some()); + assert!(registry.get_conversation_id(&room_b).await.is_some()); + + // Reset all + registry.reset_all().await; + assert!(registry.get_conversation_id(&room_a).await.is_none()); + assert!(registry.get_conversation_id(&room_b).await.is_none()); + } + + #[tokio::test] + async fn test_conversation_with_context_hint() { + let Some(api_key) = load_env() else { eprintln!("Skipping: no API key"); return; }; + let mistral = Arc::new( + mistralai_client::v1::client::Client::new(Some(api_key), None, None, None).unwrap(), + ); + let store = Arc::new(Store::open_memory().unwrap()); + let registry = ConversationRegistry::new("mistral-medium-latest".into(), 118000, store); + + let room = format!("test-hint-{}", uuid::Uuid::new_v4()); + let input = mistralai_client::v1::conversations::ConversationInput::Text( + "what color was mentioned in the context?".into() + ); + let hint = "sienna: my favorite color is chartreuse\nlonni: nice, i like teal"; + + let resp = registry.send_message(&room, input, true, &mistral, Some(hint)).await.unwrap(); + let text = resp.assistant_text().unwrap_or_default().to_lowercase(); + assert!(text.contains("chartreuse") || text.contains("teal") || text.contains("color"), + "Should reference the context hint: got '{text}'"); + } } // ══════════════════════════════════════════════════════════════════════════