diff --git a/crates/g3-core/src/task_result_comprehensive_tests.rs b/crates/g3-core/src/task_result_comprehensive_tests.rs index 3164d68..0f15f49 100644 --- a/crates/g3-core/src/task_result_comprehensive_tests.rs +++ b/crates/g3-core/src/task_result_comprehensive_tests.rs @@ -6,14 +6,10 @@ use std::sync::Arc; fn test_task_result_basic_functionality() { // Create a context window with some messages let mut context = ContextWindow::new(10000); - context.add_message(Message { - role: MessageRole::User, - content: "Test message 1".to_string(), - }); - context.add_message(Message { - role: MessageRole::Assistant, - content: "Response 1".to_string(), - }); + context.add_message(Message::new(MessageRole::User, "Test message 1".to_string()) + ); + context.add_message(Message::new(MessageRole::Assistant, "Response 1".to_string()) + ); // Create a TaskResult let response = "This is the response\n\nFinal output block".to_string(); @@ -100,10 +96,7 @@ fn test_context_window_preservation() { // Add some messages for i in 0..5 { - context.add_message(Message { - role: if i % 2 == 0 { MessageRole::User } else { MessageRole::Assistant }, - content: format!("Message {}", i), - }); + context.add_message(Message::new(if i % 2 == 0 { MessageRole::User } else { MessageRole::Assistant }, format!("Message {}", i))); } // Create TaskResult diff --git a/crates/g3-core/tests/test_context_thinning.rs b/crates/g3-core/tests/test_context_thinning.rs index db6761f..f0ef2a1 100644 --- a/crates/g3-core/tests/test_context_thinning.rs +++ b/crates/g3-core/tests/test_context_thinning.rs @@ -46,10 +46,10 @@ fn test_thin_context_basic() { // Add some messages to the first third for i in 0..9 { if i % 2 == 0 { - context.add_message(Message { - role: MessageRole::Assistant, - content: format!("Assistant message {}", i), - }); + context.add_message(Message::new( + MessageRole::Assistant, + format!("Assistant message {}", i), + )); } else { // Add tool results with varying sizes let content = if i == 1 { @@ -63,10 +63,10 @@ fn test_thin_context_basic() { format!("Tool result: small result {}", i) }; - context.add_message(Message { - role: MessageRole::User, + context.add_message(Message::new( + MessageRole::User, content, - }); + )); } } @@ -98,10 +98,10 @@ fn test_thin_write_file_tool_calls() { let mut context = ContextWindow::new(10000); // Add some messages including a write_file tool call with large content - context.add_message(Message { - role: MessageRole::User, - content: "Please create a large file".to_string(), - }); + context.add_message(Message::new( + MessageRole::User, + "Please create a large file".to_string(), + )); // Add an assistant message with a write_file tool call containing large content let large_content = "x".repeat(1500); @@ -109,22 +109,22 @@ fn test_thin_write_file_tool_calls() { r#"{{"tool": "write_file", "args": {{"file_path": "test.txt", "content": "{}"}}}}"#, large_content ); - context.add_message(Message { - role: MessageRole::Assistant, - content: format!("I'll create that file.\n\n{}", tool_call_json), - }); + context.add_message(Message::new( + MessageRole::Assistant, + format!("I'll create that file.\n\n{}", tool_call_json), + )); - context.add_message(Message { - role: MessageRole::User, - content: "Tool result: ✅ Successfully wrote 1500 lines".to_string(), - }); + context.add_message(Message::new( + MessageRole::User, + "Tool result: ✅ Successfully wrote 1500 lines".to_string(), + )); // Add more messages to ensure we have enough for "first third" logic for i in 0..6 { - context.add_message(Message { - role: MessageRole::Assistant, - content: format!("Response {}", i), - }); + context.add_message(Message::new( + MessageRole::Assistant, + format!("Response {}", i), + )); } // Trigger thinning at 50% @@ -154,10 +154,10 @@ fn test_thin_str_replace_tool_calls() { let mut context = ContextWindow::new(10000); // Add some messages including a str_replace tool call with large diff - context.add_message(Message { - role: MessageRole::User, - content: "Please update the file".to_string(), - }); + context.add_message(Message::new( + MessageRole::User, + "Please update the file".to_string(), + )); // Add an assistant message with a str_replace tool call containing large diff let large_diff = format!("--- old\n{}\n+++ new\n{}", "-old line\n".repeat(100), "+new line\n".repeat(100)); @@ -165,22 +165,22 @@ fn test_thin_str_replace_tool_calls() { r#"{{"tool": "str_replace", "args": {{"file_path": "test.txt", "diff": "{}"}}}}"#, large_diff.replace('\n', "\\n") ); - context.add_message(Message { - role: MessageRole::Assistant, - content: format!("I'll update that file.\n\n{}", tool_call_json), - }); + context.add_message(Message::new( + MessageRole::Assistant, + format!("I'll update that file.\n\n{}", tool_call_json), + )); - context.add_message(Message { - role: MessageRole::User, - content: "Tool result: ✅ applied unified diff".to_string(), - }); + context.add_message(Message::new( + MessageRole::User, + "Tool result: ✅ applied unified diff".to_string(), + )); // Add more messages to ensure we have enough for "first third" logic for i in 0..6 { - context.add_message(Message { - role: MessageRole::Assistant, - content: format!("Response {}", i), - }); + context.add_message(Message::new( + MessageRole::Assistant, + format!("Response {}", i), + )); } // Trigger thinning at 50% @@ -212,10 +212,10 @@ fn test_thin_context_no_large_results() { // Add only small messages for i in 0..9 { - context.add_message(Message { - role: MessageRole::User, - content: format!("Tool result: small {}", i), - }); + context.add_message(Message::new( + MessageRole::User, + format!("Tool result: small {}", i), + )); } context.used_tokens = 5000; @@ -244,7 +244,7 @@ fn test_thin_context_only_affects_first_third() { MessageRole::Assistant }; - context.add_message(Message { role, content }); + context.add_message(Message::new(role, content)); } context.used_tokens = 5000; diff --git a/crates/g3-core/tests/test_todo_context_thinning.rs b/crates/g3-core/tests/test_todo_context_thinning.rs index 016e3e6..27443a9 100644 --- a/crates/g3-core/tests/test_todo_context_thinning.rs +++ b/crates/g3-core/tests/test_todo_context_thinning.rs @@ -8,27 +8,18 @@ fn test_todo_read_results_not_thinned() { let mut context = ContextWindow::new(10000); // Add a todo_read tool call - context.add_message(Message { - role: MessageRole::Assistant, - content: r#"{"tool": "todo_read", "args": {}}"#.to_string(), - }); + context.add_message(Message::new(MessageRole::Assistant, r#"{"tool": "todo_read", "args": {}}"#.to_string())); // Add a large TODO result (> 500 chars) let large_todo_result = format!( "Tool result: 📝 TODO list:\n{}", "- [ ] Task with long description\n".repeat(50) ); - context.add_message(Message { - role: MessageRole::User, - content: large_todo_result.clone(), - }); + context.add_message(Message::new(MessageRole::User, large_todo_result.clone())); // Add more messages to ensure we have enough for "first third" logic for i in 0..6 { - context.add_message(Message { - role: MessageRole::Assistant, - content: format!("Response {}", i), - }); + context.add_message(Message::new(MessageRole::Assistant, format!("Response {}", i))) } // Trigger thinning at 50% @@ -65,27 +56,18 @@ fn test_todo_write_results_not_thinned() { // Add a todo_write tool call let large_content = "- [ ] Task\n".repeat(100); - context.add_message(Message { - role: MessageRole::Assistant, - content: format!(r#"{{"tool": "todo_write", "args": {{"content": "{}"}}}}"#, large_content), - }); + context.add_message(Message::new(MessageRole::Assistant, format!(r#"{{"tool": "todo_write", "args": {{"content": "{}"}}}}"#, large_content))); // Add a large TODO write result let large_todo_result = format!( "Tool result: ✅ TODO list updated ({} chars) and saved to todo.g3.md", large_content.len() ); - context.add_message(Message { - role: MessageRole::User, - content: large_todo_result.clone(), - }); + context.add_message(Message::new(MessageRole::User, large_todo_result.clone())); // Add more messages for i in 0..6 { - context.add_message(Message { - role: MessageRole::Assistant, - content: format!("Response {}", i), - }); + context.add_message(Message::new(MessageRole::Assistant, format!("Response {}", i))) } // Trigger thinning at 50% @@ -119,24 +101,15 @@ fn test_non_todo_results_still_thinned() { let mut context = ContextWindow::new(10000); // Add a non-TODO tool call (e.g., read_file) - context.add_message(Message { - role: MessageRole::Assistant, - content: r#"{"tool": "read_file", "args": {"file_path": "test.txt"}}"#.to_string(), - }); + context.add_message(Message::new(MessageRole::Assistant, r#"{"tool": "read_file", "args": {"file_path": "test.txt"}}"#.to_string())); // Add a large read_file result (> 500 chars) let large_result = format!("Tool result: {}", "x".repeat(1500)); - context.add_message(Message { - role: MessageRole::User, - content: large_result, - }); + context.add_message(Message::new(MessageRole::User, large_result)); // Add more messages for i in 0..6 { - context.add_message(Message { - role: MessageRole::Assistant, - content: format!("Response {}", i), - }); + context.add_message(Message::new(MessageRole::Assistant, format!("Response {}", i))) } // Trigger thinning at 50% @@ -172,27 +145,18 @@ fn test_todo_read_with_spaces_in_tool_name() { let mut context = ContextWindow::new(10000); // Add a todo_read tool call with spaces (JSON formatting variation) - context.add_message(Message { - role: MessageRole::Assistant, - content: r#"{"tool": "todo_read", "args": {}}"#.to_string(), - }); + context.add_message(Message::new(MessageRole::Assistant, r#"{"tool": "todo_read", "args": {}}"#.to_string())); // Add a large TODO result let large_todo_result = format!( "Tool result: 📝 TODO list:\n{}", "- [ ] Task\n".repeat(50) ); - context.add_message(Message { - role: MessageRole::User, - content: large_todo_result.clone(), - }); + context.add_message(Message::new(MessageRole::User, large_todo_result.clone())); // Add more messages for i in 0..6 { - context.add_message(Message { - role: MessageRole::Assistant, - content: format!("Response {}", i), - }); + context.add_message(Message::new(MessageRole::Assistant, format!("Response {}", i))) } // Trigger thinning diff --git a/crates/g3-core/tests/test_todo_persistence.rs b/crates/g3-core/tests/test_todo_persistence.rs index f43eed3..69baabd 100644 --- a/crates/g3-core/tests/test_todo_persistence.rs +++ b/crates/g3-core/tests/test_todo_persistence.rs @@ -27,7 +27,7 @@ fn get_todo_path(temp_dir: &TempDir) -> PathBuf { #[serial] async fn test_todo_write_creates_file() { let temp_dir = TempDir::new().unwrap(); - let agent = create_test_agent_in_dir(&temp_dir).await; + let mut agent = create_test_agent_in_dir(&temp_dir).await; let todo_path = get_todo_path(&temp_dir); // Initially, todo.g3.md should not exist @@ -67,7 +67,7 @@ async fn test_todo_read_from_file() { fs::write(&todo_path, test_content).unwrap(); // Create agent (should load from file) - let agent = create_test_agent_in_dir(&temp_dir).await; + let mut agent = create_test_agent_in_dir(&temp_dir).await; // Create a tool call to read TODO let tool_call = g3_core::ToolCall { @@ -88,7 +88,7 @@ async fn test_todo_read_from_file() { #[serial] async fn test_todo_read_empty_file() { let temp_dir = TempDir::new().unwrap(); - let agent = create_test_agent_in_dir(&temp_dir).await; + let mut agent = create_test_agent_in_dir(&temp_dir).await; // Create a tool call to read TODO (file doesn't exist) let tool_call = g3_core::ToolCall { @@ -111,7 +111,7 @@ async fn test_todo_persistence_across_agents() { // Agent 1: Write TODO { - let agent = create_test_agent_in_dir(&temp_dir).await; + let mut agent = create_test_agent_in_dir(&temp_dir).await; let tool_call = g3_core::ToolCall { tool: "todo_write".to_string(), args: serde_json::json!({ @@ -126,7 +126,7 @@ async fn test_todo_persistence_across_agents() { // Agent 2: Read TODO (new agent instance) { - let agent = create_test_agent_in_dir(&temp_dir).await; + let mut agent = create_test_agent_in_dir(&temp_dir).await; let tool_call = g3_core::ToolCall { tool: "todo_read".to_string(), args: serde_json::json!({}), @@ -143,7 +143,7 @@ async fn test_todo_persistence_across_agents() { #[serial] async fn test_todo_update_preserves_file() { let temp_dir = TempDir::new().unwrap(); - let agent = create_test_agent_in_dir(&temp_dir).await; + let mut agent = create_test_agent_in_dir(&temp_dir).await; let todo_path = get_todo_path(&temp_dir); // Write initial TODO @@ -173,7 +173,7 @@ async fn test_todo_update_preserves_file() { #[serial] async fn test_todo_handles_large_content() { let temp_dir = TempDir::new().unwrap(); - let agent = create_test_agent_in_dir(&temp_dir).await; + let mut agent = create_test_agent_in_dir(&temp_dir).await; let todo_path = get_todo_path(&temp_dir); // Create a large TODO (but under the 50k limit) @@ -202,7 +202,7 @@ async fn test_todo_handles_large_content() { #[serial] async fn test_todo_respects_size_limit() { let temp_dir = TempDir::new().unwrap(); - let agent = create_test_agent_in_dir(&temp_dir).await; + let mut agent = create_test_agent_in_dir(&temp_dir).await; // Create content that exceeds the default 50k limit let huge_content = "x".repeat(60_000); @@ -232,7 +232,7 @@ async fn test_todo_agent_initialization_loads_file() { fs::write(&todo_path, initial_content).unwrap(); // Create agent - should load the file during initialization - let agent = create_test_agent_in_dir(&temp_dir).await; + let mut agent = create_test_agent_in_dir(&temp_dir).await; // Read TODO - should return the pre-existing content let tool_call = g3_core::ToolCall { @@ -248,7 +248,7 @@ async fn test_todo_agent_initialization_loads_file() { #[serial] async fn test_todo_handles_unicode_content() { let temp_dir = TempDir::new().unwrap(); - let agent = create_test_agent_in_dir(&temp_dir).await; + let mut agent = create_test_agent_in_dir(&temp_dir).await; let todo_path = get_todo_path(&temp_dir); // Create TODO with unicode characters @@ -283,7 +283,7 @@ async fn test_todo_handles_unicode_content() { #[serial] async fn test_todo_empty_content_creates_empty_file() { let temp_dir = TempDir::new().unwrap(); - let agent = create_test_agent_in_dir(&temp_dir).await; + let mut agent = create_test_agent_in_dir(&temp_dir).await; let todo_path = get_todo_path(&temp_dir); // Write empty TODO @@ -306,7 +306,7 @@ async fn test_todo_empty_content_creates_empty_file() { #[serial] async fn test_todo_whitespace_only_content() { let temp_dir = TempDir::new().unwrap(); - let agent = create_test_agent_in_dir(&temp_dir).await; + let mut agent = create_test_agent_in_dir(&temp_dir).await; // Write whitespace-only TODO let tool_call = g3_core::ToolCall {