// file: crates/ksp-store-postgres-lib/tests/dependency_boundary.rs // version: 8 #![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 schema = include_str!("../src/schema.rs"); let bootstrap_sql = include_str!("../migrations/v000_bootstrap/tables/001_ksp_store_schema_migrations.sql"); assert!(migration.contains("crate::V000_RESOURCES")); assert!(migration.contains("crate::V001_RESOURCES")); assert!(schema.contains("../migrations/v000_bootstrap/tables/001_ksp_store_schema_migrations.sql")); assert!(schema.contains("../migrations/v001_raw_transaction/tables/001_ksp_store_identity.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("mod schema;")); 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_fix_001_migration_engine_uses_split_schema_contract_and_binds_network_without_repository_scope() { let migration = include_str!("../src/migration.rs"); let schema = include_str!("../src/schema.rs"); let identity_table = include_str!("../migrations/v001_raw_transaction/tables/001_ksp_store_identity.sql"); let raw_table = include_str!("../migrations/v001_raw_transaction/tables/002_ksp_raw_transactions.sql"); let observation_table = include_str!("../migrations/v001_raw_transaction/tables/003_ksp_raw_transaction_observations.sql"); let archive_table = include_str!("../migrations/v001_raw_transaction/tables/004_ksp_raw_transaction_archive_payloads.sql"); let index = include_str!("../migrations/v001_raw_transaction/indexes/001_ix_ksp_raw_transactions_slot_signature.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("schema_autocreate")); assert!(migration.contains("schema_autoupdate")); 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)")); assert!(schema.contains("SchemaResourceState")); assert!(schema.contains("verify_v001_external_compatibility")); assert!(identity_table.contains("CREATE TABLE IF NOT EXISTS ksp_store_identity")); assert!(raw_table.contains("CREATE TABLE IF NOT EXISTS ksp_raw_transactions")); assert!(observation_table.contains("CREATE TABLE IF NOT EXISTS ksp_raw_transaction_observations")); assert!(archive_table.contains("CREATE TABLE IF NOT EXISTS ksp_raw_transaction_archive_payloads")); assert!(index.contains("CREATE INDEX IF NOT EXISTS ix_ksp_raw_transactions_slot_signature")); 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!(!schema.contains(forbidden), "repository/cross-scope implementation leaked into schema contract: {forbidden}"); } for removed in ["migrations/V000__bootstrap.sql", "migrations/V001__raw_transaction.sql"] { let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join(removed); assert!(!path.exists(), "obsolete monolithic migration must be deleted by pre.003-fix.001: {removed}"); } return; }