use super::*; #[tokio::test] async fn partial_sequence_fails_closed() { let database_url = crank_test_support::postgres_schema_url("test_partial_sequence").await; let pool = sqlx::PgPool::connect(&database_url).await.unwrap(); MigrationAuthority::apply(&pool).await.unwrap(); sqlx::query("delete from __crank_migrations where version = 1") .execute(&pool) .await .unwrap(); assert_eq!( MigrationAuthority::preflight(&pool) .await .unwrap_err() .code(), "partial_sequence" ); } #[tokio::test] async fn missing_relation_with_current_ledger_fails_closed() { let database_url = crank_test_support::postgres_schema_url("test_missing_relation").await; let pool = sqlx::PgPool::connect(&database_url).await.unwrap(); MigrationAuthority::apply(&pool).await.unwrap(); sqlx::query("drop table usage_rollups") .execute(&pool) .await .unwrap(); let error = MigrationAuthority::preflight(&pool).await.unwrap_err(); assert_eq!(error.code(), "partial_sequence"); assert_eq!(error.stage(), "preflight.schema"); } #[tokio::test] async fn unregistered_legacy_extension_provenance_is_rejected() { let database_url = crank_test_support::postgres_schema_url("test_legacy_extension").await; let pool = sqlx::PgPool::connect(&database_url).await.unwrap(); MigrationAuthority::apply(&pool).await.unwrap(); sqlx::query("drop table __crank_migrations, __crank_migration_legacy_audit") .execute(&pool) .await .unwrap(); let checksum = "a".repeat(64); sqlx::query( "insert into __crank_ext_migrations (extension_name, version, checksum) values ('known-extension', 1, $1)", ) .bind(&checksum) .execute(&pool) .await .unwrap(); let error = MigrationAuthority::apply(&pool).await.unwrap_err(); assert_eq!(error.code(), "legacy_conflict"); } #[tokio::test] async fn any_owned_relation_without_core_ledger_is_partial() { let database_url = crank_test_support::postgres_schema_url("test_owned_partial").await; let pool = sqlx::PgPool::connect(&database_url).await.unwrap(); sqlx::query("create table users (id text primary key)") .execute(&pool) .await .unwrap(); let error = MigrationAuthority::preflight(&pool).await.unwrap_err(); assert_eq!(error.code(), "partial_sequence"); assert_eq!(error.stage(), "preflight.core_missing"); } #[tokio::test] async fn empty_core_ledger_is_reported_separately() { let database_url = crank_test_support::postgres_schema_url("test_empty_core_ledger").await; let pool = sqlx::PgPool::connect(&database_url).await.unwrap(); MigrationAuthority::apply(&pool).await.unwrap(); sqlx::query("delete from __crank_core_migrations") .execute(&pool) .await .unwrap(); let error = MigrationAuthority::preflight(&pool).await.unwrap_err(); assert_eq!(error.code(), "partial_sequence"); assert_eq!(error.stage(), "preflight.core_cardinality"); } #[tokio::test] async fn current_ledger_with_structural_drift_fails_closed() { let database_url = crank_test_support::postgres_schema_url("test_structural_drift").await; let pool = sqlx::PgPool::connect(&database_url).await.unwrap(); MigrationAuthority::apply(&pool).await.unwrap(); sqlx::query("alter table mcp_transport_sessions drop column supports_elicitation") .execute(&pool) .await .unwrap(); let error = MigrationAuthority::preflight(&pool).await.unwrap_err(); assert_eq!(error.code(), "partial_sequence"); assert_eq!(error.stage(), "preflight.schema"); } #[tokio::test] async fn tampered_legacy_audit_fails_closed() { let database_url = crank_test_support::postgres_schema_url("test_tampered_audit").await; let pool = sqlx::PgPool::connect(&database_url).await.unwrap(); MigrationAuthority::apply(&pool).await.unwrap(); sqlx::query( "update __crank_migration_legacy_audit set source_checksum = 'tampered' where source = 'core'", ) .execute(&pool) .await .unwrap(); let error = MigrationAuthority::preflight(&pool).await.unwrap_err(); assert_eq!(error.code(), "legacy_conflict"); }