Skip to content

Commit bb3ba49

Browse files
QCLI Automation for hooks,usage,issue,tools,subscribe,model,compact,editor tests
1 parent 5452ba1 commit bb3ba49

9 files changed

+387
-160
lines changed

e2etests/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,12 @@ pub mod q_chat_helper {
138138
},
139139
Ok(_) => {
140140
// No more data, but wait a bit more in case there's more coming
141-
std::thread::sleep(Duration::from_millis(2000));
141+
std::thread::sleep(Duration::from_millis(2500));
142142
if total_content.len() > 0 { break; }
143143
},
144144
Err(_) => break,
145145
}
146-
std::thread::sleep(Duration::from_millis(2000));
146+
std::thread::sleep(Duration::from_millis(2500));
147147
}
148148

149149
Ok(total_content)

e2etests/tests/test_compact_command.rs

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
use q_cli_e2e_tests::q_chat_helper::QChatSession;
1+
use q_cli_e2e_tests::{get_chat_session, cleanup_if_last_test};
2+
use std::sync::atomic::{AtomicUsize, Ordering};
23

3-
#[test]
4-
#[cfg(feature = "compact")]
4+
static TEST_COUNT: AtomicUsize = AtomicUsize::new(0);
55

6-
fn test_all_compact_commands() -> Result<(), Box<dyn std::error::Error>> {
7-
let mut chat = QChatSession::new()?;
8-
println!(":white_check_mark: Q Chat session started");
9-
10-
test_compact_command(&mut chat)?;
11-
test_compact_help_command(&mut chat)?;
12-
13-
chat.quit()?;
14-
println!(":white_check_mark: All tests completed successfully");
15-
Ok(())
16-
}
6+
// List of covered tests
7+
const TEST_NAMES: &[&str] = &[
8+
"test_compact_command",
9+
"test_compact_help_command",
10+
];
11+
const TOTAL_TESTS: usize = TEST_NAMES.len();
1712

18-
fn test_compact_command(chat: &mut QChatSession) -> Result<(), Box<dyn std::error::Error>> {
13+
#[test]
14+
#[cfg(feature = "compact")]
15+
fn test_compact_command() -> Result<(), Box<dyn std::error::Error>> {
1916
println!("🔍 Testing /compact command...");
2017

18+
let session = get_chat_session();
19+
let mut chat = session.lock().unwrap();
20+
2121
let response = chat.execute_command("/compact")?;
2222

2323
println!("📝 Compact response: {} bytes", response.len());
@@ -36,12 +36,23 @@ fn test_compact_command(chat: &mut QChatSession) -> Result<(), Box<dyn std::erro
3636

3737
println!("✅ All compact content verified!");
3838

39+
// Release the lock before cleanup
40+
drop(chat);
41+
42+
// Cleanup only if this is the last test
43+
cleanup_if_last_test(&TEST_COUNT, TOTAL_TESTS)?;
44+
3945
Ok(())
4046
}
4147

42-
fn test_compact_help_command(chat: &mut QChatSession) -> Result<(), Box<dyn std::error::Error>> {
48+
#[test]
49+
#[cfg(feature = "compact")]
50+
fn test_compact_help_command() -> Result<(), Box<dyn std::error::Error>> {
4351
println!("🔍 Testing /compact --help command...");
4452

53+
let session = get_chat_session();
54+
let mut chat = session.lock().unwrap();
55+
4556
let response = chat.execute_command("/compact --help")?;
4657

4758
println!("📝 Compact help response: {} bytes", response.len());
@@ -94,5 +105,11 @@ fn test_compact_help_command(chat: &mut QChatSession) -> Result<(), Box<dyn std:
94105

95106
println!("✅ All compact help content verified!");
96107

108+
// Release the lock before cleanup
109+
drop(chat);
110+
111+
// Cleanup only if this is the last test
112+
cleanup_if_last_test(&TEST_COUNT, TOTAL_TESTS)?;
113+
97114
Ok(())
98115
}

e2etests/tests/test_editor_help_command.rs

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
1-
use q_cli_e2e_tests::q_chat_helper::QChatSession;
1+
use q_cli_e2e_tests::{get_chat_session, cleanup_if_last_test};
2+
use std::sync::atomic::{AtomicUsize, Ordering};
3+
4+
static TEST_COUNT: AtomicUsize = AtomicUsize::new(0);
5+
6+
// List of covered tests
7+
const TEST_NAMES: &[&str] = &[
8+
"test_editor_help_command",
9+
"test_help_editor_command",
10+
];
11+
const TOTAL_TESTS: usize = TEST_NAMES.len();
212

313
#[test]
414
#[cfg(feature = "editor")]
5-
fn test_all_editor_commands() -> Result<(), Box<dyn std::error::Error>> {
6-
let mut chat = QChatSession::new()?;
7-
println!(":white_check_mark: Q Chat session started");
8-
9-
test_editor_help_command(&mut chat)?;
10-
test_help_editor_command(&mut chat)?;
11-
12-
chat.quit()?;
13-
println!(":white_check_mark: All tests completed successfully");
14-
Ok(())
15-
}
16-
fn test_editor_help_command(chat: &mut QChatSession) -> Result<(), Box<dyn std::error::Error>> {
15+
fn test_editor_help_command() -> Result<(), Box<dyn std::error::Error>> {
1716
println!("🔍 Testing /editor --help command...");
1817

19-
let mut chat = QChatSession::new()?;
20-
println!("✅ Q Chat session started");
18+
let session = get_chat_session();
19+
let mut chat = session.lock().unwrap();
2120

2221
let response = chat.execute_command("/editor --help")?;
2322

@@ -48,13 +47,24 @@ fn test_editor_help_command(chat: &mut QChatSession) -> Result<(), Box<dyn std::
4847
println!("✅ Found help flags: -h, --help with Print help description");
4948

5049
println!("✅ All editor help content verified!");
50+
51+
// Release the lock before cleanup
52+
drop(chat);
53+
54+
// Cleanup only if this is the last test
55+
cleanup_if_last_test(&TEST_COUNT, TOTAL_TESTS)?;
5156

5257
Ok(())
5358
}
5459

55-
fn test_help_editor_command(chat: &mut QChatSession) -> Result<(), Box<dyn std::error::Error>> {
60+
#[test]
61+
#[cfg(feature = "editor")]
62+
fn test_help_editor_command() -> Result<(), Box<dyn std::error::Error>> {
5663
println!("🔍 Testing /help editor command...");
5764

65+
let session = get_chat_session();
66+
let mut chat = session.lock().unwrap();
67+
5868
let response = chat.execute_command("/help editor")?;
5969

6070
println!("📝 Help editor response: {} bytes", response.len());
@@ -80,6 +90,12 @@ fn test_help_editor_command(chat: &mut QChatSession) -> Result<(), Box<dyn std::
8090
println!("✅ Found help flags: -h, --help with Print help description");
8191

8292
println!("✅ All editor help content verified!");
83-
93+
94+
// Release the lock before cleanup
95+
drop(chat);
96+
97+
// Cleanup only if this is the last test
98+
cleanup_if_last_test(&TEST_COUNT, TOTAL_TESTS)?;
99+
84100
Ok(())
85101
}

e2etests/tests/test_hooks_command.rs

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
use q_cli_e2e_tests::q_chat_helper::QChatSession;
1+
use q_cli_e2e_tests::{get_chat_session, cleanup_if_last_test};
2+
use std::sync::atomic::{AtomicUsize, Ordering};
3+
4+
static TEST_COUNT: AtomicUsize = AtomicUsize::new(0);
5+
6+
// List of covered tests
7+
const TEST_NAMES: &[&str] = &[
8+
"test_hooks_command",
9+
"test_hooks_help_command",
10+
];
11+
const TOTAL_TESTS: usize = TEST_NAMES.len();
212

313
#[test]
414
#[cfg(feature = "hooks")]
5-
fn test_all_hoooks_commands() -> Result<(), Box<dyn std::error::Error>> {
6-
let mut chat = QChatSession::new()?;
7-
println!(":white_check_mark: Q Chat session started");
8-
9-
test_hooks_command(&mut chat)?;
10-
test_hooks_help_command(&mut chat)?;
11-
12-
chat.quit()?;
13-
println!(":white_check_mark: All tests completed successfully");
14-
Ok(())
15-
}
16-
17-
fn test_hooks_command(chat: &mut QChatSession) -> Result<(), Box<dyn std::error::Error>> {
15+
fn test_hooks_command() -> Result<(), Box<dyn std::error::Error>> {
1816
println!("🔍 Testing /hooks command...");
1917

20-
18+
let session = get_chat_session();
19+
let mut chat = session.lock().unwrap();
20+
2121
let response = chat.execute_command("/hooks")?;
2222

2323
println!("📝 Hooks command response: {} bytes", response.len());
@@ -36,12 +36,23 @@ fn test_hooks_command(chat: &mut QChatSession) -> Result<(), Box<dyn std::error:
3636

3737
println!("✅ All hooks command functionality verified!");
3838

39+
// Release the lock before cleanup
40+
drop(chat);
41+
42+
// Cleanup only if this is the last test
43+
cleanup_if_last_test(&TEST_COUNT, TOTAL_TESTS)?;
44+
3945
Ok(())
4046
}
4147

42-
fn test_hooks_help_command(chat: &mut QChatSession) -> Result<(), Box<dyn std::error::Error>> {
48+
#[test]
49+
#[cfg(feature = "hooks")]
50+
fn test_hooks_help_command() -> Result<(), Box<dyn std::error::Error>> {
4351
println!("🔍 Testing /hooks --help command...");
4452

53+
let session = get_chat_session();
54+
let mut chat = session.lock().unwrap();
55+
4556
let response = chat.execute_command("/hooks --help")?;
4657

4758
println!("📝 Hooks help response: {} bytes", response.len());
@@ -80,6 +91,11 @@ fn test_hooks_help_command(chat: &mut QChatSession) -> Result<(), Box<dyn std::e
8091

8192
println!("✅ All hooks help content verified!");
8293

94+
// Release the lock before cleanup
95+
drop(chat);
8396

97+
// Cleanup only if this is the last test
98+
cleanup_if_last_test(&TEST_COUNT, TOTAL_TESTS)?;
99+
84100
Ok(())
85101
}

e2etests/tests/test_issue_command.rs

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
use q_cli_e2e_tests::q_chat_helper::QChatSession;
1+
use q_cli_e2e_tests::{get_chat_session, cleanup_if_last_test};
2+
use std::sync::atomic::{AtomicUsize, Ordering};
3+
4+
static TEST_COUNT: AtomicUsize = AtomicUsize::new(0);
5+
6+
// List of covered tests
7+
const TEST_NAMES: &[&str] = &[
8+
"test_issue_command",
9+
"test_issue_force_command",
10+
"test_issue_help_command",
11+
];
12+
const TOTAL_TESTS: usize = TEST_NAMES.len();
213

314
#[test]
415
#[cfg(feature = "issue_reporting")]
5-
fn test_all_issue_commands() -> Result<(), Box<dyn std::error::Error>> {
6-
let mut chat = QChatSession::new()?;
7-
println!(":white_check_mark: Q Chat session started");
8-
9-
test_issue_command(&mut chat)?;
10-
test_issue_force_command(&mut chat)?;
11-
test_issue_help_command(&mut chat)?;
12-
13-
chat.quit()?;
14-
println!(":white_check_mark: All tests completed successfully");
15-
Ok(())
16-
}
17-
18-
fn test_issue_command(chat: &mut QChatSession) -> Result<(), Box<dyn std::error::Error>> {
16+
fn test_issue_command() -> Result<(), Box<dyn std::error::Error>> {
1917
println!("🔍 Testing /issue command with bug report...");
2018

21-
19+
let session = get_chat_session();
20+
let mut chat = session.lock().unwrap();
21+
2222
let response = chat.execute_command("/issue \"Bug: Q CLI crashes when using large files\"")?;
2323

2424
println!("📝 Issue command response: {} bytes", response.len());
@@ -31,12 +31,24 @@ fn test_issue_command(chat: &mut QChatSession) -> Result<(), Box<dyn std::error:
3131
println!("✅ Found browser opening confirmation");
3232

3333
println!("✅ All issue command functionality verified!");
34+
35+
// Release the lock before cleanup
36+
drop(chat);
37+
38+
// Cleanup only if this is the last test
39+
cleanup_if_last_test(&TEST_COUNT, TOTAL_TESTS)?;
40+
3441
Ok(())
3542
}
3643

37-
fn test_issue_force_command(chat: &mut QChatSession) -> Result<(), Box<dyn std::error::Error>> {
44+
#[test]
45+
#[cfg(feature = "issue_reporting")]
46+
fn test_issue_force_command() -> Result<(), Box<dyn std::error::Error>> {
3847
println!("🔍 Testing /issue --force command with critical bug...");
3948

49+
let session = get_chat_session();
50+
let mut chat = session.lock().unwrap();
51+
4052
let response = chat.execute_command("/issue --force \"Critical bug in file handling\"")?;
4153

4254
println!("📝 Issue force command response: {} bytes", response.len());
@@ -49,11 +61,23 @@ fn test_issue_force_command(chat: &mut QChatSession) -> Result<(), Box<dyn std::
4961
println!("✅ Found browser opening confirmation");
5062

5163
println!("✅ All issue --force command functionality verified!");
64+
65+
// Release the lock before cleanup
66+
drop(chat);
67+
68+
// Cleanup only if this is the last test
69+
cleanup_if_last_test(&TEST_COUNT, TOTAL_TESTS)?;
70+
5271
Ok(())
5372
}
5473

55-
fn test_issue_help_command(chat: &mut QChatSession) -> Result<(), Box<dyn std::error::Error>> {
74+
#[test]
75+
#[cfg(feature = "issue_reporting")]
76+
fn test_issue_help_command() -> Result<(), Box<dyn std::error::Error>> {
5677
println!("🔍 Testing /issue --help command...");
78+
79+
let session = get_chat_session();
80+
let mut chat = session.lock().unwrap();
5781

5882
let response = chat.execute_command("/issue --help")?;
5983

@@ -83,6 +107,13 @@ fn test_issue_help_command(chat: &mut QChatSession) -> Result<(), Box<dyn std::e
83107
println!("✅ Found Options section with force and help flags");
84108

85109
println!("✅ All issue help content verified!");
110+
111+
// Release the lock before cleanup
112+
drop(chat);
113+
114+
// Cleanup only if this is the last test
115+
cleanup_if_last_test(&TEST_COUNT, TOTAL_TESTS)?;
116+
86117
Ok(())
87118
}
88119

0 commit comments

Comments
 (0)