no-mistakes-postgres-engine 0.109.128

PostgreSQL embedded SQL extraction, schema catalog, and replay-safety analysis for no-mistakes
Documentation
use super::SchemaCatalog;
use std::path::PathBuf;

fn fixture_root() -> PathBuf {
    PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/postgres/catalog-logical-scope")
}

#[test]
fn logical_tables_keep_nested_parents_without_hiding_public_leaf_facts() {
    let json = std::fs::read_to_string(fixture_root().join("with-local-leaf/schema.json")).unwrap();
    let catalog = SchemaCatalog::from_json(&json).unwrap();
    assert!(catalog.tables().any(|table| table.name == "BadLeaf"));
    let logical = catalog
        .logical_tables()
        .map(|table| table.name.as_str())
        .collect::<Vec<_>>();
    assert!(!logical.contains(&"BadLeaf"));
    assert!(logical.contains(&"accounts"));
    assert!(logical.contains(&"parent_accounts"));
    assert!(logical.contains(&"nested_events_2026"));
}

#[test]
fn catalog_allow_entries_require_a_complete_object_identity() {
    let malformed = include_str!(concat!(
        env!("CARGO_MANIFEST_DIR"),
        "/../../fixtures/postgres/catalog-logical-scope/malformed-object-refs.json"
    ));
    let objects: Vec<String> = serde_json::from_str(malformed).unwrap();
    for object in objects {
        assert!(
            object.parse::<super::CatalogObjectRef>().is_err(),
            "accepted incomplete allow entry {object:?}"
        );
    }
}

#[test]
fn malformed_trigger_targets_and_functions_supply_no_catalog_identity() {
    let malformed = include_str!(concat!(
        env!("CARGO_MANIFEST_DIR"),
        "/../../fixtures/postgres/catalog-logical-scope/malformed-triggers.json"
    ));
    let definitions: Vec<String> = serde_json::from_str(malformed).unwrap();
    for definition in definitions {
        assert!(
            super::trigger::parse_trigger(&definition).is_err(),
            "accepted incomplete trigger definition {definition:?}"
        );
    }
}

#[test]
fn trigger_function_evidence_is_specific_to_the_table_and_trigger_name() {
    let catalog = SchemaCatalog::from_json(include_str!(concat!(
        env!("CARGO_MANIFEST_DIR"),
        "/../../fixtures/postgres/catalog-logical-scope/baseline/schema.json"
    )))
    .unwrap();
    let accounts = catalog.table("accounts").unwrap();
    let trigger = &accounts.triggers[0];
    let functions = super::trigger_functions::TriggerFunctions::new(&catalog);
    assert!(functions.resolve(accounts, trigger).is_some());

    let mut unrecorded_trigger = trigger.clone();
    unrecorded_trigger.name.push_str("_unrecorded");
    assert!(functions.resolve(accounts, &unrecorded_trigger).is_none());

    let mut unrecorded_table = accounts.clone();
    unrecorded_table.name.push_str("_unrecorded");
    assert!(functions.resolve(&unrecorded_table, trigger).is_none());
}