Files
khadhroony-solana-project/crates/ksp-store-postgres-lib/tests/dependency_boundary.rs
2026-08-30 08:41:26 +02:00

101 lines
4.4 KiB
Rust

// file: crates/ksp-store-postgres-lib/tests/dependency_boundary.rs
// version: 6
#![warn(missing_docs)]
#![deny(unreachable_pub)]
#![forbid(unsafe_code)]
//! Dependency and ownership canaries for the physical PostgreSQL Store backend.
#[test]
fn pre_005_backend_owns_exact_physical_runtime_dependencies_without_reverse_facade_edge() {
let manifest = include_str!("../Cargo.toml");
for required in
["deadpool-postgres", "ksp-logging-lib", "ksp-store-api", "rustls", "rustls-native-certs", "sha2", "tokio-postgres", "tokio-postgres-rustls"]
{
assert!(manifest.contains(required), "missing PostgreSQL backend dependency: {required}");
}
for forbidden in ["ksp-store-lib", "ksp-config-lib", "ksp-materializer", "ksp-program", "ksp-onchain-transport-lib", "ksp-offchain-transport-lib", "sqlx"] {
assert!(!manifest.contains(forbidden), "forbidden PostgreSQL backend dependency detected: {forbidden}");
}
let migration = include_str!("../src/migration.rs");
let bootstrap_sql = include_str!("../migrations/V000__bootstrap.sql");
assert!(migration.contains("include_str!(\"../migrations/V000__bootstrap.sql\")"));
assert!(bootstrap_sql.contains("ksp_store_schema_migrations"));
for forbidden in ["RawTransaction", "RawAccountState", "raw_transaction", "raw_account", "CORE", "DECODE", "SPECIALIZED"] {
assert!(!migration.contains(forbidden), "business migration implementation leaked into foundation: {forbidden}");
assert!(!bootstrap_sql.contains(forbidden), "business schema leaked into foundation SQL: {forbidden}");
}
return;
}
#[test]
fn pre_005_backend_keeps_environment_sql_migrations_and_physical_types_private() {
let crate_root = include_str!("../src/lib.rs");
assert!(crate_root.contains("mod error;"));
assert!(crate_root.contains("mod health;"));
assert!(crate_root.contains("mod migration;"));
assert!(crate_root.contains("mod runtime;"));
assert!(crate_root.contains("const _: &str = crate::TRACING_TARGET;"));
for forbidden in [
"pub mod ",
"ksp_store_lib",
"ksp_config_lib",
"tokio_postgres::Client",
"tokio_postgres::Row",
"tokio_postgres::Statement",
"deadpool_postgres::Pool;",
] {
assert!(!crate_root.contains(forbidden), "forbidden PostgreSQL crate-root surface detected: {forbidden}");
}
let runtime = include_str!("../src/runtime.rs");
for forbidden in [
"std::env",
"dotenv",
"KSP_",
"KSPB_",
"PGHOST",
"PGPORT",
"PGUSER",
"PGPASSWORD",
".pgpass",
"CREATE TABLE",
"INSERT INTO",
"UPDATE ",
"DELETE FROM",
"SELECT ",
] {
assert!(!runtime.contains(forbidden), "forbidden PostgreSQL backend ownership/scope content detected: {forbidden}");
}
return;
}
#[test]
fn pre_007_health_probe_remains_foundation_only_and_private_sql() {
let health = include_str!("../src/health.rs");
assert!(health.contains("SELECT 1::BIGINT"));
assert!(health.contains("ksp_store_schema_migrations"));
for forbidden in
["RawTransaction", "RawAccountState", "raw_transaction", "raw_account", "CORE", "DECODE", "SPECIALIZED", "std::env", "dotenv", "KSP_SECRET_"]
{
assert!(!health.contains(forbidden), "forbidden health ownership/scope content detected: {forbidden}");
}
return;
}
#[test]
fn pre_002_migration_engine_is_registry_driven_and_network_hook_ready_without_v001_schema() {
let migration = include_str!("../src/migration.rs");
assert!(migration.contains("const EMBEDDED_MIGRATIONS: &[EmbeddedMigration]"));
assert!(migration.contains("MigrationHook::None"));
assert!(migration.contains("run_migration_hook(transaction, network, migration.hook, MigrationHookContext::AppliedNow).await"));
assert!(migration.contains("network: &ksp_store_api::RawNetworkId"));
assert!(migration.contains("MigrationHookContext::Existing"));
assert!(migration.contains("run_applied_migration_hooks(&transaction, network, next_index).await"));
assert!(migration.contains("validate_history(history.as_slice(), EMBEDDED_MIGRATIONS)"));
assert!(migration.contains("apply_pending_migrations(&transaction, network, next_index).await"));
assert!(!migration.contains("V001__raw_transaction.sql"));
assert!(!migration.contains("ksp_store_identity"));
return;
}