1#![allow(
2 clippy::collapsible_if,
3 clippy::collapsible_match,
4 clippy::double_ended_iterator_last,
5 clippy::int_plus_one,
6 clippy::large_enum_variant,
7 clippy::len_without_is_empty,
8 clippy::let_and_return,
9 clippy::manual_contains,
10 clippy::manual_pattern_char_comparison,
11 clippy::manual_repeat_n,
12 clippy::manual_strip,
13 clippy::manual_unwrap_or_default,
14 clippy::map_clone,
15 clippy::iter_kv_map,
16 clippy::needless_borrow,
17 clippy::needless_borrows_for_generic_args,
18 clippy::needless_range_loop,
19 clippy::new_without_default,
20 clippy::obfuscated_if_else,
21 clippy::ptr_arg,
22 clippy::question_mark,
23 clippy::same_item_push,
24 clippy::should_implement_trait,
25 clippy::single_match,
26 clippy::too_many_arguments,
27 clippy::type_complexity,
28 clippy::unnecessary_sort_by,
29 clippy::unnecessary_cast,
30 clippy::unnecessary_lazy_evaluations,
31 clippy::unnecessary_map_or
32)]
33
34pub mod agent_child_env;
50pub mod alert_records;
51pub mod alert_state;
52pub mod artifact_owner;
53pub mod ast_grep_hints;
54pub mod ast_grep_lang;
55pub mod backup;
56pub mod bash_background;
57pub mod bash_permissions;
58pub mod bash_rewrite;
59pub mod build_breaker;
60pub mod cache_freshness;
61pub mod callgraph;
62pub mod callgraph_store;
63pub mod calls;
64pub mod checkpoint;
65pub mod cold_build_limiter;
66pub mod commands;
67pub mod compress;
68pub mod config;
69pub mod config_resolve;
70pub mod context;
71pub mod db;
72pub mod edit;
73pub mod effective_path;
74pub mod error;
75pub mod executor;
76pub mod extract;
77pub mod fleet_status;
78pub mod format;
79pub mod fs_lock;
80pub mod fuzzy_match;
81pub mod gh_shim;
82pub mod github_read;
83pub mod grep_executor;
84pub mod harness;
85pub mod hashline;
86pub mod imports;
87pub mod indent;
88pub mod inspect;
89pub mod jsonc;
90pub mod language;
91pub mod legacy_partitions;
92pub mod local_embed;
93pub mod log_ctx;
94pub mod logging;
95pub mod lsp;
96pub mod lsp_hints;
97pub mod memory;
98pub mod migrate_storage;
99pub mod parser;
100pub mod patch;
101pub mod path_identity;
102pub mod pattern_compile;
103mod platform_tls;
104pub mod protocol;
105pub mod pty_render;
106pub mod query_shape;
107pub mod readonly_artifacts;
108pub mod response_finalize;
109pub mod root_cache;
110pub mod run_tool_call;
111pub mod runtime_drain;
112pub mod runtime_registry;
113pub mod sandbox_profile;
114pub mod sandbox_spawn;
115pub mod scoped_key;
116pub mod search_index;
117pub mod semantic_index;
118pub mod standing_roots;
119pub mod subc;
120pub mod subc_config;
121pub mod subc_format;
122pub mod subc_translate;
123pub mod symbol_cache_disk;
124pub mod symbol_diff;
125pub mod symbols;
126pub mod synapse_embed;
127pub mod tool_path;
128pub mod url_fetch;
129pub(crate) mod walk_boundary;
130pub mod watcher_filter;
131pub(crate) mod windows_command;
136pub mod windows_shell;
137
138#[cfg(test)]
139pub(crate) mod test_allocations;
140#[cfg(test)]
141pub(crate) mod test_env;
142
143#[cfg(test)]
144mod tests {
145 use super::*;
146 use config::Config;
147 use error::AftError;
148 use protocol::{RawRequest, Response};
149
150 #[test]
153 fn raw_request_deserializes_ping() {
154 let json = r#"{"id":"1","command":"ping"}"#;
155 let req: RawRequest = serde_json::from_str(json).unwrap();
156 assert_eq!(req.id, "1");
157 assert_eq!(req.command, "ping");
158 assert!(req.lsp_hints.is_none());
159 }
160
161 #[test]
162 fn raw_request_deserializes_echo_with_params() {
163 let json = r#"{"id":"2","command":"echo","message":"hello"}"#;
164 let req: RawRequest = serde_json::from_str(json).unwrap();
165 assert_eq!(req.id, "2");
166 assert_eq!(req.command, "echo");
167 assert_eq!(req.params["message"], "hello");
169 }
170
171 #[test]
172 fn raw_request_preserves_unknown_fields() {
173 let json = r#"{"id":"3","command":"ping","future_field":"abc","nested":{"x":1}}"#;
174 let req: RawRequest = serde_json::from_str(json).unwrap();
175 assert_eq!(req.params["future_field"], "abc");
176 assert_eq!(req.params["nested"]["x"], 1);
177 }
178
179 #[test]
180 fn raw_request_with_lsp_hints() {
181 let json = r#"{"id":"4","command":"ping","lsp_hints":{"completions":["foo","bar"]}}"#;
182 let req: RawRequest = serde_json::from_str(json).unwrap();
183 assert!(req.lsp_hints.is_some());
184 let hints = req.lsp_hints.unwrap();
185 assert_eq!(hints["completions"][0], "foo");
186 }
187
188 #[test]
189 fn response_success_round_trip() {
190 let resp = Response::success("42", serde_json::json!({"command": "pong"}));
191 let json_str = serde_json::to_string(&resp).unwrap();
192 let v: serde_json::Value = serde_json::from_str(&json_str).unwrap();
193 assert_eq!(v["id"], "42");
194 assert_eq!(v["success"], true);
195 assert_eq!(v["command"], "pong");
196 }
197
198 #[test]
199 fn response_error_round_trip() {
200 let resp = Response::error("99", "unknown_command", "unknown command: foo");
201 let json_str = serde_json::to_string(&resp).unwrap();
202 let v: serde_json::Value = serde_json::from_str(&json_str).unwrap();
203 assert_eq!(v["id"], "99");
204 assert_eq!(v["success"], false);
205 assert_eq!(v["code"], "unknown_command");
206 assert_eq!(v["message"], "unknown command: foo");
207 }
208
209 #[test]
212 fn error_display_symbol_not_found() {
213 let err = AftError::SymbolNotFound {
214 name: "foo".into(),
215 file: "bar.rs".into(),
216 };
217 assert_eq!(err.to_string(), "symbol 'foo' not found in bar.rs");
218 assert_eq!(err.code(), "symbol_not_found");
219 }
220
221 #[test]
222 fn error_display_ambiguous_symbol() {
223 let err = AftError::AmbiguousSymbol {
224 name: "Foo".into(),
225 candidates: vec!["a.rs:10".into(), "b.rs:20".into()],
226 };
227 let s = err.to_string();
228 assert!(s.contains("Foo"));
229 assert!(s.contains("a.rs:10, b.rs:20"));
230 }
231
232 #[test]
233 fn error_display_parse_error() {
234 let err = AftError::ParseError {
235 message: "unexpected token".into(),
236 };
237 assert_eq!(err.to_string(), "parse error: unexpected token");
238 }
239
240 #[test]
241 fn error_display_file_not_found() {
242 let err = AftError::FileNotFound {
243 path: "/tmp/missing.rs".into(),
244 };
245 assert_eq!(err.to_string(), "file not found: /tmp/missing.rs");
246 }
247
248 #[test]
249 fn error_display_invalid_request() {
250 let err = AftError::InvalidRequest {
251 message: "missing field".into(),
252 };
253 assert_eq!(err.to_string(), "invalid request: missing field");
254 }
255
256 #[test]
257 fn error_display_checkpoint_not_found() {
258 let err = AftError::CheckpointNotFound {
259 name: "pre-refactor".into(),
260 };
261 assert_eq!(err.to_string(), "checkpoint not found: pre-refactor");
262 assert_eq!(err.code(), "checkpoint_not_found");
263 }
264
265 #[test]
266 fn error_display_no_undo_history() {
267 let err = AftError::NoUndoHistory {
268 path: "src/main.rs".into(),
269 };
270 assert_eq!(err.to_string(), "no undo history for: src/main.rs");
271 assert_eq!(err.code(), "no_undo_history");
272 }
273
274 #[test]
275 fn error_display_ambiguous_match() {
276 let err = AftError::AmbiguousMatch {
277 pattern: "TODO".into(),
278 count: 5,
279 };
280 assert_eq!(
281 err.to_string(),
282 "pattern 'TODO' matches 5 occurrences, expected exactly 1"
283 );
284 assert_eq!(err.code(), "ambiguous_match");
285 }
286
287 #[test]
288 fn error_to_json_has_code_and_message() {
289 let err = AftError::FileNotFound { path: "/x".into() };
290 let j = err.to_error_json();
291 assert_eq!(j["code"], "file_not_found");
292 assert!(j["message"].as_str().unwrap().contains("/x"));
293 }
294
295 #[test]
298 fn config_default_values() {
299 let cfg = Config::default();
300 assert!(cfg.project_root.is_none());
301 assert_eq!(cfg.validation_depth, 1);
302 assert_eq!(cfg.checkpoint_ttl_hours, 24);
303 assert_eq!(cfg.max_symbol_depth, 10);
304 assert_eq!(cfg.formatter_timeout_secs, 10);
305 assert_eq!(cfg.type_checker_timeout_secs, 30);
306 }
307}