Skip to content

Commit 9ee973a

Browse files
committed
Add new test cases related to tools and fix the warning
1 parent ae4d39d commit 9ee973a

21 files changed

+169
-18
lines changed

e2etests/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ edition = "2021"
99
expectrl = "0.7"
1010

1111
[features]
12-
core_session = ["help", "tools", "quit", "clear"] # Core Session Commands (/help, /tools, /quit, /clear)
12+
core_session = ["help", "quit", "clear"] # Core Session Commands (/help, /quit, /clear)
1313
help = [] # Help Command (/help)
14-
tools = [] # Tools Command (/tools)
1514
quit = [] # Quit Command (/quit)
1615
clear = [] # Clear Command (/clear)
1716

17+
tools = [] # Tools Command (/tools)
1818
agent = [] # Agent Commands (/agent list, /agent create, etc.)
1919
context = [] # Context Commands (/context show, /context add, etc.)
2020
save_load = [] # Save/Load Commands (/save, /load, help)

e2etests/tests/agent/test_agent_commands.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#[allow(unused_imports)]
22
use q_cli_e2e_tests::q_chat_helper;
33
use std::sync::{Mutex, Once, atomic::{AtomicUsize, Ordering}};
4+
#[allow(dead_code)]
45
static INIT: Once = Once::new();
6+
#[allow(dead_code)]
57
static mut CHAT_SESSION: Option<Mutex<q_chat_helper::QChatSession>> = None;
68

9+
#[allow(dead_code)]
710
pub fn get_chat_session() -> &'static Mutex<q_chat_helper::QChatSession> {
811
unsafe {
912
INIT.call_once(|| {
@@ -15,6 +18,7 @@ pub fn get_chat_session() -> &'static Mutex<q_chat_helper::QChatSession> {
1518
}
1619
}
1720

21+
#[allow(dead_code)]
1822
pub fn cleanup_if_last_test(test_count: &AtomicUsize, total_tests: usize) -> Result<usize, Box<dyn std::error::Error>> {
1923
let count = test_count.fetch_add(1, Ordering::SeqCst) + 1;
2024
if count == total_tests {

e2etests/tests/ai_prompts/test_ai_prompt.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#[allow(unused_imports)]
22
use q_cli_e2e_tests::q_chat_helper;
33
use std::sync::{Mutex, Once, atomic::{AtomicUsize, Ordering}};
4+
#[allow(dead_code)]
45
static INIT: Once = Once::new();
6+
#[allow(dead_code)]
57
static mut CHAT_SESSION: Option<Mutex<q_chat_helper::QChatSession>> = None;
68

9+
#[allow(dead_code)]
710
pub fn get_chat_session() -> &'static Mutex<q_chat_helper::QChatSession> {
811
unsafe {
912
INIT.call_once(|| {
@@ -15,6 +18,7 @@ pub fn get_chat_session() -> &'static Mutex<q_chat_helper::QChatSession> {
1518
}
1619
}
1720

21+
#[allow(dead_code)]
1822
pub fn cleanup_if_last_test(test_count: &AtomicUsize, total_tests: usize) -> Result<usize, Box<dyn std::error::Error>> {
1923
let count = test_count.fetch_add(1, Ordering::SeqCst) + 1;
2024
if count == total_tests {
@@ -126,10 +130,10 @@ fn test_simple_greeting() -> Result<(), Box<dyn std::error::Error>> {
126130
println!("✅ AI recognized and responded to greeting appropriately");
127131
} else if response.len() > 20 {
128132
println!("✅ Got substantial response ({} bytes) to greeting", response.len());
129-
println!("ℹ️ Response doesn't contain typical greeting words but seems AI-generated");
133+
println!("⚠️ Response doesn't contain typical greeting words but seems AI-generated");
130134
} else {
131-
println!("ℹ️ Got minimal response - unclear if AI-generated or echo");
132-
println!("ℹ️ Response length: {} bytes", response.len());
135+
println!("⚠️ Got minimal response - unclear if AI-generated or echo");
136+
println!("⚠️ Response length: {} bytes", response.len());
133137
}
134138

135139
println!("✅ Test completed successfully");

e2etests/tests/ai_prompts/test_prompts_commands.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#[allow(unused_imports)]
22
use q_cli_e2e_tests::q_chat_helper;
33
use std::sync::{Mutex, Once, atomic::{AtomicUsize, Ordering}};
4+
#[allow(dead_code)]
45
static INIT: Once = Once::new();
6+
#[allow(dead_code)]
57
static mut CHAT_SESSION: Option<Mutex<q_chat_helper::QChatSession>> = None;
68

9+
#[allow(dead_code)]
710
pub fn get_chat_session() -> &'static Mutex<q_chat_helper::QChatSession> {
811
unsafe {
912
INIT.call_once(|| {
@@ -15,6 +18,7 @@ pub fn get_chat_session() -> &'static Mutex<q_chat_helper::QChatSession> {
1518
}
1619
}
1720

21+
#[allow(dead_code)]
1822
pub fn cleanup_if_last_test(test_count: &AtomicUsize, total_tests: usize) -> Result<usize, Box<dyn std::error::Error>> {
1923
let count = test_count.fetch_add(1, Ordering::SeqCst) + 1;
2024
if count == total_tests {

e2etests/tests/all_tests.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ mod integration;
77
mod mcp;
88
mod model;
99
mod save_load;
10-
mod session_mgmt;
10+
mod session_mgmt;
11+
mod tools;

e2etests/tests/context/test_context_command.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#[allow(unused_imports)]
22
use q_cli_e2e_tests::q_chat_helper;
33
use std::sync::{Mutex, Once, atomic::{AtomicUsize, Ordering}};
4+
#[allow(dead_code)]
45
static INIT: Once = Once::new();
6+
#[allow(dead_code)]
57
static mut CHAT_SESSION: Option<Mutex<q_chat_helper::QChatSession>> = None;
68

9+
#[allow(dead_code)]
710
pub fn get_chat_session() -> &'static Mutex<q_chat_helper::QChatSession> {
811
unsafe {
912
INIT.call_once(|| {
@@ -15,6 +18,7 @@ pub fn get_chat_session() -> &'static Mutex<q_chat_helper::QChatSession> {
1518
}
1619
}
1720

21+
#[allow(dead_code)]
1822
pub fn cleanup_if_last_test(test_count: &AtomicUsize, total_tests: usize) -> Result<usize, Box<dyn std::error::Error>> {
1923
let count = test_count.fetch_add(1, Ordering::SeqCst) + 1;
2024
if count == total_tests {

e2etests/tests/core_session/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
pub mod test_clear_command;
22
pub mod test_help_command;
3-
pub mod test_quit_command;
4-
pub mod test_tools_command;
3+
pub mod test_quit_command;

e2etests/tests/core_session/test_clear_command.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#[allow(unused_imports)]
22
use q_cli_e2e_tests::q_chat_helper;
33
use std::sync::{Mutex, Once, atomic::{AtomicUsize, Ordering}};
4+
#[allow(dead_code)]
45
static INIT: Once = Once::new();
6+
#[allow(dead_code)]
57
static mut CHAT_SESSION: Option<Mutex<q_chat_helper::QChatSession>> = None;
68

9+
#[allow(dead_code)]
710
pub fn get_chat_session() -> &'static Mutex<q_chat_helper::QChatSession> {
811
unsafe {
912
INIT.call_once(|| {
@@ -15,6 +18,7 @@ pub fn get_chat_session() -> &'static Mutex<q_chat_helper::QChatSession> {
1518
}
1619
}
1720

21+
#[allow(dead_code)]
1822
pub fn cleanup_if_last_test(test_count: &AtomicUsize, total_tests: usize) -> Result<usize, Box<dyn std::error::Error>> {
1923
let count = test_count.fetch_add(1, Ordering::SeqCst) + 1;
2024
if count == total_tests {
@@ -52,7 +56,7 @@ fn test_clear_command() -> Result<(), Box<dyn std::error::Error>> {
5256

5357
// Send initial message
5458
println!("\n🔍 Sending prompt: 'My name is TestUser'");
55-
let _initial_response = chat.send_prompt("My name is TestUser")?;
59+
let _initial_response = chat.execute_command("My name is TestUser")?;
5660
println!("📝 Initial response: {} bytes", _initial_response.len());
5761
println!("📝 INITIAL RESPONSE OUTPUT:");
5862
println!("{}", _initial_response);
@@ -66,7 +70,7 @@ fn test_clear_command() -> Result<(), Box<dyn std::error::Error>> {
6670

6771
// Check if AI remembers previous conversation
6872
println!("\n🔍 Sending prompt: 'What is my name?'");
69-
let test_response = chat.send_prompt("What is my name?")?;
73+
let test_response = chat.execute_command("What is my name?")?;
7074
println!("📝 Test response: {} bytes", test_response.len());
7175
println!("📝 TEST RESPONSE OUTPUT:");
7276
println!("{}", test_response);

e2etests/tests/core_session/test_help_command.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#[allow(unused_imports)]
22
use q_cli_e2e_tests::q_chat_helper;
33
use std::sync::{Mutex, Once, atomic::{AtomicUsize, Ordering}};
4+
#[allow(dead_code)]
45
static INIT: Once = Once::new();
6+
#[allow(dead_code)]
57
static mut CHAT_SESSION: Option<Mutex<q_chat_helper::QChatSession>> = None;
68

9+
#[allow(dead_code)]
710
pub fn get_chat_session() -> &'static Mutex<q_chat_helper::QChatSession> {
811
unsafe {
912
INIT.call_once(|| {
@@ -15,6 +18,7 @@ pub fn get_chat_session() -> &'static Mutex<q_chat_helper::QChatSession> {
1518
}
1619
}
1720

21+
#[allow(dead_code)]
1822
pub fn cleanup_if_last_test(test_count: &AtomicUsize, total_tests: usize) -> Result<usize, Box<dyn std::error::Error>> {
1923
let count = test_count.fetch_add(1, Ordering::SeqCst) + 1;
2024
if count == total_tests {
Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,48 @@
11
#[allow(unused_imports)]
2-
use q_cli_e2e_tests::q_chat_helper::QChatSession;
2+
use q_cli_e2e_tests::q_chat_helper;
3+
use std::sync::{Mutex, Once, atomic::{AtomicUsize}};
4+
#[allow(dead_code)]
5+
static INIT: Once = Once::new();
6+
#[allow(dead_code)]
7+
static mut CHAT_SESSION: Option<Mutex<q_chat_helper::QChatSession>> = None;
8+
9+
#[allow(dead_code)]
10+
pub fn get_chat_session() -> &'static Mutex<q_chat_helper::QChatSession> {
11+
unsafe {
12+
INIT.call_once(|| {
13+
let chat = q_chat_helper::QChatSession::new().expect("Failed to create chat session");
14+
println!("✅ Q Chat session started");
15+
CHAT_SESSION = Some(Mutex::new(chat));
16+
});
17+
(&raw const CHAT_SESSION).as_ref().unwrap().as_ref().unwrap()
18+
}
19+
}
20+
21+
#[allow(dead_code)]
22+
static TEST_COUNT: AtomicUsize = AtomicUsize::new(0);
23+
24+
// List of covered tests
25+
#[allow(dead_code)]
26+
const TEST_NAMES: &[&str] = &[
27+
"test_quit_command",
28+
];
29+
#[allow(dead_code)]
30+
const TOTAL_TESTS: usize = TEST_NAMES.len();
331

432
#[test]
533
#[cfg(all(feature = "quit", feature = "sanity"))]
634
fn test_quit_command() -> Result<(), Box<dyn std::error::Error>> {
735
println!("\n🔍 Testing /quit command... | Description: Tests the /quit command to properly terminate the Q Chat session and exit cleanly");
836

9-
let mut chat = QChatSession::new()?;
37+
let session = get_chat_session();
38+
let mut chat = session.lock().unwrap();
39+
1040
println!("✅ Q Chat session started");
1141

12-
chat.quit()?;
42+
chat.execute_command("/quit")?;
43+
1344
println!("✅ /quit command executed successfully");
1445
println!("✅ Test completed successfully");
15-
46+
1647
Ok(())
1748
}

0 commit comments

Comments
 (0)