112 lines
4.9 KiB
Rust
112 lines
4.9 KiB
Rust
// file: crates/ksp-store-postgres-lib/tests/dependency_boundary.rs
|
|
// version: 7
|
|
|
|
#![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!(migration.contains("include_str!(\"../migrations/V001__raw_transaction.sql\")"));
|
|
assert!(bootstrap_sql.contains("ksp_store_schema_migrations"));
|
|
for forbidden in ["RawTransaction", "RawAccountState", "raw_transaction", "raw_account", "CORE", "DECODE", "SPECIALIZED"] {
|
|
assert!(!bootstrap_sql.contains(forbidden), "business schema leaked into immutable V000 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_003_migration_engine_embeds_v001_and_binds_network_without_repository_scope() {
|
|
let migration = include_str!("../src/migration.rs");
|
|
let v001 = include_str!("../migrations/V001__raw_transaction.sql");
|
|
assert!(migration.contains("const EMBEDDED_MIGRATIONS: &[EmbeddedMigration]"));
|
|
assert!(migration.contains("MigrationHook::StoreIdentity"));
|
|
assert!(migration.contains("MigrationHookContext::AppliedNow"));
|
|
assert!(migration.contains("MigrationHookContext::Existing"));
|
|
assert!(migration.contains("INSERT INTO ksp_store_identity (singleton, network) VALUES (1, $1)"));
|
|
assert!(migration.contains("SELECT singleton, network FROM ksp_store_identity ORDER BY singleton LIMIT 2"));
|
|
assert!(migration.contains("ksp_store_api::RawNetworkId::new(stored_network)"));
|
|
for required in [
|
|
"CREATE TABLE ksp_store_identity",
|
|
"CREATE TABLE ksp_raw_transactions",
|
|
"CREATE TABLE ksp_raw_transaction_observations",
|
|
"CREATE TABLE ksp_raw_transaction_archive_payloads",
|
|
"CREATE INDEX ix_ksp_raw_transactions_slot_signature",
|
|
] {
|
|
assert!(v001.contains(required), "missing V001 physical object: {required}");
|
|
}
|
|
for forbidden in ["impl ksp_store_api::RawTransaction", "repository", "sqlx", "RawAccountState"] {
|
|
assert!(!migration.contains(forbidden), "repository/cross-scope implementation leaked into migration engine: {forbidden}");
|
|
assert!(!v001.contains(forbidden), "forbidden V001 scope content detected: {forbidden}");
|
|
}
|
|
return;
|
|
}
|