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
//! The `CALL` procedure contract's behavior tests (the executor's
//! `procedures` module family): the diverted scan contract's paren-less rejections, the YIELD
//! WHERE typed gate, and the row-provenance shapes of the registry path.
mod row_provenance_tests {
use std::collections::BTreeMap;
use crate::exec::test_support::{
exec_autocommit, exec_cypher, try_exec_cypher, try_exec_cypher_params,
};
use crate::graph::Graph;
use relate_core::Value;
/// The diverted scan calls read their arguments positionally, so the
/// one contract check every dispatch path reads (stellar round 2,
/// F-2-26/F-2-43) states the paren-less form's rejection by its
/// form: with a YIELD it is the passing-mode violation — never a
/// misleading arity count — and standalone it is the arity
/// rejection over the empty list the grammar passes.
#[test]
fn the_diverted_scan_contract_rejects_paren_less_calls_by_their_form() {
let graph = Graph::default();
let in_query = try_exec_cypher(&graph, "CALL db.index.vector.queryNodes YIELD node")
.err()
.expect("an in-query paren-less vector call is the passing-mode rejection");
assert!(
in_query.to_string().contains("InvalidArgumentPassingMode"),
"{in_query}"
);
let standalone = try_exec_cypher(&graph, "CALL db.index.vector.queryNodes")
.err()
.expect("a paren-less vector call passes no positional list");
let text = standalone.to_string();
assert!(
text.contains("InvalidNumberOfArguments")
&& text.contains("db.index.vector.queryNodes expected 3, got 0"),
"{text}"
);
}
/// A `CALL`'s `YIELD … WHERE` is a predicate position: a runtime
/// non-boolean (a parameter bound to an integer) is the typed
/// `requires a boolean` rejection every other optional-WHERE site
/// raises through the one `where_clause_holds` gate — never a silent
/// row drop (the composer once hand-spelled the truthy check).
#[test]
fn a_call_yield_where_with_a_non_boolean_parameter_is_the_typed_rejection() {
let graph = Graph::default();
exec_autocommit(&graph, "CREATE (:User), (:Admin)").expect("the fixture's CREATE succeeds");
let params: BTreeMap<String, Value> =
[("flag".to_string(), Value::Int(7))].into_iter().collect();
let error = try_exec_cypher_params(
&graph,
"CALL db.labels() YIELD label WHERE $flag RETURN label",
¶ms,
)
.err()
.expect("a non-boolean CALL YIELD WHERE predicate must be rejected");
let text = error.to_string();
assert!(
text.contains("InvalidArgumentType") && text.contains("requires a boolean"),
"{text}"
);
}
/// A no-argument built-in's rows are produced once for the call and
/// answered by every driving row — two driving rows times two labels,
/// never one production that only the first row sees.
#[test]
fn a_no_argument_builtin_answers_its_rows_for_every_driving_row() {
let graph = Graph::default();
exec_autocommit(&graph, "CREATE (:User), (:Admin)").expect("the fixture's CREATE succeeds");
let result = exec_cypher(
&graph,
"UNWIND [1, 2] AS i CALL db.labels() YIELD label \
RETURN i, label ORDER BY i, label",
);
let string = |value: &str| Value::String(value.into());
assert_eq!(
result.rows,
vec![
vec![Value::Int(1), string("Admin")],
vec![Value::Int(1), string("User")],
vec![Value::Int(2), string("Admin")],
vec![Value::Int(2), string("User")],
]
);
}
/// A built-in whose producer reads its arguments produces them under
/// every driving row's own binding: `db.stats.retrieve` is served the
/// section each row carries, never an empty argument map.
#[test]
fn an_argument_taking_builtin_produces_rows_from_each_rows_bindings() {
let graph = Graph::default();
let result = exec_cypher(
&graph,
"UNWIND [1, 2] AS i WITH i, 'GRAPH COUNTS' AS wanted \
CALL db.stats.retrieve(wanted) YIELD section RETURN i, section",
);
assert_eq!(
result.rows,
vec![
vec![Value::Int(1), Value::String("GRAPH COUNTS".into())],
vec![Value::Int(2), Value::String("GRAPH COUNTS".into())],
]
);
}
}
mod producer_table_pin {
use std::collections::BTreeMap;
use crate::exec::procedure_rows::builtin_procedure_rows;
use crate::graph::Graph;
use crate::overlay::ExecGraph;
use crate::procedure_registry::BUILTIN_PROCEDURE_SIGNATURES;
use relate_core::Value;
/// The producer table and the registry agree: every executable signature
/// that declares return columns either has a diverted call path or a
/// producer arm in its registry row — asserted as the table fact
/// itself, never by classifying the probe's error text. The producer
/// call stays as smoke: every declared parameter bound to a
/// representative value, so a producer that reads its arguments is
/// exercised rather than panicking on the CALL contract's missing
/// binding. (Lives here, beside the procedures module it reads, so the
/// lower-level `procedure_rows` never reaches up into its caller, even
/// in tests.)
#[test]
fn every_row_declaring_signature_has_a_producer_or_a_diverted_path() {
let graph = Graph::default();
let view = ExecGraph::read(&graph);
for signature in BUILTIN_PROCEDURE_SIGNATURES {
// The canonical void predicate, never a re-derivation from
// `returns` — `is_void` is documented as the one fact.
if !signature.executable || signature.is_void() {
continue;
}
if crate::exec::procedures::divert_call(&relate_names::SmallName::from_name(
signature.name,
))
.is_some()
{
continue;
}
assert!(
signature.rows.is_some(),
"{} declares return columns but the registry row carries no producer",
signature.name
);
let args: BTreeMap<String, Value> = signature
.args
.iter()
.map(|arg| (arg.name.to_string(), Value::String("GRAPH COUNTS".into())))
.collect();
let _ = builtin_procedure_rows(&view, signature, None, &args);
}
}
}