92 lines
4.2 KiB
Rust
92 lines
4.2 KiB
Rust
// file: crates/ksp-store-lib/tests/dependency_boundary.rs
|
|
// version: 11
|
|
|
|
#![warn(missing_docs)]
|
|
#![deny(unreachable_pub)]
|
|
#![forbid(unsafe_code)]
|
|
|
|
//! Cargo-feature and dependency-boundary canaries for the common Store runtime facade.
|
|
|
|
#[test]
|
|
fn pre_005_manifest_keeps_backend_physical_dependencies_out_of_facade() {
|
|
let manifest = include_str!("../Cargo.toml");
|
|
assert!(manifest.contains("default = [\"postgres\"]"));
|
|
assert!(manifest.contains("postgres = [\"dep:ksp-store-postgres-lib\"]"));
|
|
assert!(manifest.contains("ksp-logging-lib = { path = \"../ksp-logging-lib\" }"));
|
|
assert!(manifest.contains("ksp-store-api = { path = \"../ksp-store-api\" }"));
|
|
assert!(manifest.contains("ksp-store-postgres-lib = { path = \"../ksp-store-postgres-lib\", optional = true }"));
|
|
for forbidden in [
|
|
"ksp-config-lib",
|
|
"ksp-materializer",
|
|
"ksp-program",
|
|
"ksp-onchain-transport-lib",
|
|
"ksp-offchain-transport-lib",
|
|
"tokio-postgres",
|
|
"deadpool-postgres",
|
|
"rustls",
|
|
] {
|
|
assert!(!manifest.contains(forbidden), "forbidden Store facade dependency detected: {forbidden}");
|
|
}
|
|
return;
|
|
}
|
|
|
|
#[test]
|
|
fn pre_005_facade_exposes_no_physical_postgres_types_or_environment_bypass() {
|
|
let crate_root = include_str!("../src/lib.rs");
|
|
assert!(crate_root.contains("pub use self::settings::StoreSettings;"));
|
|
assert!(crate_root.contains("pub use self::health::StoreHealthSnapshot;"));
|
|
assert!(crate_root.contains("pub use self::health::StoreRuntimeSnapshot;"));
|
|
assert!(crate_root.contains("pub use self::store::Store;"));
|
|
assert!(crate_root.contains("pub use ksp_store_api::RawTransaction;"));
|
|
assert!(crate_root.contains("const _: &str = crate::TRACING_TARGET;"));
|
|
for forbidden in [
|
|
"pub mod ",
|
|
"pub use ksp_store_postgres_lib",
|
|
"tokio_postgres",
|
|
"deadpool_postgres",
|
|
"rustls::",
|
|
"deadpool::managed::Pool",
|
|
"tokio_postgres::Client",
|
|
"tokio_postgres::Row",
|
|
"tokio_postgres::Statement",
|
|
] {
|
|
assert!(!crate_root.contains(forbidden), "forbidden physical backend facade surface detected: {forbidden}");
|
|
}
|
|
let production = format!("{}\n{}\n{}", include_str!("../src/health.rs"), include_str!("../src/settings.rs"), include_str!("../src/store.rs"));
|
|
for forbidden in ["ksp_config_lib", "std::env", "dotenv", "PGHOST", "PGPORT", "PGUSER", "PGPASSWORD", ".pgpass", "tokio_postgres", "deadpool_postgres"] {
|
|
assert!(!production.contains(forbidden), "forbidden Store facade ownership bypass detected: {forbidden}");
|
|
}
|
|
return;
|
|
}
|
|
|
|
#[test]
|
|
fn v0_3_8_pre_009_facade_dispatches_fourteen_raw_capabilities_without_physical_leak() {
|
|
let store = include_str!("../src/store.rs");
|
|
for required in [
|
|
"impl ksp_store_api::RawAccountObservationInspectionRead for Store",
|
|
"impl ksp_store_api::RawAccountObservationRead for Store",
|
|
"impl ksp_store_api::RawAccountObservationWrite for Store",
|
|
"impl ksp_store_api::RawAccountStateInspectionRead for Store",
|
|
"impl ksp_store_api::RawAccountStateRead for Store",
|
|
"impl ksp_store_api::RawAccountStateWrite for Store",
|
|
"impl ksp_store_api::RawTransactionInspectionRead for Store",
|
|
"impl ksp_store_api::RawTransactionObservationInspectionRead for Store",
|
|
"impl ksp_store_api::RawTransactionObservationRead for Store",
|
|
"impl ksp_store_api::RawTransactionObservationWrite for Store",
|
|
"impl ksp_store_api::RawTransactionRead for Store",
|
|
"impl ksp_store_api::RawTransactionRetentionRead for Store",
|
|
"impl ksp_store_api::RawTransactionRetentionWrite for Store",
|
|
"impl ksp_store_api::RawTransactionWrite for Store",
|
|
"validate_operation_network",
|
|
"StoreRuntime::Postgres(backend)",
|
|
"map_postgres_error",
|
|
] {
|
|
assert!(store.contains(required), "missing pre.008 Store capability dispatch contract: {required}");
|
|
}
|
|
assert_eq!(store.matches("impl ksp_store_api::Raw").count(), 14);
|
|
for forbidden in ["tokio_postgres::", "deadpool_postgres::", "CREATE TABLE", "INSERT INTO", "UPDATE ksp_", "DELETE FROM"] {
|
|
assert!(!store.contains(forbidden), "pre.008 facade leaked physical backend material: {forbidden}");
|
|
}
|
|
return;
|
|
}
|