relate-executor 1.5.0

In-memory graph and Cypher physical executor
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
//! The catalog renderers' unit tests — split out of `show_catalog.rs`
//! so the production file stays well under the 1k-line boundary.

use super::*;

use crate::function_registry::FunctionCategory;
use crate::procedure_registry::is_ontology_procedure;
use crate::Graph;
use relate_core::{PreviewFeature, PreviewSources};

/// The one required-cell reader: a missing or non-STRING cell panics
/// naming the row and column.
fn text<'a>(row: &'a Row, column: &str) -> &'a str {
    row[column]
        .as_str()
        .unwrap_or_else(|| panic!("{} has no {column} cell", name_of(row)))
}

fn name_of(row: &Row) -> &str {
    row["name"]
        .as_str()
        .expect("every catalog row carries a string name")
}

/// A role column's list cell as strings.
fn roles<'a>(row: &'a Row, column: &str) -> Vec<&'a str> {
    let name = name_of(row);
    let cell = &row[column];
    cell.as_list()
        .unwrap_or_else(|| panic!("{name}.{column} is not a list: {cell:?}"))
        .iter()
        .map(|v| {
            v.as_str()
                .unwrap_or_else(|| panic!("{name}.{column} holds a non-STRING role"))
        })
        .collect()
}

fn is_ontology_row(row: &Row) -> bool {
    is_ontology_procedure(name_of(row))
}

/// A row's `signature` cell starts with its own `name` cell: the renderer
/// names a row from its registry name for both cells — including the
/// hand-written `special_signature` tails — so a disagreement means the
/// row carries two names.
fn assert_signature_names_row(row: &Row) {
    let name = name_of(row);
    let signature = text(row, "signature");
    assert!(
        signature.starts_with(&format!("{name}(")),
        "{name} renders `{signature}`"
    );
}

/// The boolean-cell reader, the twin of [`text`]: a missing or non-BOOL
/// cell panics naming the row and column.
fn flag(row: &Row, column: &str) -> bool {
    let name = name_of(row);
    row[column]
        .as_bool()
        .unwrap_or_else(|| panic!("{name} has no {column} cell"))
}

/// The catalog-metadata floor both renderers share (ADR-0497 §6/§8): a
/// listed row carries a non-empty description and a signature naming its
/// own row, never the `(...) :: ANY` placeholder — a placeholder or blank
/// cell is a catalogue gap, not a display detail.
fn assert_row_carries_catalog_metadata(row: &Row) {
    let name = name_of(row);
    let description = text(row, "description");
    assert!(!description.is_empty(), "{name} has an empty description");
    let signature = text(row, "signature");
    assert!(
        !signature.contains("(...) :: ANY"),
        "{name} keeps the placeholder signature `{signature}`"
    );
    assert_signature_names_row(row);
}

/// The catalog rows whose rendered name is spelled in mixed case, one
/// entry per rendered row (no dedup: a name that lost its spelling on an
/// arity sibling row must fail the count, not hide behind it), sorted:
/// the display-spelling surface of one preview set.
fn mixed_case_names(rows: &[Row]) -> Vec<&str> {
    let mut names: Vec<&str> = rows
        .iter()
        .map(name_of)
        .filter(|name| name.chars().any(|c| c.is_ascii_uppercase()))
        .collect();
    names.sort_unstable();
    names
}

#[test]
fn show_functions_hides_the_preview_gated_names_while_their_flags_are_disabled() {
    // ADR-0497 §4: the catalogue and the admission gate read the one
    // `function_preview_feature` table, so a disabled name is listed
    // nowhere.
    let disabled: Vec<String> = function_catalog_rows(Graph::default().preview())
        .iter()
        .map(|row| name_of(row).to_ascii_lowercase())
        .collect();
    // Derived from the one table, never hand-copied: `SHOW FUNCTIONS`
    // renders display spellings (`coll.hasAnyOf`), so the lowercased
    // row names are compared against the accessor's lowercase entries.
    let gated: Vec<&str> = relate_front::validate::gated_function_names().collect();
    for name in &gated {
        assert!(
            !disabled.contains(&name.to_string()),
            "{name} must not be listed without its opt-in"
        );
    }

    let mut enabled = Graph::default();
    enabled.configure_preview(PreviewSources {
        env: relate_front::validate::every_name_gate(),
        ..PreviewSources::default()
    });
    let listed: Vec<String> = function_catalog_rows(enabled.preview())
        .iter()
        .map(|row| name_of(row).to_ascii_lowercase())
        .collect();
    for name in &gated {
        assert!(
            listed.contains(&name.to_string()),
            "{name} must be listed with its opt-in"
        );
    }
    // Enabling the gates adds exactly the gated names and leaves every
    // other row identical and in order.
    assert_eq!(listed.len(), disabled.len() + gated.len());
    let other_rows: Vec<String> = listed
        .iter()
        .filter(|name| !gated.contains(&name.as_str()))
        .cloned()
        .collect();
    assert_eq!(other_rows, disabled);
}

#[test]
fn show_procedures_hides_the_ontology_family_while_the_preview_is_disabled() {
    // ADR-0378: a default executor graph carries the empty preview set,
    // so no ontology-family row is discoverable.
    let disabled = procedure_catalog_rows(Graph::default().preview());
    assert!(
        disabled.iter().all(|row| !is_ontology_row(row)),
        "a disabled store lists no db.ontology.* row"
    );

    let mut enabled = Graph::default();
    enabled.configure_preview(PreviewSources {
        env: PreviewFeatures::none().with_feature(PreviewFeature::Ontology),
        ..PreviewSources::default()
    });
    let listed = procedure_catalog_rows(enabled.preview());
    // Enabling the gate adds exactly the registry's ontology-family rows
    // that the catalog lists — the count applies the catalog's own
    // `listed` filter as well as the family predicate — and leaves every
    // other row identical and in order.
    let catalog_family: Vec<_> = BUILTIN_PROCEDURE_SIGNATURES
        .iter()
        .filter(|signature| signature.listed)
        .filter(|signature| is_ontology_procedure(signature.name))
        .collect();
    assert_eq!(listed.len(), disabled.len() + catalog_family.len());
    let other_rows: Vec<Row> = listed
        .iter()
        .filter(|row| !is_ontology_row(row))
        .cloned()
        .collect();
    assert_eq!(other_rows, disabled);

    // Each listed row carries the registry's own name, mode,
    // description and rendered signature: the gate changes availability
    // only.
    for signature in catalog_family {
        let row = listed
            .iter()
            .find(|row| name_of(row) == signature.name)
            .unwrap_or_else(|| panic!("{} must be listed while enabled", signature.name));
        assert_eq!(row["mode"], CypherValue::Str(signature.mode.to_string()));
        assert_eq!(
            row["description"],
            CypherValue::Str(signature.description.to_string())
        );
        assert_eq!(
            row["signature"],
            CypherValue::Str(render_procedure_signature(
                signature.name,
                signature.args,
                signature.returns,
            ))
        );
    }
}

/// ADR-0497 §6: every `SHOW PROCEDURES` row the catalog lists renders a
/// non-empty description and the CIP-113 signature of its own name —
/// the catalog is the whole inventory, so a row with a placeholder or a
/// blank signature is a catalogue gap rather than a display detail.
#[test]
fn every_listed_row_renders_a_description_and_a_cip113_signature() {
    let rows = procedure_catalog_rows(Graph::default().preview());
    assert!(!rows.is_empty());
    for row in &rows {
        assert_row_carries_catalog_metadata(row);
    }
}

/// ADR-0497 §8: every `SHOW FUNCTIONS` row of a default store carries the
/// brief columns — a non-empty description and a CIP-113 signature
/// rendered from typed parameters (never the old `(...) :: ANY`
/// placeholder). The category cell is the registry row's own
/// `FunctionCategory` (rendered verbatim by `function_row`), and the
/// row-per-advertised-name pairing is pinned by
/// `function_registry::the_metadata_tables_cover_exactly_the_advertised_registry`.
#[test]
fn every_function_catalog_row_carries_full_metadata() {
    let rows = function_catalog_rows(Graph::default().preview());
    assert!(!rows.is_empty());
    for row in &rows {
        assert_row_carries_catalog_metadata(row);
    }
}

/// The `aggregating` cell is the row's own `Aggregating` category, never a
/// second name-based lookup: every listed row's cell agrees with its
/// category and with the engine's aggregate vocabulary, so a registry row
/// cannot claim a classification the aggregation machinery does not fold
/// (or miss one it does). The aggregate rows are the aggregate catalogue,
/// gated aliases included.
#[test]
fn the_aggregating_cell_is_the_rows_own_aggregate_category() {
    let mut every_gate = Graph::default();
    every_gate.configure_preview(PreviewSources {
        env: relate_front::validate::every_name_gate(),
        ..PreviewSources::default()
    });
    let rows = function_catalog_rows(every_gate.preview());
    for row in &rows {
        let name = name_of(row);
        let category = text(row, "category");
        let aggregating = flag(row, "aggregating");
        assert_eq!(
            aggregating,
            category == FunctionCategory::Aggregating.as_str(),
            "{name}'s aggregating cell disagrees with its `{category}` category"
        );
        assert_eq!(
            aggregating,
            relate_front::agg::is_aggregate_name(name),
            "{name}'s aggregating cell disagrees with the aggregate vocabulary"
        );
    }
    let mut aggregates: Vec<&str> = rows
        .iter()
        .filter(|row| flag(row, "aggregating"))
        .map(name_of)
        .collect();
    aggregates.sort_unstable();
    assert_eq!(
        aggregates,
        [
            "avg",
            "collect",
            "collect_list",
            "count",
            "max",
            "min",
            "percentileCont",
            "percentileDisc",
            "percentile_cont",
            "percentile_disc",
            "stDev",
            "stDevP",
            "stddev_pop",
            "stddev_samp",
            "stdev_pop",
            "stdev_samp",
            "sum",
        ]
    );
}

/// The `show_expectations` corpus rows this metadata is filled from
/// (`features/correctness/ShowFunctions.feature`): the spot rows assert
/// name, category and description verbatim, and the `Numeric` filter
/// lists the rounding family once per `round` arity (lines 2660-2670).
#[test]
fn function_metadata_matches_the_recorded_corpus_rows() {
    let rows = function_catalog_rows(Graph::default().preview());
    let named =
        |name: &str| -> Vec<&Row> { rows.iter().filter(|row| name_of(row) == name).collect() };
    let one = |name: &str| -> &Row {
        let mut found = named(name);
        assert_eq!(found.len(), 1, "{name} must be listed once");
        found.pop().expect("checked len")
    };

    let abs = one("abs");
    assert_eq!(text(abs, "category"), "Numeric");
    assert_eq!(
        text(abs, "description"),
        "Returns the absolute value of an `INTEGER` or `FLOAT`."
    );

    let from_element_id = one("db.nameFromElementId");
    assert_eq!(text(from_element_id, "category"), "Database");
    assert_eq!(
        text(from_element_id, "description"),
        "Resolves the database name for the given element id"
    );

    let tail = one("tail");
    assert_eq!(text(tail, "category"), "List");
    assert_eq!(
        text(tail, "description"),
        "Returns all but the first element in a `LIST<ANY>`."
    );

    // Lines 82-83: the arity overloads render as two rows with their own
    // descriptions, transcribed verbatim from the corpus (the second
    // cell really does end in `....`).
    let flatten = named("coll.flatten");
    let mut descriptions: Vec<&str> = flatten.iter().map(|row| text(row, "description")).collect();
    descriptions.sort_unstable();
    assert_eq!(
        descriptions,
        [
            "Returns a list flattened to ....",
            "Returns a list flattened to the given nesting depth.",
        ]
    );

    // Lines 2660-2670: the `Numeric` category is exactly the rounding
    // family, with `round` repeated per arity row.
    let mut numeric: Vec<&str> = rows
        .iter()
        .filter(|row| text(row, "category") == "Numeric")
        .map(name_of)
        .collect();
    numeric.sort_unstable();
    assert_eq!(
        numeric,
        ["abs", "ceil", "ceiling", "floor", "isNaN", "rand", "round", "round", "round", "sign",]
    );
}

/// The display-spelling contract (ADR-0497 §11): the catalog's mixed-case
/// names are exactly the reference catalogue's. The reference is the
/// Cypher-25 corpus's generated `ShowFunctions*` tables, live-verified
/// against Neo4j 2026.10.1 (`SHOW FUNCTIONS YIELD name`): 42 default
/// rows, plus the three preview-gated `coll.has*` rows, which render
/// their CIP camelCase. Every other row renders its lowercase spelling,
/// so a name that loses or gains a spelling — or gains a typo'd one —
/// fails here instead of silently rendering lowercase. That every
/// rendered spelling is still callable in its own casing is the
/// case-insensitive matching fact pinned end-to-end by
/// `canonical_registries::catalog_display_spellings_are_callable_in_their_own_casing`.
#[test]
fn the_catalog_renders_the_reference_display_spellings() {
    /// The 42 default-surface names the reference catalogue spells in
    /// mixed case.
    const DEFAULT: &[&str] = &[
        "allReduce",
        "allShortestPaths",
        "coll.indexOf",
        "db.nameFromElementId",
        "duration.inDays",
        "duration.inMonths",
        "duration.inSeconds",
        "elementId",
        "endNode",
        "graph.byElementId",
        "graph.byName",
        "graph.propertiesByName",
        "isEmpty",
        "isNaN",
        "nullIf",
        "percentileCont",
        "percentileDisc",
        "point.withinBBox",
        "randomUUID",
        "shortestPath",
        "startNode",
        "stDev",
        "stDevP",
        "string.indexOf",
        "string.regexReplace",
        "toBoolean",
        "toBooleanList",
        "toBooleanOrNull",
        "toFloat",
        "toFloatList",
        "toFloatOrNull",
        "toInteger",
        "toIntegerList",
        "toIntegerOrNull",
        "toLower",
        "toString",
        "toStringList",
        "toStringOrNull",
        "toUpper",
        "uuid.leastSignificantBits",
        "uuid.mostSignificantBits",
        "valueType",
    ];
    /// The preview-gated names, rendered in their CIP camelCase: they
    /// join the default set exactly while their flags are on.
    const GATED: &[&str] = &["coll.hasAllOf", "coll.hasAnyOf", "coll.hasNoneOf"];

    let mut default_expected = DEFAULT.to_vec();
    default_expected.sort_unstable();
    let default_rows = function_catalog_rows(Graph::default().preview());
    assert_eq!(mixed_case_names(&default_rows), default_expected);

    let mut every_expected: Vec<&str> = DEFAULT.iter().chain(GATED).copied().collect();
    every_expected.sort_unstable();
    let mut every_gate = Graph::default();
    every_gate.configure_preview(PreviewSources {
        env: relate_front::validate::every_name_gate(),
        ..PreviewSources::default()
    });
    let gated_rows = function_catalog_rows(every_gate.preview());
    assert_eq!(mixed_case_names(&gated_rows), every_expected);

    // A row's `signature` cell starts with its own `name` cell: the only
    // hand-written signature text (`special_signature` tails, e.g.
    // `allReduce`) must agree with the row's own name spelling, or the row
    // would carry two names. Covers every rendered row, gated rows
    // included.
    for row in &gated_rows {
        assert_signature_names_row(row);
    }
}

/// Live Neo4j 2026.10.1 (`SHOW FUNCTIONS YIELD name`): the catalog is
/// case-sensitively name-sorted, not registration-ordered. The `Numeric`
/// filter therefore lists the rounding family in reference order, and
/// the mixed-case `percentileCont` sorts before `percentile_cont`
/// (`C` < `_`) — a case-insensitive sort would invert the pair.
#[test]
fn function_catalog_renders_the_reference_name_order() {
    let rows = function_catalog_rows(Graph::default().preview());
    let names: Vec<&str> = rows.iter().map(name_of).collect();
    let mut sorted = names.clone();
    sorted.sort_unstable();
    assert_eq!(names, sorted, "catalog rows are not in name order");

    let numeric: Vec<&str> = rows
        .iter()
        .filter(|row| text(row, "category") == "Numeric")
        .map(name_of)
        .collect();
    assert_eq!(
        numeric,
        ["abs", "ceil", "ceiling", "floor", "isNaN", "rand", "round", "round", "round", "sign",]
    );

    let position = |name: &str| names.iter().position(|n| *n == name).expect(name);
    assert!(position("percentileCont") < position("percentile_cont"));
}

/// The `rolesExecution`/`rolesBoostedExecution` cells copy live Neo4j
/// 2026.10.1: every built-in function is executable by PUBLIC plus the
/// five roles with nothing boosted, and a procedure is admin-only
/// exactly when its `admin` flag says so (boosted always `admin`). The
/// role cell is derived from the flag, so the two cannot disagree. The
/// registry's `admin` values are live-verified against 2026.10.1
/// (`SHOW PROCEDURES YIELD name, admin`), but the inventory deliberately
/// diverges: the server-only families are not listed, so the rows that
/// remain are the five the body comment pins.
#[test]
fn role_cells_match_live_neo4j() {
    let rows = function_catalog_rows(Graph::default().preview());
    for row in &rows {
        let name = name_of(row);
        assert_eq!(
            roles(row, "rolesExecution"),
            [
                "PUBLIC",
                "admin",
                "architect",
                "editor",
                "publisher",
                "reader"
            ],
            "{name}"
        );
        assert!(roles(row, "rolesBoostedExecution").is_empty(), "{name}");
    }

    let procedures = procedure_catalog_rows(Graph::default().preview());
    assert!(!procedures.is_empty());
    // The admin inventory is pinned independently of the roles derivation
    // below. It deliberately diverges from live 2026.10.1, whose
    // `SHOW PROCEDURES YIELD name, admin` lists 34 admin rows: 29 of those
    // belong to the server-only families Relate does not list (cluster,
    // routing, fleet management, CDC, sessions/connections/locks/pools/JMX/
    // security/scheduler, usage statistics, server config — see
    // ADR-0557). What remains is the five
    // admin rows an embedded engine can actually answer, `db.labels` still
    // among the non-admin ones.
    let admin_names: Vec<&str> = procedures
        .iter()
        .filter(|row| flag(row, "admin"))
        .map(name_of)
        .collect();
    assert_eq!(
        admin_names,
        [
            "db.clearQueryCaches",
            "db.listLocks",
            "db.prepareForReplanning",
            "db.stats.retrieve",
            "dbms.listConfig",
        ]
    );
    for row in &procedures {
        let name = name_of(row);
        let admin = flag(row, "admin");
        let expected: &[&str] = if admin {
            &["admin"]
        } else {
            &["PUBLIC", "admin"]
        };
        assert_eq!(roles(row, "rolesExecution"), expected, "{name}");
        assert_eq!(roles(row, "rolesBoostedExecution"), ["admin"], "{name}");
    }
}