Skip to content

Commit 21ffeb9

Browse files
authored
Merge pull request #3 from abhishekanne/tests
Add new e2e tests and improvements
2 parents 0f8153b + bb3ba49 commit 21ffeb9

File tree

56 files changed

+2966
-2139
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2966
-2139
lines changed

e2etests/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ mcp = []
2121
ai_prompts = []
2222
issue_reporting = []
2323
tools=[]
24+
compact=[]
25+
hooks=[]
26+
usage=[]
27+
editor=[]
28+
subscribe=[]
2429

2530
[[test]]
2631
name = "test_help_command"

e2etests/run_simple_categorized.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ RUN_MCP=true
1717
RUN_AI_PROMPTS=true
1818
RUN_ISSUE_REPORTING=true
1919
RUN_TOOLS=true
20+
RUN_COMPACT=true
21+
RUN_HOOKS=true
22+
RUN_USAGE=true
23+
RUN_EDITOR=true
24+
RUN_SUBSCRIBE=true
2025
# ============================================================================
2126

2227
Q_BINARY="q"
@@ -215,6 +220,46 @@ if [ "$RUN_TOOLS" = true ]; then
215220
fi
216221
fi
217222

223+
if [ "$RUN_COMPACT" = true ]; then
224+
if run_category "compact" "COMPACT"; then
225+
((total_passed++))
226+
else
227+
((total_failed++))
228+
fi
229+
fi
230+
231+
if [ "$RUN_HOOKS" = true ]; then
232+
if run_category "hooks" "HOOKS"; then
233+
((total_passed++))
234+
else
235+
((total_failed++))
236+
fi
237+
fi
238+
239+
if [ "$RUN_USAGE" = true ]; then
240+
if run_category "usage" "USAGE"; then
241+
((total_passed++))
242+
else
243+
((total_failed++))
244+
fi
245+
fi
246+
247+
if [ "$RUN_EDITOR" = true ]; then
248+
if run_category "editor" "EDITOR"; then
249+
((total_passed++))
250+
else
251+
((total_failed++))
252+
fi
253+
fi
254+
255+
if [ "$RUN_SUBSCRIBE" = true ]; then
256+
if run_category "subscribe" "SUBSCRIBE"; then
257+
((total_passed++))
258+
else
259+
((total_failed++))
260+
fi
261+
fi
262+
218263
# Final summary
219264
echo ""
220265
echo "🎯 FINAL SUMMARY"

e2etests/src/lib.rs

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,37 @@
11
// Q CLI E2E Test Framework
22
// This library provides end-to-end testing utilities for Amazon Q CLI
33

4+
use std::sync::{Mutex, Once, atomic::{AtomicUsize, Ordering}};
5+
6+
static INIT: Once = Once::new();
7+
static mut CHAT_SESSION: Option<Mutex<q_chat_helper::QChatSession>> = None;
8+
9+
pub fn get_chat_session() -> &'static Mutex<q_chat_helper::QChatSession> {
10+
unsafe {
11+
INIT.call_once(|| {
12+
let chat = q_chat_helper::QChatSession::new().expect("Failed to create chat session");
13+
println!("✅ Q Chat session started");
14+
CHAT_SESSION = Some(Mutex::new(chat));
15+
});
16+
CHAT_SESSION.as_ref().unwrap()
17+
}
18+
}
19+
20+
pub fn cleanup_if_last_test(test_count: &AtomicUsize, total_tests: usize) -> Result<usize, Box<dyn std::error::Error>> {
21+
let count = test_count.fetch_add(1, Ordering::SeqCst) + 1;
22+
if count == total_tests {
23+
unsafe {
24+
if let Some(session) = &CHAT_SESSION {
25+
if let Ok(mut chat) = session.lock() {
26+
chat.quit()?;
27+
println!("✅ Test completed successfully");
28+
}
29+
}
30+
}
31+
}
32+
Ok(count)
33+
}
34+
435
pub mod q_chat_helper {
536
//! Helper module for Q CLI testing with hybrid approach
637
//! - expectrl for commands (/help, /tools)
@@ -107,17 +138,25 @@ pub mod q_chat_helper {
107138
},
108139
Ok(_) => {
109140
// No more data, but wait a bit more in case there's more coming
110-
std::thread::sleep(Duration::from_millis(200));
141+
std::thread::sleep(Duration::from_millis(2500));
111142
if total_content.len() > 0 { break; }
112143
},
113144
Err(_) => break,
114145
}
115-
std::thread::sleep(Duration::from_millis(200));
146+
std::thread::sleep(Duration::from_millis(2500));
116147
}
117148

118149
Ok(total_content)
119150
}
120151

152+
/// Send key input (like arrow keys, Enter, etc.)
153+
pub fn send_key_input(&mut self, key_sequence: &str) -> Result<String, Error> {
154+
self.session.write_all(key_sequence.as_bytes())?;
155+
self.session.flush()?;
156+
std::thread::sleep(Duration::from_millis(200));
157+
self.read_response()
158+
}
159+
121160
/// Quit the Q Chat session
122161
pub fn quit(&mut self) -> Result<(), Error> {
123162
self.session.send_line("/quit")?;

e2etests/tests/agent_without_subcommand.rs

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

e2etests/tests/test_add_file_context.rs

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

e2etests/tests/test_add_globe_pattern_file_context.rs

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

e2etests/tests/test_add_multiple_file_context.rs

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

e2etests/tests/test_add_non_existing_file_context.rs

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

0 commit comments

Comments
 (0)