Skip to content

Commit 55af456

Browse files
add new tests for editor,compact feature and description for editor , comoact feature test cases
1 parent 9552cee commit 55af456

File tree

2 files changed

+116
-9
lines changed

2 files changed

+116
-9
lines changed

e2etests/tests/integration/test_editor_help_command.rs

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const TEST_NAMES: &[&str] = &[
1313
"test_editor_h_command",
1414
"test_editor_command_interaction",
1515
"test_editor_command_error",
16+
"test_editor_with_file_path",
1617
];
1718
#[allow(dead_code)]
1819
const TOTAL_TESTS: usize = TEST_NAMES.len();
@@ -182,7 +183,7 @@ fn test_editor_h_command() -> Result<(), Box<dyn std::error::Error>> {
182183
#[test]
183184
#[cfg(all(feature = "editor", feature = "sanity"))]
184185
fn test_editor_command_interaction() -> Result<(), Box<dyn std::error::Error>> {
185-
println!("🔍 Testing /editor command interaction...");
186+
println!("🔍 Testing /editor command interaction... | Description: Test that the /editor command successfully launches the integrated editor interface");
186187

187188
let session = get_chat_session();
188189
let mut chat = session.lock().unwrap_or_else(|poisoned| poisoned.into_inner());
@@ -233,7 +234,7 @@ fn test_editor_command_interaction() -> Result<(), Box<dyn std::error::Error>> {
233234
#[test]
234235
#[cfg(all(feature = "editor", feature = "sanity"))]
235236
fn test_editor_command_error() -> Result<(), Box<dyn std::error::Error>> {
236-
println!("🔍 Testing /editor command error handling");
237+
println!("🔍 Testing /editor command error handling ... | Description: Tests the /editor <non_exixt_filepath> command error handling when attempting to open a nonexistent file");
237238

238239
let session = get_chat_session();
239240
let mut chat = session.lock().unwrap_or_else(|poisoned| poisoned.into_inner());
@@ -278,5 +279,62 @@ fn test_editor_command_error() -> Result<(), Box<dyn std::error::Error>> {
278279
// Cleanup only if this is the last test
279280
cleanup_if_last_test(&TEST_COUNT, TOTAL_TESTS)?;
280281

282+
Ok(())
283+
}
284+
285+
#[test]
286+
#[cfg(all(feature = "editor", feature = "sanity"))]
287+
fn test_editor_with_file_path() -> Result<(), Box<dyn std::error::Error>> {
288+
println!("🔍 Testing /editor <filepath> command... | Description: Tests the /editor <filepath> command to load an existing file into the editor and verify content loading");
289+
290+
let home_dir = std::env::var("HOME").unwrap_or_else(|_| "/tmp".to_string());
291+
let test_file_path = format!("{}/test_editor_file.txt", home_dir);
292+
293+
// Create a test file
294+
std::fs::write(&test_file_path, "Hello from test file\nThis is a test file for editor command.")?;
295+
println!("✅ Created test file at {}", test_file_path);
296+
297+
let session = get_chat_session();
298+
let mut chat = session.lock().unwrap_or_else(|poisoned| poisoned.into_inner());
299+
300+
// Execute /editor command with file path
301+
let response = chat.execute_command(&format!("/editor {}", test_file_path))?;
302+
303+
println!("📝 Editor with file response: {} bytes", response.len());
304+
println!("📝 FULL OUTPUT:");
305+
println!("{}", response);
306+
println!("📝 END OUTPUT");
307+
308+
// Press 'i' to enter insert mode
309+
let insert_response = chat.execute_command("i")?;
310+
println!("📝 Insert mode response: {} bytes", insert_response.len());
311+
312+
313+
// Press Esc to exit insert mode
314+
let esc_response = chat.execute_command("\x1b")?; // ESC key
315+
println!("📝 Esc response: {} bytes", esc_response.len());
316+
317+
// Execute :wq to save and quit
318+
let wq_response = chat.execute_command(":wq")?;
319+
320+
println!("📝 Final wq response: {} bytes", wq_response.len());
321+
println!("📝 WQ RESPONSE:");
322+
println!("{}", wq_response);
323+
println!("📝 END WQ RESPONSE");
324+
325+
// Verify the file content is loaded in editor
326+
assert!(wq_response.contains("Hello from test file"), "File content not loaded in editor");
327+
println!("✅ File content loaded successfully in editor");
328+
329+
// Clean up test file
330+
std::fs::remove_file(test_file_path).ok();
331+
println!("✅ Cleaned up test file");
332+
333+
// Release the lock before cleanup
334+
drop(chat);
335+
336+
// Cleanup only if this is the last test
337+
cleanup_if_last_test(&TEST_COUNT, TOTAL_TESTS)?;
338+
281339
Ok(())
282340
}

e2etests/tests/session_mgmt/test_compact_command.rs

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ fn test_compact_h_command() -> Result<(), Box<dyn std::error::Error>> {
184184
#[test]
185185
#[cfg(all(feature = "compact", feature = "sanity"))]
186186
fn test_compact_truncate_true_command() -> Result<(), Box<dyn std::error::Error>> {
187-
println!("🔍 Testing /compact --truncate-large-messages true command...");
187+
println!("🔍 Testing /compact --truncate-large-messages true command... | Description: Test that the /compact —truncate-large-messages truncates large messages");
188188

189189
let session = get_chat_session();
190190
let mut chat = session.lock().unwrap_or_else(|poisoned| poisoned.into_inner());
@@ -228,7 +228,7 @@ fn test_compact_truncate_true_command() -> Result<(), Box<dyn std::error::Error>
228228
#[test]
229229
#[cfg(all(feature = "compact", feature = "sanity"))]
230230
fn test_compact_truncate_false_command() -> Result<(), Box<dyn std::error::Error>> {
231-
println!("🔍 Testing /compact --truncate-large-messages false command...");
231+
println!("🔍 Testing /compact --truncate-large-messages false command... | Description: Tests the /compact --truncate-large-messages false command to verify no message truncation occurs");
232232

233233
let session = get_chat_session();
234234
let mut chat = session.lock().unwrap_or_else(|poisoned| poisoned.into_inner());
@@ -271,7 +271,7 @@ fn test_compact_truncate_false_command() -> Result<(), Box<dyn std::error::Error
271271
#[test]
272272
#[cfg(all(feature = "compact", feature = "sanity"))]
273273
fn test_show_summary() -> Result<(), Box<dyn std::error::Error>> {
274-
println!("🔍 Testing /compact --show-summary command...");
274+
println!("🔍 Testing /compact --show-summary command... | Description: Tests the /compact --show-summary command to display conversation summary after compaction");
275275

276276
let session = get_chat_session();
277277
let mut chat = session.lock().unwrap_or_else(|poisoned| poisoned.into_inner());
@@ -322,7 +322,7 @@ fn test_show_summary() -> Result<(), Box<dyn std::error::Error>> {
322322
#[test]
323323
#[cfg(all(feature = "compact", feature = "sanity"))]
324324
fn test_max_message_truncate_true() -> Result<(), Box<dyn std::error::Error>> {
325-
println!("🔍 Testing /compact --truncate-large-messages true --max-message-length command...");
325+
println!("🔍 Testing /compact --truncate-large-messages true --max-message-length command... | Description: Test /compact --truncate-large-messages true --max-message-length <MAX_MESSAGE_LENGTH> command compacts the conversation by summarizing it to free up context space, truncating large messages to a maximum of provided <MAX_MESSAGE_LENGTH>. ");
326326

327327
let session = get_chat_session();
328328
let mut chat = session.lock().unwrap_or_else(|poisoned| poisoned.into_inner());
@@ -376,7 +376,7 @@ fn test_max_message_truncate_true() -> Result<(), Box<dyn std::error::Error>> {
376376
#[test]
377377
#[cfg(all(feature = "compact", feature = "sanity"))]
378378
fn test_max_message_truncate_false() -> Result<(), Box<dyn std::error::Error>> {
379-
println!("🔍 Testing /compact --truncate-large-messages false --max-message-length command...");
379+
println!("🔍 Testing /compact --truncate-large-messages false --max-message-length command... | Description: Test /compact --truncate-large-messages false --max-message-length <MAX_MESSAGE_LENGTH> command compacts the conversation by summarizing it to free up context space, but keeps large messages intact (no truncation) despite the max-message-length setting.");
380380

381381
let session = get_chat_session();
382382
let mut chat = session.lock().unwrap_or_else(|poisoned| poisoned.into_inner());
@@ -427,7 +427,7 @@ fn test_max_message_truncate_false() -> Result<(), Box<dyn std::error::Error>> {
427427
#[test]
428428
#[cfg(all(feature = "compact", feature = "sanity"))]
429429
fn test_max_message_length_invalid() -> Result<(), Box<dyn std::error::Error>> {
430-
println!("🔍 Testing /compact --max-message-length command...");
430+
println!("🔍 Testing /compact --max-message-length command... | Description: Tests the /compact --max-message-length <MAX_MESSAGE_LENGTH> command with invalid subcommand to verify proper error handling and help display");
431431

432432
let session = get_chat_session();
433433
let mut chat = session.lock().unwrap_or_else(|poisoned| poisoned.into_inner());
@@ -467,4 +467,53 @@ fn test_max_message_length_invalid() -> Result<(), Box<dyn std::error::Error>> {
467467
cleanup_if_last_test(&TEST_COUNT, TOTAL_TESTS)?;
468468

469469
Ok(())
470-
}
470+
}
471+
472+
#[test]
473+
#[cfg(all(feature = "compact", feature = "sanity"))]
474+
fn test_compact_messages_to_exclude_command() -> Result<(), Box<dyn std::error::Error>> {
475+
println!("\n🔍 Testing /compact command... | Description: Test /compact --messages-to-exclude <MESSAGES_TO_EXCLUDE> command compacts the conversation by summarizing it to free up context space, excluding provided number of user-assistant message pair from the summarization process.");
476+
477+
let session = get_chat_session();
478+
let mut chat = session.lock().unwrap_or_else(|poisoned| poisoned.into_inner());
479+
480+
let response = chat.execute_command("What is AWS?")?;
481+
482+
println!("📝 AI response: {} bytes", response.len());
483+
println!("📝 FULL OUTPUT:");
484+
println!("{}", response);
485+
println!("📝 END OUTPUT");
486+
487+
let response = chat.execute_command("What is fibonacci?")?;
488+
489+
println!("📝 AI response: {} bytes", response.len());
490+
println!("📝 FULL OUTPUT:");
491+
println!("{}", response);
492+
println!("📝 END OUTPUT");
493+
494+
let response = chat.execute_command("/compact --messages-to-exclude 1")?;
495+
496+
println!("📝 Compact response: {} bytes", response.len());
497+
println!("📝 FULL OUTPUT:");
498+
println!("{}", response);
499+
println!("📝 END OUTPUT");
500+
501+
// Verify compact response - either success or too short
502+
if response.contains("history") && response.contains("compacted") && response.contains("successfully") {
503+
println!("✅ Found compact success message");
504+
} else if response.contains("Conversation") && response.contains("short") {
505+
println!("✅ Found conversation too short message");
506+
} else {
507+
panic!("Missing expected compact response");
508+
}
509+
510+
println!("✅ All compact content verified!");
511+
512+
// Release the lock before cleanup
513+
drop(chat);
514+
515+
// Cleanup only if this is the last test
516+
cleanup_if_last_test(&TEST_COUNT, TOTAL_TESTS)?;
517+
518+
Ok(())
519+
}

0 commit comments

Comments
 (0)