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 mod windows_shell;
136
137#[cfg(test)]
138pub(crate) mod test_allocations;
139#[cfg(test)]
140pub(crate) mod test_env;
141
142#[cfg(test)]
143mod tests {
144 use super::*;
145 use config::Config;
146 use error::AftError;
147 use protocol::{RawRequest, Response};
148
149 #[test]
152 fn raw_request_deserializes_ping() {
153 let json = r#"{"id":"1","command":"ping"}"#;
154 let req: RawRequest = serde_json::from_str(json).unwrap();
155 assert_eq!(req.id, "1");
156 assert_eq!(req.command, "ping");
157 assert!(req.lsp_hints.is_none());
158 }
159
160 #[test]
161 fn raw_request_deserializes_echo_with_params() {
162 let json = r#"{"id":"2","command":"echo","message":"hello"}"#;
163 let req: RawRequest = serde_json::from_str(json).unwrap();
164 assert_eq!(req.id, "2");
165 assert_eq!(req.command, "echo");
166 assert_eq!(req.params["message"], "hello");
168 }
169
170 #[test]
171 fn raw_request_preserves_unknown_fields() {
172 let json = r#"{"id":"3","command":"ping","future_field":"abc","nested":{"x":1}}"#;
173 let req: RawRequest = serde_json::from_str(json).unwrap();
174 assert_eq!(req.params["future_field"], "abc");
175 assert_eq!(req.params["nested"]["x"], 1);
176 }
177
178 #[test]
179 fn raw_request_with_lsp_hints() {
180 let json = r#"{"id":"4","command":"ping","lsp_hints":{"completions":["foo","bar"]}}"#;
181 let req: RawRequest = serde_json::from_str(json).unwrap();
182 assert!(req.lsp_hints.is_some());
183 let hints = req.lsp_hints.unwrap();
184 assert_eq!(hints["completions"][0], "foo");
185 }
186
187 #[test]
188 fn response_success_round_trip() {
189 let resp = Response::success("42", serde_json::json!({"command": "pong"}));
190 let json_str = serde_json::to_string(&resp).unwrap();
191 let v: serde_json::Value = serde_json::from_str(&json_str).unwrap();
192 assert_eq!(v["id"], "42");
193 assert_eq!(v["success"], true);
194 assert_eq!(v["command"], "pong");
195 }
196
197 #[test]
198 fn response_error_round_trip() {
199 let resp = Response::error("99", "unknown_command", "unknown command: foo");
200 let json_str = serde_json::to_string(&resp).unwrap();
201 let v: serde_json::Value = serde_json::from_str(&json_str).unwrap();
202 assert_eq!(v["id"], "99");
203 assert_eq!(v["success"], false);
204 assert_eq!(v["code"], "unknown_command");
205 assert_eq!(v["message"], "unknown command: foo");
206 }
207
208 #[test]
211 fn error_display_symbol_not_found() {
212 let err = AftError::SymbolNotFound {
213 name: "foo".into(),
214 file: "bar.rs".into(),
215 };
216 assert_eq!(err.to_string(), "symbol 'foo' not found in bar.rs");
217 assert_eq!(err.code(), "symbol_not_found");
218 }
219
220 #[test]
221 fn error_display_ambiguous_symbol() {
222 let err = AftError::AmbiguousSymbol {
223 name: "Foo".into(),
224 candidates: vec!["a.rs:10".into(), "b.rs:20".into()],
225 };
226 let s = err.to_string();
227 assert!(s.contains("Foo"));
228 assert!(s.contains("a.rs:10, b.rs:20"));
229 }
230
231 #[test]
232 fn error_display_parse_error() {
233 let err = AftError::ParseError {
234 message: "unexpected token".into(),
235 };
236 assert_eq!(err.to_string(), "parse error: unexpected token");
237 }
238
239 #[test]
240 fn error_display_file_not_found() {
241 let err = AftError::FileNotFound {
242 path: "/tmp/missing.rs".into(),
243 };
244 assert_eq!(err.to_string(), "file not found: /tmp/missing.rs");
245 }
246
247 #[test]
248 fn error_display_invalid_request() {
249 let err = AftError::InvalidRequest {
250 message: "missing field".into(),
251 };
252 assert_eq!(err.to_string(), "invalid request: missing field");
253 }
254
255 #[test]
256 fn error_display_checkpoint_not_found() {
257 let err = AftError::CheckpointNotFound {
258 name: "pre-refactor".into(),
259 };
260 assert_eq!(err.to_string(), "checkpoint not found: pre-refactor");
261 assert_eq!(err.code(), "checkpoint_not_found");
262 }
263
264 #[test]
265 fn error_display_no_undo_history() {
266 let err = AftError::NoUndoHistory {
267 path: "src/main.rs".into(),
268 };
269 assert_eq!(err.to_string(), "no undo history for: src/main.rs");
270 assert_eq!(err.code(), "no_undo_history");
271 }
272
273 #[test]
274 fn error_display_ambiguous_match() {
275 let err = AftError::AmbiguousMatch {
276 pattern: "TODO".into(),
277 count: 5,
278 };
279 assert_eq!(
280 err.to_string(),
281 "pattern 'TODO' matches 5 occurrences, expected exactly 1"
282 );
283 assert_eq!(err.code(), "ambiguous_match");
284 }
285
286 #[test]
287 fn error_to_json_has_code_and_message() {
288 let err = AftError::FileNotFound { path: "/x".into() };
289 let j = err.to_error_json();
290 assert_eq!(j["code"], "file_not_found");
291 assert!(j["message"].as_str().unwrap().contains("/x"));
292 }
293
294 #[test]
297 fn config_default_values() {
298 let cfg = Config::default();
299 assert!(cfg.project_root.is_none());
300 assert_eq!(cfg.validation_depth, 1);
301 assert_eq!(cfg.checkpoint_ttl_hours, 24);
302 assert_eq!(cfg.max_symbol_depth, 10);
303 assert_eq!(cfg.formatter_timeout_secs, 10);
304 assert_eq!(cfg.type_checker_timeout_secs, 30);
305 }
306}