Skip to content

Commit da81eab

Browse files
Add changelog command and experiment feature tests
1 parent 8a1fb0e commit da81eab

File tree

4 files changed

+375
-2
lines changed

4 files changed

+375
-2
lines changed

e2etests/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ edition = "2021"
77

88
[dependencies]
99
expectrl = "0.7"
10+
regex = "1.0"
1011

1112
[features]
12-
core_session = ["help", "quit", "clear"] # Core Session Commands (/help, /quit, /clear)
13+
core_session = ["help", "quit", "clear", "changelog"] # Core Session Commands (/help, /quit, /clear, /changelog)
1314
help = [] # Help Command (/help)
1415
quit = [] # Quit Command (/quit)
1516
clear = [] # Clear Command (/clear)
17+
changelog = [] # Changelog Command (/changelog)
1618

1719
tools = [] # Tools Command (/tools)
1820
agent = [] # Agent Commands (/agent list, /agent create, etc.)

e2etests/tests/core_session/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
pub mod test_clear_command;
22
pub mod test_help_command;
3-
pub mod test_quit_command;
3+
pub mod test_quit_command;
4+
pub mod test_changelog_command;
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
#[allow(unused_imports)]
2+
use q_cli_e2e_tests::q_chat_helper;
3+
use std::sync::{Mutex, Once, atomic::{AtomicUsize, Ordering}};
4+
use regex::Regex;
5+
6+
#[allow(dead_code)]
7+
static INIT: Once = Once::new();
8+
#[allow(dead_code)]
9+
static mut CHAT_SESSION: Option<Mutex<q_chat_helper::QChatSession>> = None;
10+
11+
#[allow(dead_code)]
12+
pub fn get_chat_session() -> &'static Mutex<q_chat_helper::QChatSession> {
13+
unsafe {
14+
INIT.call_once(|| {
15+
let chat = q_chat_helper::QChatSession::new().expect("Failed to create chat session");
16+
println!("✅ Q Chat session started");
17+
CHAT_SESSION = Some(Mutex::new(chat));
18+
});
19+
(&raw const CHAT_SESSION).as_ref().unwrap().as_ref().unwrap()
20+
}
21+
}
22+
23+
#[allow(dead_code)]
24+
pub fn cleanup_if_last_test(test_count: &AtomicUsize, total_tests: usize) -> Result<usize, Box<dyn std::error::Error>> {
25+
let count = test_count.fetch_add(1, Ordering::SeqCst) + 1;
26+
if count == total_tests {
27+
unsafe {
28+
if let Some(session) = (&raw const CHAT_SESSION).as_ref().unwrap() {
29+
if let Ok(mut chat) = session.lock() {
30+
chat.quit()?;
31+
println!("✅ Test completed successfully");
32+
}
33+
}
34+
}
35+
}
36+
Ok(count)
37+
}
38+
39+
#[allow(dead_code)]
40+
static TEST_COUNT: AtomicUsize = AtomicUsize::new(0);
41+
42+
#[allow(dead_code)]
43+
const TEST_NAMES: &[&str] = &[
44+
"test_changelog_command",
45+
"test_changelog_help_command",
46+
];
47+
#[allow(dead_code)]
48+
const TOTAL_TESTS: usize = TEST_NAMES.len();
49+
50+
#[test]
51+
#[cfg(all(feature = "changelog", feature = "sanity"))]
52+
fn test_changelog_command() -> Result<(), Box<dyn std::error::Error>> {
53+
println!("\n🔍 Testing /changelog command... | Description: Tests the <code> /changelog</code> command to display version history and updates");
54+
55+
let session = get_chat_session();
56+
let mut chat = session.lock().unwrap();
57+
58+
println!("✅ Q Chat session started");
59+
60+
let response = chat.execute_command("/changelog")?;
61+
62+
println!("📝 Changelog response: {} bytes", response.len());
63+
println!("📝 FULL OUTPUT:");
64+
println!("{}", response);
65+
println!("📝 END OUTPUT");
66+
67+
// Verify changelog content
68+
assert!(response.contains("New") && response.contains("Amazon Q CLI"), "Missing changelog header");
69+
println!("✅ Found changelog header");
70+
71+
// Verify version format (e.g., 1.16.2)
72+
let version_regex = Regex::new(r"## \d+\.\d+\.\d+").unwrap();
73+
assert!(version_regex.is_match(&response), "Missing version format (x.x.x)");
74+
println!("✅ Found valid version format");
75+
76+
// Verify date format (e.g., 2025-09-19)
77+
let date_regex = Regex::new(r"\(\d{4}-\d{2}-\d{2}\)").unwrap();
78+
assert!(date_regex.is_match(&response), "Missing date format (YYYY-MM-DD)");
79+
println!("✅ Found valid date format");
80+
81+
// Verify /changelog command reference
82+
assert!(response.contains("/changelog"), "Missing /changelog command reference");
83+
println!("✅ Found /changelog command reference");
84+
85+
println!("✅ /changelog command test completed successfully");
86+
87+
// Release the lock before cleanup
88+
drop(chat);
89+
90+
// Cleanup only if this is the last test
91+
cleanup_if_last_test(&TEST_COUNT, TOTAL_TESTS)?;
92+
93+
Ok(())
94+
}
95+
96+
#[test]
97+
#[cfg(all(feature = "changelog", feature = "sanity"))]
98+
fn test_changelog_help_command() -> Result<(), Box<dyn std::error::Error>> {
99+
println!("\n🔍 Testing /changelog -h command... | Description: Tests the <code> /changelog -h</code> command to display help information");
100+
101+
let session = get_chat_session();
102+
let mut chat = session.lock().unwrap();
103+
104+
println!("✅ Q Chat session started");
105+
106+
let response = chat.execute_command("/changelog -h")?;
107+
108+
println!("📝 Help response: {} bytes", response.len());
109+
println!("📝 FULL OUTPUT:");
110+
println!("{}", response);
111+
println!("📝 END OUTPUT");
112+
113+
// Verify help content
114+
assert!(response.contains("Usage:") && response.contains("/changelog"), "Missing usage information");
115+
assert!(response.contains("Options:"), "Missing Options section");
116+
assert!(response.contains("-h") && response.contains("--help"), "Missing -h, --help flags");
117+
println!("✅ Found all expected help content");
118+
119+
println!("✅ /changelog -h command test completed successfully");
120+
121+
// Release the lock before cleanup
122+
drop(chat);
123+
124+
// Cleanup only if this is the last test
125+
cleanup_if_last_test(&TEST_COUNT, TOTAL_TESTS)?;
126+
127+
Ok(())
128+
}

0 commit comments

Comments
 (0)