use super::super::*;
#[test]
fn system_include_cache_entry_self_verifies_after_clear_skip() {
use crate::depgraph::SystemIncludeCache;
let tmp = tempfile::tempdir().unwrap();
let compiler = tmp.path().join("clang");
std::fs::write(&compiler, b"compiler binary").unwrap();
let include_dir = tmp.path().join("usr-include");
std::fs::create_dir_all(&include_dir).unwrap();
let mut cache = SystemIncludeCache::new();
cache.insert(
crate::core::NormalizedPath::new(&compiler),
vec![crate::core::NormalizedPath::new(&include_dir)],
);
assert_eq!(cache.len(), 1);
let hit = cache.get(&compiler);
assert!(
hit.is_some(),
"preserved entry must still stat-verify against an unchanged compiler"
);
assert_eq!(hit.unwrap().len(), 1);
filetime::set_file_mtime(
&compiler,
filetime::FileTime::from_unix_time(2_000_000_000, 0),
)
.unwrap();
std::fs::write(&compiler, b"different compiler bytes after upgrade").unwrap();
let post_change = cache.get(&compiler);
assert!(
post_change.is_none(),
"stat-verify must reject the entry once the compiler binary changes"
);
}
#[tokio::test]
#[ignore] async fn handle_clear_preserves_system_includes() {
crate::test_support::test_timeout(async {
let endpoint = crate::ipc::unique_test_endpoint();
let tmp = tempfile::tempdir().unwrap();
let cache_dir = crate::core::NormalizedPath::new(tmp.path());
let server = DaemonServer::bind_with_cache_dir(&endpoint, &cache_dir).unwrap();
let fake_compiler = tmp.path().join("fake-clang");
std::fs::write(&fake_compiler, b"fake compiler bytes").unwrap();
let synthetic_include_dir = tmp.path().join("include");
std::fs::create_dir_all(&synthetic_include_dir).unwrap();
server
.test_insert_system_includes(
crate::core::NormalizedPath::new(&fake_compiler),
vec![crate::core::NormalizedPath::new(&synthetic_include_dir)],
)
.await;
assert_eq!(
server.test_system_includes_len().await,
1,
"test setup: synthetic entry must be installed"
);
let response = super::super::handle_clear::handle_clear(server.test_state()).await;
assert!(
matches!(response, Response::Cleared { .. }),
"expected Cleared response, got: {response:?}"
);
assert_eq!(
server.test_system_includes_len().await,
1,
"issue #558: handle_clear must preserve system_includes entries — \
they self-verify via stat-verify and re-discovery is expensive"
);
})
.await;
}