Skip to main content

relate_executor/
procedure_gate.rs

1//! The one built-in-procedure → preview-feature mapping (ADR-0378).
2//!
3//! The `db.ontology.*` procedure family is gated behind ADR-0371's
4//! `RELATE_PREVIEW` opt-in. Both consumers of that fact — the facade's
5//! plan gate (`relate::gate`) and the `SHOW PROCEDURES` catalog
6//! (`show_catalog`) — read this mapping, and the mapping itself derives the
7//! family from the canonical registry predicate
8//! ([`is_ontology_procedure`]), so the gate never re-spells the family.
9
10use relate_core::PreviewFeature;
11
12use crate::procedure_registry::is_ontology_procedure;
13
14/// The preview feature gating procedure `name` (ADR-0378):
15/// `Some(PreviewFeature::Ontology)` when `name` resolves to one of the
16/// built-in `db.ontology.*` registry signatures, `None` for every other
17/// name. The lookup is by name against the built-in registry only and never
18/// consults the host procedure registry, so a user-registered procedure is
19/// not gated — a host `db.ontology.custom`, for example, resolves to no
20/// built-in signature and stays ungated.
21pub fn procedure_preview_feature(name: &str) -> Option<PreviewFeature> {
22    is_ontology_procedure(name).then_some(PreviewFeature::Ontology)
23}
24
25#[cfg(test)]
26mod tests {
27    use super::*;
28    use crate::procedure_registry::BUILTIN_PROCEDURE_SIGNATURES;
29
30    #[test]
31    fn the_ontology_family_is_the_only_gated_procedure_family() {
32        // The gated names, spelled literally: this is the independent fact
33        // the test pins, not a re-run of the predicate the mapping is
34        // defined from, so a mapping change that moved a name in or out of
35        // the family fails here.
36        let family = [
37            ("db.ontology.set", Some(PreviewFeature::Ontology)),
38            ("db.ontology.get", Some(PreviewFeature::Ontology)),
39            ("db.ontology.drop", Some(PreviewFeature::Ontology)),
40            ("db.ontology.apply", Some(PreviewFeature::Ontology)),
41        ];
42        for (name, expected) in family {
43            assert_eq!(procedure_preview_feature(name), expected, "{name}");
44        }
45        // A non-ontology name is ungated, and so is a host-registered
46        // `db.ontology.*` name: the mapping reads the built-in registry
47        // only.
48        assert_eq!(procedure_preview_feature("db.labels"), None);
49        assert_eq!(procedure_preview_feature("db.ontology.custom"), None);
50        // No other registry row is gated either: the gated set is exactly
51        // the four literal names above, so a registry row added or dropped
52        // without the matching mapping change fails here.
53        let gated: Vec<&str> = BUILTIN_PROCEDURE_SIGNATURES
54            .iter()
55            .filter(|signature| procedure_preview_feature(signature.name).is_some())
56            .map(|signature| signature.name)
57            .collect();
58        assert_eq!(
59            gated,
60            [
61                "db.ontology.apply",
62                "db.ontology.drop",
63                "db.ontology.get",
64                "db.ontology.set"
65            ]
66        );
67    }
68}