relate-executor 1.5.0

In-memory graph and Cypher physical executor
Documentation
//! The one gate-mapping module (ADR-0378, ADR-0741).
//!
//! The `db.ontology.*` procedure family is gated behind ADR-0371's
//! `RELATE_PREVIEW` opt-in. Both consumers of that fact — the facade's
//! plan gate (`relate::gate`) and the `SHOW PROCEDURES` catalog
//! (`show_catalog`) — read this mapping, and the mapping itself derives the
//! family from the canonical registry predicate
//! ([`is_ontology_procedure`]), so the gate never re-spells the family.
//!
//! The preview-gated capability rows of `dbms.listCapabilities`
//! (ADR-0741) live in the twin table [`GATED_CAPABILITIES`]: the row
//! producer renders it, so a gated row cannot exist outside it, and the
//! `relate` crate's consumer audit reads it back against the registry.

use relate_core::PreviewFeature;
use relate_ontology::MAX_SUPPORTED_SPEC_VERSION;

use crate::procedure_registry::is_ontology_procedure;

/// The preview feature gating procedure `name` (ADR-0378):
/// `Some(PreviewFeature::Ontology)` when `name` resolves to one of the
/// built-in `db.ontology.*` registry signatures, `None` for every other
/// name. The lookup is by name against the built-in registry only and never
/// consults the host procedure registry, so a user-registered procedure is
/// not gated — a host `db.ontology.custom`, for example, resolves to no
/// built-in signature and stays ungated.
pub fn procedure_preview_feature(name: &str) -> Option<PreviewFeature> {
    is_ontology_procedure(name).then_some(PreviewFeature::Ontology)
}

/// One preview-gated capability row of `dbms.listCapabilities`
/// (ADR-0741): the feature whose opt-in lists it, and the row's three
/// columns. A gated row is a content row, not a call gate — the
/// procedure stays callable with the opt-in off and its always-on rows
/// are unchanged; the gated row is simply absent.
pub struct GatedCapability {
    /// The preview feature whose opt-in lists the row.
    pub feature: PreviewFeature,
    /// The capability name — Neo4j's own entry name for the mirrored
    /// row, so ontology tooling reads the same fact from either engine.
    pub name: &'static str,
    /// The capability description.
    pub description: &'static str,
    /// The capability value, a STRING constant.
    pub value: &'static str,
}

/// The one table of preview-gated capability rows (ADR-0741): the row
/// producer renders exactly these rows, each only under its feature's
/// opt-in. Today one row — the supported ontology spec version, the
/// pin `db.ontology.set` validates against, so the listing cannot
/// drift from the gate.
pub const GATED_CAPABILITIES: &[GatedCapability] = &[GatedCapability {
    feature: PreviewFeature::Ontology,
    name: "ontology.supported.version",
    description: "The latest version of the Neo4j ontology graph spec supported by this DBMS.",
    value: MAX_SUPPORTED_SPEC_VERSION,
}];

#[cfg(test)]
mod tests {
    use super::*;
    use crate::procedure_registry::BUILTIN_PROCEDURE_SIGNATURES;

    #[test]
    fn the_ontology_family_is_the_only_gated_procedure_family() {
        // The gated names, spelled literally: this is the independent fact
        // the test pins, not a re-run of the predicate the mapping is
        // defined from, so a mapping change that moved a name in or out of
        // the family fails here.
        let family = [
            ("db.ontology.set", Some(PreviewFeature::Ontology)),
            ("db.ontology.get", Some(PreviewFeature::Ontology)),
            ("db.ontology.drop", Some(PreviewFeature::Ontology)),
            ("db.ontology.apply", Some(PreviewFeature::Ontology)),
        ];
        for (name, expected) in family {
            assert_eq!(procedure_preview_feature(name), expected, "{name}");
        }
        // A non-ontology name is ungated, and so is a host-registered
        // `db.ontology.*` name: the mapping reads the built-in registry
        // only.
        assert_eq!(procedure_preview_feature("db.labels"), None);
        assert_eq!(procedure_preview_feature("db.ontology.custom"), None);
        // No other registry row is gated either: the gated set is exactly
        // the four literal names above, so a registry row added or dropped
        // without the matching mapping change fails here.
        let gated: Vec<&str> = BUILTIN_PROCEDURE_SIGNATURES
            .iter()
            .filter(|signature| procedure_preview_feature(signature.name).is_some())
            .map(|signature| signature.name)
            .collect();
        assert_eq!(
            gated,
            [
                "db.ontology.apply",
                "db.ontology.drop",
                "db.ontology.get",
                "db.ontology.set"
            ]
        );
    }

    #[test]
    fn the_capability_table_is_the_one_mirrored_row() {
        // The gated capability rows, spelled literally: the table is the
        // row producer's one source, so the listing changes only through
        // it. This pins the one mirrored entry (ADR-0741) — Neo4j's own
        // name for the supported spec version, gated by the feature that
        // gates the rest of the ontology surface. The value's pin
        // ("1.1.0") is asserted where it is consumed, in the row
        // producer's and the facade's tests.
        assert_eq!(GATED_CAPABILITIES.len(), 1);
        let row = &GATED_CAPABILITIES[0];
        assert!(matches!(row.feature, PreviewFeature::Ontology));
        assert_eq!(row.name, "ontology.supported.version");
        assert!(!row.description.is_empty());
    }
}