Files
khadhroony-solana-project/crates/ksp-app-backfill-desk/tests/dependency_boundary.rs
2026-09-02 21:10:07 +02:00

79 lines
3.1 KiB
Rust

// file: crates/ksp-app-backfill-desk/tests/dependency_boundary.rs
// version: 1
//! Final dependency-boundary checks for the KSP Backfill desktop application.
#![forbid(unsafe_code)]
#![deny(unreachable_pub)]
#![warn(missing_docs)]
fn app_root() -> std::path::PathBuf {
return std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
}
fn read_text(path: &std::path::Path) -> String {
let source = std::fs::read_to_string(path);
assert!(source.is_ok(), "unable to read {}", path.display());
return match source {
std::result::Result::Ok(value) => value,
std::result::Result::Err(_) => String::new(),
};
}
#[test]
fn pre_013_manifest_ksp_dependency_surface_is_exact_and_backend_neutral() {
let manifest = read_text(app_root().join("Cargo.toml").as_path());
let dependency_section = manifest.split("[dependencies]").nth(1).and_then(|tail| return tail.split("[dev-dependencies]").next());
assert!(dependency_section.is_some(), "Backfill Desk manifest should expose a dependency section");
let dependency_section = match dependency_section {
std::option::Option::Some(value) => value,
std::option::Option::None => return,
};
let ksp_dependencies = dependency_section
.lines()
.filter_map(|line| {
let name = line.split('=').next().map(str::trim);
return match name {
std::option::Option::Some(value) if value.starts_with("ksp-") => std::option::Option::Some(value),
_ => std::option::Option::None,
};
})
.collect::<std::collections::BTreeSet<_>>();
assert_eq!(
ksp_dependencies,
std::collections::BTreeSet::from([
"ksp-config-lib",
"ksp-core-lib",
"ksp-job-api",
"ksp-job-backfill-lib",
"ksp-logging-lib",
"ksp-onchain-transport-lib",
"ksp-store-lib",
])
);
for forbidden in ["ksp-store-api", "ksp-store-postgres-lib", "tokio-postgres", "reqwest", "tonic", "yellowstone-grpc-proto", "mpl-token-metadata"] {
assert!(!dependency_section.contains(forbidden), "Backfill Desk manifest owns forbidden dependency {forbidden}");
}
}
#[test]
fn pre_013_production_sources_do_not_cross_into_physical_store_or_provider_clients() {
let source_root = app_root().join("src");
let entries = std::fs::read_dir(source_root.as_path());
assert!(entries.is_ok(), "Backfill Desk source directory should be readable");
let entries = match entries {
std::result::Result::Ok(value) => value,
std::result::Result::Err(_) => return,
};
for entry in entries.flatten() {
let path = entry.path();
if path.extension().and_then(std::ffi::OsStr::to_str) != std::option::Option::Some("rs") {
continue;
}
let source = read_text(path.as_path());
for forbidden in ["ksp_store_api", "ksp_store_postgres_lib", "tokio_postgres", "reqwest::", "tonic::", "yellowstone_grpc_proto"] {
assert!(!source.contains(forbidden), "{} crosses forbidden dependency boundary via {forbidden}", path.display());
}
}
}