1use std::path::{Path, PathBuf};
15
16use crate::adapters::dir_size;
17use crate::constants;
18
19#[derive(Debug, Clone)]
21pub struct ToolFootprint {
22 pub name: &'static str,
23 pub path: PathBuf,
24 pub size_bytes: u64,
25}
26
27pub fn scan(repo_root: &Path) -> Vec<ToolFootprint> {
30 let candidates = [
31 ("graphify", constants::GRAPHIFY_OUTPUT_DIR),
32 ("understand-anything", constants::UNDERSTAND_ANYTHING_DIR),
33 ];
34
35 candidates
36 .into_iter()
37 .filter_map(|(name, dir_name)| {
38 let path = repo_root.join(dir_name);
39 path.is_dir().then(|| ToolFootprint {
40 name,
41 size_bytes: dir_size(&path),
42 path,
43 })
44 })
45 .collect()
46}
47
48#[cfg(test)]
49mod tests {
50 use super::*;
51
52 #[test]
53 fn finds_only_directories_that_exist() {
54 let dir = tempfile::tempdir().unwrap();
55 assert!(scan(dir.path()).is_empty());
56
57 std::fs::create_dir(dir.path().join(constants::GRAPHIFY_OUTPUT_DIR)).unwrap();
58 std::fs::write(
59 dir.path()
60 .join(constants::GRAPHIFY_OUTPUT_DIR)
61 .join("graph.json"),
62 b"{}",
63 )
64 .unwrap();
65
66 let found = scan(dir.path());
67 assert_eq!(found.len(), 1);
68 assert_eq!(found[0].name, "graphify");
69 assert_eq!(found[0].size_bytes, 2);
70 }
71
72 #[test]
73 fn finds_both_when_both_present() {
74 let dir = tempfile::tempdir().unwrap();
75 std::fs::create_dir(dir.path().join(constants::GRAPHIFY_OUTPUT_DIR)).unwrap();
76 std::fs::create_dir(dir.path().join(constants::UNDERSTAND_ANYTHING_DIR)).unwrap();
77
78 let found = scan(dir.path());
79 assert_eq!(found.len(), 2);
80 }
81}