use std::{fs, path::Path};
const TEMPORARY_EXCEPTIONS: &[&str] = &[];
#[test]
fn http_module_does_not_depend_on_ffi() {
let manifest_dir = env!("CARGO_MANIFEST_DIR");
let http_dir = Path::new(manifest_dir).join("src").join("http");
let mut violations: Vec<String> = Vec::new();
walk(&http_dir, &mut |path| {
if path.extension().is_some_and(|e| e == "rs") {
let rel = path
.strip_prefix(Path::new(manifest_dir).join("src"))
.unwrap_or(path)
.to_string_lossy()
.replace('\\', "/");
if TEMPORARY_EXCEPTIONS.contains(&rel.as_str()) {
return;
}
let src = fs::read_to_string(path).unwrap_or_default();
let stripped: String = src
.lines()
.map(|line| {
if let Some(idx) = line.find("//") {
&line[..idx]
} else {
line
}
})
.collect::<Vec<_>>()
.join("\n");
if stripped.contains("crate::ffi") || stripped.contains("super::ffi") {
violations.push(format!(
"{} imports from crate::ffi — http MUST NOT depend on ffi (epic #182)",
path.display()
));
}
}
});
assert!(
violations.is_empty(),
"architectural invariant violated:\n{}",
violations.join("\n")
);
}
fn walk(dir: &Path, f: &mut impl FnMut(&Path)) {
if let Ok(entries) = fs::read_dir(dir) {
for entry in entries.flatten() {
let path = entry.path();
if path.is_dir() {
walk(&path, f);
} else {
f(&path);
}
}
}
}
#[test]
fn crate_root_has_canonical_layout() {
const ALLOWED: &[&str] = &["lib.rs", "endpoint", "http", "ffi"];
let manifest_dir = env!("CARGO_MANIFEST_DIR");
let src_dir = Path::new(manifest_dir).join("src");
let mut unexpected: Vec<String> = Vec::new();
for entry in fs::read_dir(&src_dir).expect("src/ exists").flatten() {
let name = entry.file_name().to_string_lossy().into_owned();
if !ALLOWED.contains(&name.as_str()) {
unexpected.push(name);
}
}
assert!(
unexpected.is_empty(),
"unexpected entries directly under src/ — only {ALLOWED:?} are allowed (epic #182):\n {}",
unexpected.join("\n ")
);
}