1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
//! Basic CLI integration tests.
//!
//! Tests that load a `.sqry/graph/manifest.json` (the cli-basic
//! fixture or the workspace's own graph) are gated behind
//! `specialty-plugins`. Both manifests' `plugin_selection.active_plugin_ids`
//! reference plugin ids (`abap`, `apex`, `pulumi`, `puppet`,
//! `servicenow-*`, `terraform`, `plsql`) that were moved behind the
//! `specialty-plugins` Cargo feature in `refactor!: make non-core
//! surfaces opt-in` (commit ecd215385). A default-feature `sqry`
//! binary errors with `unknown plugin ids: ...` when reading those
//! manifests. The `--version`/`--help`/`--explain` tests don't load
//! the graph and stay unconditional.
//!
//! Run the full set with:
//! cargo test -p sqry-cli --features specialty-plugins --test cli_basic_test
mod common;
use common::sqry_bin;
use assert_cmd::Command;
use predicates::prelude::*;
#[cfg(feature = "specialty-plugins")]
use sqry_core::test_support::verbosity;
#[cfg(feature = "specialty-plugins")]
use std::path::PathBuf;
#[cfg(feature = "specialty-plugins")]
use std::sync::Once;
// Initialize verbose logging once for all tests in this file
#[cfg(feature = "specialty-plugins")]
static INIT: Once = Once::new();
#[cfg(feature = "specialty-plugins")]
fn init_logging() {
INIT.call_once(|| {
verbosity::init(env!("CARGO_PKG_NAME"));
});
}
/// Get the path to the test fixture directory
#[cfg(feature = "specialty-plugins")]
fn fixture_path() -> PathBuf {
let manifest_dir = env!("CARGO_MANIFEST_DIR");
// CARGO_MANIFEST_DIR is sqry-cli, parent is sqry repo root
PathBuf::from(manifest_dir)
.parent()
.unwrap()
.join("test-fixtures/cli-basic")
}
#[test]
fn test_version_flag() {
let path = sqry_bin();
let mut cmd = Command::new(path);
cmd.arg("--version")
.assert()
.success()
.stdout(predicate::str::contains("sqry"));
}
#[test]
fn test_help_flag() {
let path = sqry_bin();
let mut cmd = Command::new(path);
cmd.arg("--help")
.assert()
.success()
.stdout(predicate::str::contains("Usage:"));
}
#[test]
fn test_query_help() {
let path = sqry_bin();
let mut cmd = Command::new(path);
cmd.arg("query")
.arg("--help")
.assert()
.success()
.stdout(predicate::str::contains("query"));
}
#[cfg(feature = "specialty-plugins")]
#[test]
fn test_simple_query() {
init_logging();
log::info!("Testing simple CLI query execution (kind:function)");
let path = sqry_bin();
let fixture = fixture_path();
let mut cmd = Command::new(path);
cmd.arg("query")
.arg("kind:function")
.arg(&fixture)
.assert()
.success();
log::info!("✓ Simple query completed successfully");
}
#[test]
fn test_query_with_explain() {
let path = sqry_bin();
let mut cmd = Command::new(path);
cmd.arg("query")
.arg("kind:function")
.arg(".")
.arg("--explain")
.assert()
.success()
.stderr(predicate::str::contains("Query Plan:"));
}
#[cfg(feature = "specialty-plugins")]
#[test]
fn test_query_with_verbose() {
let path = sqry_bin();
let fixture = fixture_path();
let mut cmd = Command::new(path);
cmd.arg("query")
.arg("kind:function")
.arg(&fixture)
.arg("-v")
.assert()
.success()
// Note: Hybrid mode is now the default, cache stats not yet implemented
// Test just verifies that verbose flag works without errors
.stderr(predicate::str::contains("Query executed"));
}
#[cfg(feature = "specialty-plugins")]
#[test]
fn test_query_syntax_error_exit_code() {
init_logging();
log::info!("Testing query syntax error handling (exit code 2)");
// Test that syntax errors exit with error code 2 (user input errors)
// Parse errors exit with code 2 as defined by QueryError::exit_code()
// NOTE: Must use --semantic flag because hybrid mode falls back to text search
let path = sqry_bin();
let mut cmd = Command::new(path);
cmd.arg("--semantic") // Force semantic-only mode to get parse errors
.arg("query")
.arg("kind:") // Incomplete predicate - actual syntax error
.arg(".")
.assert()
.failure()
.code(2); // Parse errors return exit code 2 (user input errors)
log::info!("✓ Syntax error correctly returned exit code 2");
}
#[cfg(feature = "specialty-plugins")]
#[test]
fn test_query_invalid_predicate_exit_code() {
// Test that invalid predicates exit with error code
// Validation errors should exit with code 2 (user/validation errors)
// NOTE: Must use --semantic flag because hybrid mode falls back to text search
let path = sqry_bin();
let mut cmd = Command::new(path);
cmd.arg("--semantic") // Force semantic-only mode to get validation errors
.arg("query")
.arg("unknown_field:value")
.arg(".")
.assert()
.failure()
.code(2); // Validation errors return exit code 2
}
#[cfg(feature = "specialty-plugins")]
#[test]
fn test_query_empty_value_exit_code() {
// Test that empty values exit with error code 2 (user input errors)
// Empty values (parse errors) exit with code 2 as defined by QueryError::exit_code()
// NOTE: Must use --semantic flag because hybrid mode falls back to text search
let path = sqry_bin();
let mut cmd = Command::new(path);
cmd.arg("--semantic") // Force semantic-only mode to get parse errors
.arg("query")
.arg("kind:")
.arg(".")
.assert()
.failure()
.code(2); // Parse errors return exit code 2 (user input errors)
}
#[cfg(feature = "specialty-plugins")]
#[test]
fn test_successful_query_exit_code_zero() {
init_logging();
log::info!("Testing successful query returns exit code 0");
// Test that successful queries exit with code 0
let path = sqry_bin();
let fixture = fixture_path();
let mut cmd = Command::new(path);
cmd.arg("query")
.arg("kind:function")
.arg(&fixture)
.assert()
.success()
.code(0);
log::info!("✓ Successful query correctly returned exit code 0");
}