use std::path::{Path, PathBuf};
use crate::adapters::dir_size;
use crate::constants;
#[derive(Debug, Clone)]
pub struct ToolFootprint {
pub name: &'static str,
pub path: PathBuf,
pub size_bytes: u64,
}
pub fn scan(repo_root: &Path) -> Vec<ToolFootprint> {
let candidates = [
("graphify", constants::GRAPHIFY_OUTPUT_DIR),
("understand-anything", constants::UNDERSTAND_ANYTHING_DIR),
];
candidates
.into_iter()
.filter_map(|(name, dir_name)| {
let path = repo_root.join(dir_name);
path.is_dir().then(|| ToolFootprint {
name,
size_bytes: dir_size(&path),
path,
})
})
.collect()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn finds_only_directories_that_exist() {
let dir = tempfile::tempdir().unwrap();
assert!(scan(dir.path()).is_empty());
std::fs::create_dir(dir.path().join(constants::GRAPHIFY_OUTPUT_DIR)).unwrap();
std::fs::write(
dir.path()
.join(constants::GRAPHIFY_OUTPUT_DIR)
.join("graph.json"),
b"{}",
)
.unwrap();
let found = scan(dir.path());
assert_eq!(found.len(), 1);
assert_eq!(found[0].name, "graphify");
assert_eq!(found[0].size_bytes, 2);
}
#[test]
fn finds_both_when_both_present() {
let dir = tempfile::tempdir().unwrap();
std::fs::create_dir(dir.path().join(constants::GRAPHIFY_OUTPUT_DIR)).unwrap();
std::fs::create_dir(dir.path().join(constants::UNDERSTAND_ANYTHING_DIR)).unwrap();
let found = scan(dir.path());
assert_eq!(found.len(), 2);
}
}