Skip to content

Commit 6da0041

Browse files
committed
Refactor: Remove verbose from MCP context and save/load and fixed the failing test case for adding multiple file as context.
1 parent d65314c commit 6da0041

File tree

6 files changed

+109
-232
lines changed

6 files changed

+109
-232
lines changed

e2etests/run_context.clean.sh

Lines changed: 0 additions & 30 deletions
This file was deleted.

e2etests/run_save_load_clean.sh

Lines changed: 0 additions & 30 deletions
This file was deleted.

e2etests/test_core_session_clean.sh

Lines changed: 0 additions & 30 deletions
This file was deleted.

e2etests/tests/context/test_context_command.rs

Lines changed: 77 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ const TEST_NAMES: &[&str] = &[
1616
"test_context_remove_command_of_non_existent_file",
1717
"test_add_remove_file_context",
1818
"test_add_glob_pattern_file_context",
19-
"test_clear_context_command",
20-
"test_add_remove_multiple_file_context"
19+
"test_add_remove_multiple_file_context",
20+
"test_clear_context_command"
2121
];
2222
#[allow(dead_code)]
2323
const TOTAL_TESTS: usize = TEST_NAMES.len();
@@ -72,12 +72,12 @@ fn test_context_help_command() -> Result<(), Box<dyn std::error::Error>> {
7272
println!("📝 END OUTPUT");
7373

7474
// Verify Usage section
75-
assert!(response.contains("Usage:"), "Missing Usage section");
75+
assert!(response.contains("Usage"), "Missing Usage section");
7676
assert!(response.contains("/context") && response.contains("<COMMAND>"), "Missing /context command in usage");
7777
println!("✅ Found Usage section");
7878

7979
// Verify Commands section
80-
assert!(response.contains("Commands:"), "Missing Commands section");
80+
assert!(response.contains("Commands"), "Missing Commands section");
8181
assert!(response.contains("show"), "Missing show command");
8282
assert!(response.contains("add"), "Missing add command");
8383
assert!(response.contains("remove"), "Missing remove command");
@@ -113,11 +113,11 @@ fn test_context_without_subcommand() -> Result<(), Box<dyn std::error::Error>> {
113113
println!("{}", response);
114114
println!("📝 END OUTPUT");
115115

116-
assert!(response.contains("Usage:"), "Missing Usage section");
116+
assert!(response.contains("Usage"), "Missing Usage section");
117117
assert!(response.contains("/context") && response.contains("<COMMAND>"), "Missing /context command in usage");
118118
println!("✅ Found Usage section with /context command");
119119

120-
assert!(response.contains("Commands:"), "Missing Commands section");
120+
assert!(response.contains("Commands"), "Missing Commands section");
121121
assert!(response.contains("show"), "Missing show command");
122122
assert!(response.contains("add"), "Missing add command");
123123
assert!(response.contains("remove"), "Missing remove command");
@@ -213,7 +213,7 @@ fn test_context_remove_command_of_non_existent_file() -> Result<(), Box<dyn std:
213213
println!("📝 END OUTPUT");
214214

215215
// Verify error message for non-existent file
216-
assert!(response.contains("Error:"), "Missing error message for non-existent file");
216+
assert!(response.contains("Error"), "Missing error message for non-existent file");
217217
println!("✅ Found expected error message for non-existent file removal");
218218

219219
// Release the lock before cleanup
@@ -383,29 +383,33 @@ fn test_add_glob_pattern_file_context()-> Result<(), Box<dyn std::error::Error>>
383383

384384
#[test]
385385
#[cfg(all(feature = "context", feature = "regression"))]
386-
fn test_clear_context_command()-> Result<(), Box<dyn std::error::Error>> {
387-
println!("🔍 Testing /context clear command...");
388-
389-
let test_file_path = "/tmp/test_context_file.py";
386+
fn test_add_remove_multiple_file_context()-> Result<(), Box<dyn std::error::Error>> {
387+
println!("🔍 Testing /context add <filename1> <filename2> <filename3> command and /context remove <filename1> <filename2> <filename3>...");
388+
389+
let test_file1_path = "/tmp/test_context_file1.py";
390+
let test_file2_path = "/tmp/test_context_file2.py";
391+
let test_file3_path = "/tmp/test_context_file.js";
390392

391393
// Create test files
392-
std::fs::write(test_file_path, "# Test Python file 1 for context\nprint('Hello from Python file 1')")?;
393-
println!("✅ Created test files at {}", test_file_path);
394+
std::fs::write(test_file1_path, "# Test Python file 1 for context\nprint('Hello from Python file 1')")?;
395+
std::fs::write(test_file2_path, "# Test Python file 2 for context\nprint('Hello from Python file 2')")?;
396+
std::fs::write(test_file3_path, "// Test JavaScript file\nconsole.log('Hello from JS file');")?;
397+
println!("✅ Created test files at {}, {}, {}", test_file1_path, test_file2_path, test_file3_path);
394398

395399
let session = get_chat_session();
396400
let mut chat = session.lock().unwrap_or_else(|poisoned| poisoned.into_inner());
397-
398-
// Add multiple files to context
399-
let add_response = chat.execute_command(&format!("/context add {}", test_file_path))?;
401+
402+
// Add multiple files to context in one command
403+
let add_response = chat.execute_command(&format!("/context add {} {} {}", test_file1_path, test_file2_path, test_file3_path))?;
400404

401405
println!("📝 Context add response: {} bytes", add_response.len());
402406
println!("📝 ADD RESPONSE:");
403407
println!("{}", add_response);
404408
println!("📝 END ADD RESPONSE");
405409

406410
// Verify files were added successfully - be flexible with the exact message format
407-
assert!(add_response.contains("Added"), "Missing success message for adding files");
408-
println!("✅ Files added to context successfully");
411+
assert!(add_response.contains("Added"), "Missing success message for adding multiple files");
412+
println!("✅ Multiple files added to context successfully");
409413

410414
// Execute /context show to confirm files are present
411415
let show_response = chat.execute_command("/context show")?;
@@ -415,41 +419,45 @@ fn test_clear_context_command()-> Result<(), Box<dyn std::error::Error>> {
415419
println!("{}", show_response);
416420
println!("📝 END SHOW RESPONSE");
417421

418-
// Verify files are present in context
419-
assert!(show_response.contains(test_file_path), "Python file not found in context show output");
420-
println!("✅ Files confirmed present in context");
421-
422-
// Execute /context clear to remove all files
423-
let clear_response = chat.execute_command("/context clear")?;
422+
// Verify all files are present in context
423+
assert!(show_response.contains(test_file1_path), "Python file not found in context show output");
424+
assert!(show_response.contains(test_file2_path), "JavaScript file not found in context show output");
425+
assert!(show_response.contains(test_file3_path), "Text file not found in context show output");
426+
println!("✅ All files confirmed present in context");
427+
428+
// Remove multiple files from context
429+
let remove_response = chat.execute_command(&format!("/context remove {} {} {}", test_file1_path, test_file2_path, test_file3_path))?;
424430

425-
println!("📝 Context clear response: {} bytes", clear_response.len());
426-
println!("📝 CLEAR RESPONSE:");
427-
println!("{}", clear_response);
428-
println!("📝 END CLEAR RESPONSE");
431+
println!("📝 Context remove response: {} bytes", remove_response.len());
432+
println!("📝 REMOVE RESPONSE:");
433+
println!("{}", remove_response);
434+
println!("📝 END REMOVE RESPONSE");
429435

430-
// Verify context was cleared successfully
431-
assert!(clear_response.contains("Cleared context"), "Missing success message for clearing context");
432-
println!("✅ Context cleared successfully");
436+
// Verify files were removed successfully - be flexible with the exact message format
437+
assert!(remove_response.contains("Removed"), "Missing success message for removing multiple files");
438+
println!("✅ Multiple files removed from context successfully");
433439

434-
// Execute /context show to confirm no files remain
440+
// Execute /context show to confirm files are gone
435441
let final_show_response = chat.execute_command("/context show")?;
436442

437443
println!("📝 Final context show response: {} bytes", final_show_response.len());
438444
println!("📝 FINAL SHOW RESPONSE:");
439445
println!("{}", final_show_response);
440446
println!("📝 END FINAL SHOW RESPONSE");
441447

442-
// Verify no files remain in context
443-
assert!(!final_show_response.contains(test_file_path), "Python file still found in context after clear");
444-
assert!(final_show_response.contains("Agent (q_cli_default):"), "Missing Agent section");
445-
assert!(final_show_response.contains("<none>"), "Missing <none> indicator for cleared context");
446-
println!("✅ All files confirmed removed from context and <none> sections present");
448+
// Verify files are no longer in context
449+
assert!(!final_show_response.contains(test_file1_path), "Python file still found in context after removal");
450+
assert!(!final_show_response.contains(test_file2_path), "JavaScript file still found in context after removal");
451+
assert!(!final_show_response.contains(test_file3_path), "Text file still found in context after removal");
452+
println!("✅ All files confirmed removed from context");
447453

448454
// Release the lock before cleanup
449455
drop(chat);
450456

451457
// Clean up test file
452-
let _ = std::fs::remove_file(test_file_path);
458+
let _ = std::fs::remove_file(test_file1_path);
459+
let _ = std::fs::remove_file(test_file2_path);
460+
let _ = std::fs::remove_file(test_file3_path);
453461
println!("✅ Cleaned up test file");
454462

455463
// Cleanup only if this is the last test
@@ -460,33 +468,29 @@ fn test_clear_context_command()-> Result<(), Box<dyn std::error::Error>> {
460468

461469
#[test]
462470
#[cfg(all(feature = "context", feature = "regression"))]
463-
fn test_add_remove_multiple_file_context()-> Result<(), Box<dyn std::error::Error>> {
464-
println!("🔍 Testing /context add <filename1> <filename2> <filename3> command and /context remove <filename1> <filename2> <filename3>...");
465-
466-
let test_file1_path = "/tmp/test_context_file1.py";
467-
let test_file2_path = "/tmp/test_context_file2.py";
468-
let test_file3_path = "/tmp/test_context_file.js";
471+
fn test_clear_context_command()-> Result<(), Box<dyn std::error::Error>> {
472+
println!("🔍 Testing /context clear command...");
473+
474+
let test_file_path = "/tmp/test_context_file.py";
469475

470476
// Create test files
471-
std::fs::write(test_file1_path, "# Test Python file 1 for context\nprint('Hello from Python file 1')")?;
472-
std::fs::write(test_file2_path, "# Test Python file 2 for context\nprint('Hello from Python file 2')")?;
473-
std::fs::write(test_file3_path, "// Test JavaScript file\nconsole.log('Hello from JS file');")?;
474-
println!("✅ Created test files at {}, {}, {}", test_file1_path, test_file2_path, test_file3_path);
477+
std::fs::write(test_file_path, "# Test Python file 1 for context\nprint('Hello from Python file 1')")?;
478+
println!("✅ Created test files at {}", test_file_path);
475479

476480
let session = get_chat_session();
477481
let mut chat = session.lock().unwrap_or_else(|poisoned| poisoned.into_inner());
478-
479-
// Add multiple files to context in one command
480-
let add_response = chat.execute_command(&format!("/context add {} {} {}", test_file1_path, test_file2_path, test_file3_path))?;
482+
483+
// Add multiple files to context
484+
let add_response = chat.execute_command(&format!("/context add {}", test_file_path))?;
481485

482486
println!("📝 Context add response: {} bytes", add_response.len());
483487
println!("📝 ADD RESPONSE:");
484488
println!("{}", add_response);
485489
println!("📝 END ADD RESPONSE");
486490

487491
// Verify files were added successfully - be flexible with the exact message format
488-
assert!(add_response.contains("Added"), "Missing success message for adding multiple files");
489-
println!("✅ Multiple files added to context successfully");
492+
assert!(add_response.contains("Added"), "Missing success message for adding files");
493+
println!("✅ Files added to context successfully");
490494

491495
// Execute /context show to confirm files are present
492496
let show_response = chat.execute_command("/context show")?;
@@ -496,45 +500,41 @@ fn test_add_remove_multiple_file_context()-> Result<(), Box<dyn std::error::Erro
496500
println!("{}", show_response);
497501
println!("📝 END SHOW RESPONSE");
498502

499-
// Verify all files are present in context
500-
assert!(show_response.contains(test_file1_path), "Python file not found in context show output");
501-
assert!(show_response.contains(test_file2_path), "JavaScript file not found in context show output");
502-
assert!(show_response.contains(test_file3_path), "Text file not found in context show output");
503-
println!("✅ All files confirmed present in context");
504-
505-
// Remove multiple files from context
506-
let remove_response = chat.execute_command(&format!("/context remove {} {} {}", test_file1_path, test_file2_path, test_file3_path))?;
503+
// Verify files are present in context
504+
assert!(show_response.contains(test_file_path), "Python file not found in context show output");
505+
println!("✅ Files confirmed present in context");
507506

508-
println!("📝 Context remove response: {} bytes", remove_response.len());
509-
println!("📝 REMOVE RESPONSE:");
510-
println!("{}", remove_response);
511-
println!("📝 END REMOVE RESPONSE");
507+
// Execute /context clear to remove all files
508+
let clear_response = chat.execute_command("/context clear")?;
512509

513-
// Verify files were removed successfully - be flexible with the exact message format
514-
assert!(remove_response.contains("Removed"), "Missing success message for removing multiple files");
515-
println!("✅ Multiple files removed from context successfully");
510+
println!("📝 Context clear response: {} bytes", clear_response.len());
511+
println!("📝 CLEAR RESPONSE:");
512+
println!("{}", clear_response);
513+
println!("📝 END CLEAR RESPONSE");
516514

517-
// Execute /context show to confirm files are gone
515+
// Verify context was cleared successfully
516+
assert!(clear_response.contains("Cleared context"), "Missing success message for clearing context");
517+
println!("✅ Context cleared successfully");
518+
519+
// Execute /context show to confirm no files remain
518520
let final_show_response = chat.execute_command("/context show")?;
519521

520522
println!("📝 Final context show response: {} bytes", final_show_response.len());
521523
println!("📝 FINAL SHOW RESPONSE:");
522524
println!("{}", final_show_response);
523525
println!("📝 END FINAL SHOW RESPONSE");
524526

525-
// Verify files are no longer in context
526-
assert!(!final_show_response.contains(test_file1_path), "Python file still found in context after removal");
527-
assert!(!final_show_response.contains(test_file2_path), "JavaScript file still found in context after removal");
528-
assert!(!final_show_response.contains(test_file3_path), "Text file still found in context after removal");
529-
println!("✅ All files confirmed removed from context");
527+
// Verify no files remain in context
528+
assert!(!final_show_response.contains(test_file_path), "Python file still found in context after clear");
529+
assert!(final_show_response.contains("Agent (q_cli_default):"), "Missing Agent section");
530+
assert!(final_show_response.contains("<none>"), "Missing <none> indicator for cleared context");
531+
println!("✅ All files confirmed removed from context and <none> sections present");
530532

531533
// Release the lock before cleanup
532534
drop(chat);
533535

534536
// Clean up test file
535-
let _ = std::fs::remove_file(test_file1_path);
536-
let _ = std::fs::remove_file(test_file2_path);
537-
let _ = std::fs::remove_file(test_file3_path);
537+
let _ = std::fs::remove_file(test_file_path);
538538
println!("✅ Cleaned up test file");
539539

540540
// Cleanup only if this is the last test

0 commit comments

Comments
 (0)