Skip to content

Add new e2e tests and improvements #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: tests
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions e2etests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ mcp = []
ai_prompts = []
issue_reporting = []
tools=[]
compact=[]
hooks=[]
usage=[]
editor=[]
subscribe=[]

[[test]]
name = "test_help_command"
Expand Down
45 changes: 45 additions & 0 deletions e2etests/run_simple_categorized.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ RUN_MCP=true
RUN_AI_PROMPTS=true
RUN_ISSUE_REPORTING=true
RUN_TOOLS=true
RUN_COMPACT=true
RUN_HOOKS=true
RUN_USAGE=true
RUN_EDITOR=true
RUN_SUBSCRIBE=true
# ============================================================================

Q_BINARY="q"
Expand Down Expand Up @@ -215,6 +220,46 @@ if [ "$RUN_TOOLS" = true ]; then
fi
fi

if [ "$RUN_COMPACT" = true ]; then
if run_category "compact" "COMPACT"; then
((total_passed++))
else
((total_failed++))
fi
fi

if [ "$RUN_HOOKS" = true ]; then
if run_category "hooks" "HOOKS"; then
((total_passed++))
else
((total_failed++))
fi
fi

if [ "$RUN_USAGE" = true ]; then
if run_category "usage" "USAGE"; then
((total_passed++))
else
((total_failed++))
fi
fi

if [ "$RUN_EDITOR" = true ]; then
if run_category "editor" "EDITOR"; then
((total_passed++))
else
((total_failed++))
fi
fi

if [ "$RUN_SUBSCRIBE" = true ]; then
if run_category "subscribe" "SUBSCRIBE"; then
((total_passed++))
else
((total_failed++))
fi
fi

# Final summary
echo ""
echo "🎯 FINAL SUMMARY"
Expand Down
12 changes: 10 additions & 2 deletions e2etests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,25 @@ pub mod q_chat_helper {
},
Ok(_) => {
// No more data, but wait a bit more in case there's more coming
std::thread::sleep(Duration::from_millis(200));
std::thread::sleep(Duration::from_millis(2000));
if total_content.len() > 0 { break; }
},
Err(_) => break,
}
std::thread::sleep(Duration::from_millis(200));
std::thread::sleep(Duration::from_millis(2000));
}

Ok(total_content)
}

/// Send key input (like arrow keys, Enter, etc.)
pub fn send_key_input(&mut self, key_sequence: &str) -> Result<String, Error> {
self.session.write_all(key_sequence.as_bytes())?;
self.session.flush()?;
std::thread::sleep(Duration::from_millis(200));
self.read_response()
}

/// Quit the Q Chat session
pub fn quit(&mut self) -> Result<(), Error> {
self.session.send_line("/quit")?;
Expand Down
55 changes: 0 additions & 55 deletions e2etests/tests/agent_without_subcommand.rs

This file was deleted.

100 changes: 100 additions & 0 deletions e2etests/tests/test_add_and_remove_mcp_command.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
use q_cli_e2e_tests::q_chat_helper::QChatSession;

#[test]
#[cfg(feature = "mcp")]
fn test_add_and_remove_mcp_command() -> Result<(), Box<dyn std::error::Error>> {
println!("🔍 Testing q mcp add command...");

// First install uv dependency before starting Q Chat
println!("🔍 Installing uv dependency...");
std::process::Command::new("pip3")
.args(["install", "uv", "--break-system-packages"])
.output()
.expect("Failed to install uv");
println!("✅ uv dependency installed");

let mut chat = QChatSession::new()?;
println!("✅ Q Chat session started");

// Execute mcp add command
println!("🔍 Executing command: 'q mcp add --name aws-documentation --command uvx --args awslabs.aws-documentation-mcp-server@latest'");
let response = chat.execute_command("q mcp add --name aws-documentation --command uvx --args awslabs.aws-documentation-mcp-server@latest")?;

println!("📝 Response: {} bytes", response.len());
println!("📝 RESPONSE:");
println!("{}", response);
println!("📝 END RESPONSE");

// Verify tool execution details
assert!(response.contains("I will run the following shell command:"), "Missing command execution description");
assert!(response.contains("q mcp add --name aws-documentation --command uvx --args awslabs.aws-documentation-mcp-server@latest"), "Missing full command");
assert!(response.contains("Purpose:") && response.contains("Add AWS documentation MCP server"), "Missing purpose description");
println!("✅ Found tool execution details");

// Verify tool execution prompt appears
assert!(response.contains("🛠️ Using tool: execute_bash"), "Missing tool execution indicator");
assert!(response.contains("Allow this action?") && response.contains("to trust (always allow) this tool for the session."), "Missing permission prompt");
println!("✅ Found tool execution permission prompt");

// Allow the tool execution
let allow_response = chat.execute_command("y")?;

println!("📝 Allow response: {} bytes", allow_response.len());
println!("📝 ALLOW RESPONSE:");
println!("{}", allow_response);
println!("📝 END ALLOW RESPONSE");

// Verify successful addition
assert!(allow_response.contains("✓ Added MCP server") && allow_response.contains("'aws-documentation'") && allow_response.contains("to global config in"), "Missing success message");
assert!(allow_response.contains("/Users/") && allow_response.contains("/.aws/amazonq/mcp.json"), "Missing config file path");
println!("✅ Found successful addition message");

// Verify completion indicator
assert!(allow_response.contains("Completed in") && allow_response.contains("s"), "Missing completion time indicator");
println!("✅ Found completion indicator");

println!("✅ All q mcp add command execution verified successfully");

// Now test removing the MCP server
println!("🔍 Executing remove command: 'q mcp remove --name aws-documentation'");
let remove_response = chat.execute_command("q mcp remove --name aws-documentation")?;

println!("📝 Remove response: {} bytes", remove_response.len());
println!("📝 REMOVE RESPONSE:");
println!("{}", remove_response);
println!("📝 END REMOVE RESPONSE");

// Verify remove tool execution details
assert!(remove_response.contains("I will run the following shell command:"), "Missing remove command execution description");
assert!(remove_response.contains("q mcp remove --name aws-documentation"), "Missing full remove command");
println!("✅ Found remove tool execution details");

// Verify remove tool execution prompt
assert!(remove_response.contains("🛠️ Using tool: execute_bash"), "Missing remove tool execution indicator");
assert!(remove_response.contains("Allow this action?"), "Missing remove permission prompt");
println!("✅ Found remove tool execution permission prompt");

// Allow the remove tool execution
let remove_allow_response = chat.execute_command("y")?;

println!("📝 Remove allow response: {} bytes", remove_allow_response.len());
println!("📝 REMOVE ALLOW RESPONSE:");
println!("{}", remove_allow_response);
println!("📝 END REMOVE ALLOW RESPONSE");

// Verify successful removal
assert!(remove_allow_response.contains("✓ Removed MCP server") && remove_allow_response.contains("'aws-documentation'") && remove_allow_response.contains("from global config"), "Missing removal success message");
assert!(remove_allow_response.contains("/Users/") && remove_allow_response.contains("/.aws/amazonq/mcp.json"), "Missing config file path in removal");
println!("✅ Found successful removal message");

// Verify remove completion indicator
assert!(remove_allow_response.contains("Completed in") && remove_allow_response.contains("s"), "Missing remove completion time indicator");
println!("✅ Found remove completion indicator");

println!("✅ All q mcp remove command execution verified successfully");

chat.quit()?;
println!("✅ Test completed successfully");

Ok(())
}
51 changes: 0 additions & 51 deletions e2etests/tests/test_add_file_context.rs

This file was deleted.

59 changes: 0 additions & 59 deletions e2etests/tests/test_add_globe_pattern_file_context.rs

This file was deleted.

Loading