use std::collections::BTreeMap;
use relate_core::Value;
use crate::exec::catalog::principal_cell;
use crate::overlay::ExecGraph;
const RELATE_VERSION: &str = env!("CARGO_PKG_VERSION");
const NEO4J_KERNEL_VERSION: &str = "2026.10-relate";
pub(super) fn db_info_rows(graph: &ExecGraph<'_>) -> Vec<BTreeMap<String, Value>> {
let namespace = graph.namespace().as_str();
vec![BTreeMap::from([
("id".into(), Value::String(namespace.into())),
("name".into(), Value::String(namespace.into())),
("creationDate".into(), Value::Null),
])]
}
pub(super) fn dbms_info_rows() -> Vec<BTreeMap<String, Value>> {
vec![BTreeMap::from([
("id".into(), Value::String("relate".into())),
("name".into(), Value::String("system".into())),
(
"creationDate".into(),
Value::String("1970-01-01T00:00:00Z".into()),
),
])]
}
pub(super) fn dbms_show_current_user_rows(principal: Option<&str>) -> Vec<BTreeMap<String, Value>> {
vec![BTreeMap::from([
("username".into(), principal_cell(principal, "relate")),
(
"roles".into(),
Value::List(vec![Value::String("admin".into())].into()),
),
("flags".into(), Value::List(Vec::new().into())),
])]
}
pub(super) fn dbms_license_agreement_rows() -> Vec<BTreeMap<String, Value>> {
vec![BTreeMap::from([
("status".into(), Value::String("yes".into())),
("daysLeftOnTrial".into(), Value::Null),
("totalTrialDays".into(), Value::Null),
])]
}
pub(super) fn dbms_components_rows() -> Vec<BTreeMap<String, Value>> {
const COMPONENTS: &[(&str, &[&str])] = &[
("Neo4j Kernel", &[NEO4J_KERNEL_VERSION]),
("Cypher", &["5", "25"]),
("Relate", &[RELATE_VERSION]),
];
COMPONENTS
.iter()
.map(|(name, versions)| {
BTreeMap::from([
("name".into(), Value::String((*name).into())),
(
"versions".into(),
Value::List(
versions
.iter()
.map(|version| Value::String((*version).into()))
.collect::<Vec<_>>()
.into(),
),
),
("edition".into(), Value::String("community".into())),
])
})
.collect()
}
pub(super) fn dbms_config_rows() -> Vec<BTreeMap<String, Value>> {
const CONFIG: &[(&str, &str, &str)] = &[
(
"browser.allow_outgoing_connections",
"true",
"Whether the Browser may open outgoing connections to other servers.",
),
(
"browser.credential_timeout",
"0",
"Seconds before the Browser discards retained credentials (0 = never).",
),
(
"browser.post_connect_cmd",
"",
"Command the Browser runs after connecting.",
),
(
"browser.remote_content_hostname_whitelist",
"*",
"Hostnames the Browser may load remote content from.",
),
(
"browser.retain_connection_credentials",
"false",
"Whether the Browser retains connection credentials.",
),
(
"browser.retain_editor_history",
"true",
"Whether the Browser retains editor history.",
),
(
"client.allow_telemetry",
"false",
"Whether client telemetry collection is allowed.",
),
(
"dbms.security.auth_enabled",
"true",
"Whether the server requires authentication.",
),
(
"server.metrics.prefix",
"relate",
"Prefix for reported metrics names.",
),
];
CONFIG
.iter()
.map(|(name, value, description)| {
BTreeMap::from([
("name".into(), Value::String((*name).into())),
("description".into(), Value::String((*description).into())),
("value".into(), Value::String((*value).into())),
("dynamic".into(), Value::Bool(false)),
("defaultValue".into(), Value::String((*value).into())),
("startupValue".into(), Value::String((*value).into())),
("explicitlySet".into(), Value::Bool(false)),
("validValues".into(), Value::String("".into())),
])
})
.collect()
}
pub(super) fn dbms_list_capabilities_rows(graph: &ExecGraph<'_>) -> Vec<BTreeMap<String, Value>> {
fn row(name: &str, description: &str, value: Value) -> BTreeMap<String, Value> {
BTreeMap::from([
("name".to_string(), Value::String(name.into())),
("description".to_string(), Value::String(description.into())),
("value".to_string(), value),
])
}
let mut rows = vec![
row(
"cypher.version",
"The Cypher dialect version this engine implements.",
Value::String(
relate_parser::error::SUPPORTED_CYPHER_VERSION
.to_string()
.into(),
),
),
row(
"fulltext.index",
"Whether fulltext indexes and their query procedures are available.",
Value::Bool(true),
),
row(
"vector.index",
"Whether vector indexes and their query procedures are available.",
Value::Bool(true),
),
row(
"pattern.engine",
"The pattern-matching engine in force for this database.",
Value::String(graph.base().pattern_engine().as_str().into()),
),
];
for capability in crate::procedure_gate::GATED_CAPABILITIES {
if graph.preview().enabled(capability.feature) {
rows.push(row(
capability.name,
capability.description,
Value::String(capability.value.into()),
));
}
}
rows
}
#[cfg(test)]
mod tests {
use super::super::test_helpers::{capability_names, rows, rows_with_principal, string};
use super::*;
use crate::graph::Graph;
use relate_core::PreviewFeatures;
#[test]
fn dbms_list_capabilities_reports_the_engines_own_facts() {
let rows = rows(&Graph::default(), "dbms.listCapabilities");
assert_eq!(
capability_names(&rows),
[
"cypher.version",
"fulltext.index",
"vector.index",
"pattern.engine"
]
);
assert_eq!(rows[0]["value"], Value::String("25".into()));
assert_eq!(rows[1]["value"], Value::Bool(true));
assert_eq!(rows[2]["value"], Value::Bool(true));
assert_eq!(rows[3]["value"], Value::String("auto".into()));
for row in &rows {
assert!(!row["description"]
.as_string()
.expect("every capability row carries a description")
.is_empty());
}
}
#[test]
fn the_ontology_capability_row_lists_only_under_the_opt_in() {
let mut enabled = Graph::default();
enabled.configure_preview(relate_core::PreviewSources {
env: PreviewFeatures::parse("ontology").unwrap(),
..relate_core::PreviewSources::default()
});
let rows = rows(&enabled, "dbms.listCapabilities");
assert_eq!(
capability_names(&rows),
[
"cypher.version",
"fulltext.index",
"vector.index",
"pattern.engine",
"ontology.supported.version",
]
);
assert_eq!(rows[4]["value"], Value::String("1.1.0".into()));
assert!(!rows[4]["description"]
.as_string()
.expect("the ontology row carries a description")
.is_empty());
}
#[test]
fn dbms_components_returns_kernel_cypher_relate_rows_with_edition() {
let graph = Graph::default();
let rows = rows(&graph, "dbms.components");
assert_eq!(rows.len(), 3);
assert_eq!(rows[0]["name"], string("Neo4j Kernel"));
assert_eq!(
rows[0]["versions"],
Value::List(vec![string(NEO4J_KERNEL_VERSION)].into())
);
assert_eq!(rows[0]["edition"], string("community"));
assert_eq!(rows[1]["name"], string("Cypher"));
assert_eq!(
rows[1]["versions"],
Value::List(vec![string("5"), string("25")].into())
);
assert_eq!(rows[1]["edition"], string("community"));
assert_eq!(rows[2]["name"], string("Relate"));
assert_eq!(
rows[2]["versions"],
Value::List(vec![string(RELATE_VERSION)].into())
);
assert_eq!(rows[2]["edition"], string("community"));
}
#[test]
fn db_info_reports_the_graphs_namespace() {
let graph = Graph::default();
let neo4j_rows = rows(&graph, "db.info");
assert_eq!(neo4j_rows.len(), 1);
assert_eq!(neo4j_rows[0]["id"], string("neo4j"));
assert_eq!(neo4j_rows[0]["name"], string("neo4j"));
let mut ontologies = Graph::default();
ontologies.set_namespace(relate_core::Namespace::SystemOntologies);
let ontologies_rows = rows(&ontologies, "db.info");
assert_eq!(ontologies_rows.len(), 1);
assert_eq!(ontologies_rows[0]["id"], string("system_ontologies"));
assert_eq!(ontologies_rows[0]["name"], string("system_ontologies"));
}
#[test]
fn dbms_info_returns_the_desktop_compat_row() {
let graph = Graph::default();
let rows = rows(&graph, "dbms.info");
assert_eq!(rows.len(), 1);
assert_eq!(rows[0]["id"], string("relate"));
assert_eq!(rows[0]["name"], string("system"));
assert_eq!(rows[0]["creationDate"], string("1970-01-01T00:00:00Z"));
}
#[test]
fn dbms_family_signatures_declare_their_outputs() {
const CONFIG: &[&str] = &[
"name",
"description",
"value",
"dynamic",
"defaultValue",
"startupValue",
"explicitlySet",
"validValues",
];
let expected: std::collections::BTreeMap<&str, Vec<&str>> = [
("dbms.clientConfig", CONFIG),
("dbms.components", &["name", "versions", "edition"]),
("dbms.info", &["id", "name", "creationDate"]),
(
"dbms.licenseAgreementDetails",
&["status", "daysLeftOnTrial", "totalTrialDays"],
),
("dbms.listCapabilities", &["name", "description", "value"]),
("dbms.listConfig", CONFIG),
("dbms.showCurrentUser", &["username", "roles", "flags"]),
]
.into_iter()
.map(|(name, columns)| (name, columns.to_vec()))
.collect();
let actual: std::collections::BTreeMap<&str, Vec<&str>> =
crate::procedure_registry::BUILTIN_PROCEDURE_SIGNATURES
.iter()
.filter(|signature| signature.executable && signature.name.starts_with("dbms."))
.map(|signature| (signature.name, signature.return_columns().collect()))
.collect();
assert_eq!(actual, expected);
}
#[test]
fn dbms_show_current_user_returns_the_placeholder_row_without_a_principal() {
let graph = Graph::default();
let rows = rows(&graph, "dbms.showCurrentUser");
assert_eq!(rows.len(), 1);
assert_eq!(rows[0]["username"], string("relate"));
assert_eq!(rows[0]["roles"], Value::List(vec![string("admin")].into()));
assert_eq!(rows[0]["flags"], Value::List(Vec::new().into()));
}
#[test]
fn dbms_show_current_user_reports_the_connection_principal() {
let graph = Graph::default();
let rows = rows_with_principal(&graph, "dbms.showCurrentUser", Some("alice"));
assert_eq!(rows.len(), 1);
assert_eq!(rows[0]["username"], string("alice"));
assert_eq!(rows[0]["roles"], Value::List(vec![string("admin")].into()));
assert_eq!(rows[0]["flags"], Value::List(Vec::new().into()));
}
#[test]
fn dbms_config_rows_match_the_adr0143_allowlist() {
let graph = Graph::default();
let client_rows = rows(&graph, "dbms.clientConfig");
let list_rows = rows(&graph, "dbms.listConfig");
assert_eq!(client_rows, list_rows);
assert_eq!(client_rows.len(), 9);
let expected: &[(&str, &str)] = &[
("browser.allow_outgoing_connections", "true"),
("browser.credential_timeout", "0"),
("browser.post_connect_cmd", ""),
("browser.remote_content_hostname_whitelist", "*"),
("browser.retain_connection_credentials", "false"),
("browser.retain_editor_history", "true"),
("client.allow_telemetry", "false"),
("dbms.security.auth_enabled", "true"),
("server.metrics.prefix", "relate"),
];
for (row, (name, value)) in client_rows.iter().zip(expected) {
assert_eq!(row["name"], string(name));
assert_eq!(row["value"], string(value));
assert_eq!(row["dynamic"], Value::Bool(false));
assert_eq!(row["defaultValue"], string(value));
assert_eq!(row["startupValue"], string(value));
assert_eq!(row["explicitlySet"], Value::Bool(false));
assert_eq!(row["validValues"], string(""));
assert!(matches!(&row["description"], Value::String(d) if !d.is_empty()));
}
}
#[test]
fn dbms_license_agreement_details_returns_the_honest_row() {
let graph = Graph::default();
let rows = rows(&graph, "dbms.licenseAgreementDetails");
assert_eq!(rows.len(), 1);
assert_eq!(rows[0]["status"], string("yes"));
assert_eq!(rows[0]["daysLeftOnTrial"], Value::Null);
assert_eq!(rows[0]["totalTrialDays"], Value::Null);
}
}