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
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
//! ADR-0175 (LABS-178): the integer-argument sites — `range()`,
//! `substring()` / `left()` / `right()`, `SKIP` / `LIMIT`, list index and
//! slice, and arithmetic at the i64 limits — follow neo4j:2026.09. The
//! table below pins every other-sites row of ADR-0175's probe table (its
//! "Relate after" column, in table order) through the product parser,
//! planner, and executor:
//!
//! - `range()` / `substring()` / `left()` / `right()` / slice bounds coerce
//! runtime floats with Java `(long)`-cast semantics (truncate toward
//! zero, NaN → 0, ±Infinity and out-of-range saturate); `substring()` /
//! `left()` / `right()` then require [0, 2147483647], raising
//! NumberOutOfRange, while a FLOAT slice bound saturates into the int32
//! range (ADR-0631, superseding ADR-0175's int32-fit rejection — an
//! oversized bound reads as past-the-end). An INTEGER slice
//! bound is a long instead: it clamps across the whole i64 range (the
//! harness's ListSlicing pins Integer.MAX_VALUE+1 through Long.MAX/MIN).
//! A `range()` zero step raises NumberOutOfRange and a size overflow
//! raises `integer out of range`.
//! - `SKIP` / `LIMIT` and the list index reject every runtime float
//! (including 1.0, NaN, ±Infinity) with InvalidArgumentType.
//! - A non-INTEGER *literal* at the `range()` / `substring()` / `left()` /
//! `right()` sites (and a float literal at list index / slice) fails at
//! plan time with the same InvalidArgumentType kind (the `†` rows — the
//! planner raises them, so they surface as `type error:` before
//! execution; the planner unit tests in relate-planner pin the phase).
//! A non-numeric runtime value (`head(['x', '1'])`, a parameter) takes
//! that rejection from the executor's argument coercion, and only a
//! genuinely absent argument keeps the historical default.
//! - `(-9223372036854775808) / -1` raises `integer out of range` like the
//! other checked operators (ADR-0569, superseding ADR-0175's wrap);
//! `% -1` keeps its exact 0 result.
//!
//! The six `‡` deviation rows (`SKIP` / `LIMIT` of `0.0/0.0`, `1.0/0.0`
//! and `head([1.0/0.0, 'x'])`) fail at compile time in Neo4j (22NB1 /
//! 22003) and at runtime in Relate — same outcome, different phase
//! (ADR-0175's recorded deviation); the table pins Relate's runtime
//! error.
use relate_core::{Error, Value};
use super::test_support::try_exec_cypher;
use crate::graph::Graph;
use crate::test_support::ints;
/// The expected outcome of one probe row — ADR-0175's "Relate after"
/// cell.
enum Expect {
/// A single-row, single-column `v` result equal to this value.
V(Value),
/// A single-row float `v` result that is NaN (NaN != NaN, so it
/// cannot ride `V`).
Nan,
/// A statement's rows: one `x` integer per row, in order.
Xs(&'static [i64]),
/// The query fails; the error message starts with this prefix (the
/// after-cell's stderr prefix).
Err(&'static str),
}
fn s(text: &str) -> Value {
Value::String(text.into())
}
/// Run one probe row: `query` is the full statement for the SKIP/LIMIT
/// rows and `RETURN <expr> AS v` for the rest — exactly ADR-0175's probe
/// shape.
fn check(g: &Graph, query: &str, expect: &Expect) {
match (try_exec_cypher(g, query), expect) {
(Ok(result), Expect::V(want)) => {
assert_eq!(result.rows.len(), 1, "{query}: expected one row");
assert_eq!(result.rows[0].len(), 1, "{query}: expected one column");
assert_eq!(&result.rows[0][0], want, "{query}");
}
(Ok(result), Expect::Nan) => {
assert_eq!(result.rows.len(), 1, "{query}: expected one row");
assert!(
matches!(result.rows[0][0], Value::Float(f) if f.is_nan()),
"{query}: expected a NaN float, got {:?}",
result.rows[0][0]
);
}
(Ok(result), Expect::Xs(want)) => {
let got: Vec<&Value> = result.rows.iter().map(|r| &r[0]).collect();
let want: Vec<Value> = want.iter().map(|i| Value::Int(*i)).collect();
assert_eq!(got, want.iter().collect::<Vec<_>>(), "{query}");
}
(Err(error), Expect::Err(prefix)) => {
assert!(
error.to_string().starts_with(prefix),
"{query}: expected error starting with {prefix:?}, got {error:?}"
);
}
(Ok(result), Expect::Err(prefix)) => {
panic!(
"{query}: expected error {prefix:?}, got rows {:?}",
result.rows
)
}
(Err(error), _) => panic!("{query}: unexpected error {error}"),
}
}
#[test]
fn adr0175_other_sites_probe_rows() {
let g = Graph::default();
// (query, expected) in ADR-0175's probe-table order; `RETURN … AS v`
// wraps the expression rows exactly like the ADR's probe command.
let rows: Vec<(&'static str, Expect)> = vec![
// --- range() ---
// Float literal: plan-time rejection (ADR-0175's static-gate rule).
(
"RETURN range(1.5, 5) AS v",
Expect::Err("type error: InvalidArgumentType: range() start"),
),
// Runtime floats truncate toward zero.
(
"RETURN range(head([1.5, 'x']), 5) AS v",
Expect::V(ints(&[1, 2, 3, 4, 5])),
),
(
"RETURN range(head([-2.9, 'x']), 2) AS v",
Expect::V(ints(&[-2, -1, 0, 1, 2])),
),
(
"RETURN range(head([1.0, 'x']), 5) AS v",
Expect::V(ints(&[1, 2, 3, 4, 5])),
),
(
"RETURN range(1, head([5.9, 'x'])) AS v",
Expect::V(ints(&[1, 2, 3, 4, 5])),
),
(
"RETURN range(1, 10, head([2.5, 'x'])) AS v",
Expect::V(ints(&[1, 3, 5, 7, 9])),
),
(
"RETURN range(1, 5, head([1.0, 'x'])) AS v",
Expect::V(ints(&[1, 2, 3, 4, 5])),
),
// NaN converts to 0.
(
"RETURN range(head([0.0/0.0, 'x']), 5) AS v",
Expect::V(ints(&[0, 1, 2, 3, 4, 5])),
),
(
"RETURN range(1, head([0.0/0.0, 'x'])) AS v",
Expect::V(ints(&[])),
),
// A zero step — NaN included — is NumberOutOfRange.
(
"RETURN range(1, 5, head([0.0/0.0, 'x'])) AS v",
Expect::Err("semantic error: NumberOutOfRange: range() step cannot be 0"),
),
// ±Infinity saturate at the i64 limits.
(
"RETURN range(head([1.0/0.0, 'x']), 5) AS v",
Expect::V(ints(&[])),
),
(
"RETURN range(1, 5, head([1.0/0.0, 'x'])) AS v",
Expect::V(ints(&[1])),
),
// A size computation overflowing i64 is the arithmetic-overflow error.
(
"RETURN range(1, head([-1.0/0.0, 'x'])) AS v",
Expect::Err("type error: integer out of range"),
),
(
"RETURN range(5, 1, head([-1.0/0.0, 'x'])) AS v",
Expect::V(ints(&[5])),
),
(
"RETURN range(head([9.3e18, 'x']), head([9.3e18, 'x'])) AS v",
Expect::V(ints(&[i64::MAX])),
),
// --- substring() ---
// Float literal: plan-time rejection.
(
"RETURN substring('abcdef', 1.5) AS v",
Expect::Err("type error: InvalidArgumentType: substring() start must be an integer"),
),
(
"RETURN substring('abcdef', head([1.5, 'x'])) AS v",
Expect::V(s("bcdef")),
),
(
"RETURN substring('abcdef', head([1.0, 'x'])) AS v",
Expect::V(s("bcdef")),
),
(
"RETURN substring('abcdef', head([0.0/0.0, 'x'])) AS v",
Expect::V(s("abcdef")),
),
// Beyond [0, 2147483647] — ±Infinity, 2147483648.0, 9.3e18 — or
// below 0 raises NumberOutOfRange.
(
"RETURN substring('abcdef', head([1.0/0.0, 'x'])) AS v",
Expect::Err("semantic error: NumberOutOfRange: substring() start"),
),
(
"RETURN substring('abcdef', head([-1.0/0.0, 'x'])) AS v",
Expect::Err("semantic error: NumberOutOfRange: substring() start"),
),
(
"RETURN substring('abcdef', head([-1.5, 'x'])) AS v",
Expect::Err("semantic error: NumberOutOfRange: substring() start"),
),
(
"RETURN substring('abcdef', head([2147483648.0, 'x'])) AS v",
Expect::Err("semantic error: NumberOutOfRange: substring() start"),
),
(
"RETURN substring('abcdef', head([9.3e18, 'x'])) AS v",
Expect::Err("semantic error: NumberOutOfRange: substring() start"),
),
(
"RETURN substring('abcdef', 1, head([2.5, 'x'])) AS v",
Expect::V(s("bc")),
),
(
"RETURN substring('abcdef', head([0.0/0.0, 'x']), head([0.0/0.0, 'x'])) AS v",
Expect::V(s("")),
),
(
"RETURN substring('abcdef', 1, head([1.0/0.0, 'x'])) AS v",
Expect::Err("semantic error: NumberOutOfRange: substring() length"),
),
// --- left() / right() ---
(
"RETURN left('abcdef', head([2.9, 'x'])) AS v",
Expect::V(s("ab")),
),
(
"RETURN left('abcdef', head([0.0/0.0, 'x'])) AS v",
Expect::V(s("")),
),
(
"RETURN left('abcdef', head([1.0/0.0, 'x'])) AS v",
Expect::Err("semantic error: NumberOutOfRange: left() length"),
),
(
"RETURN left('abcdef', head([-1.0, 'x'])) AS v",
Expect::Err("semantic error: NumberOutOfRange: left() length"),
),
(
"RETURN right('abcdef', head([2.9, 'x'])) AS v",
Expect::V(s("ef")),
),
(
"RETURN right('abcdef', head([0.0/0.0, 'x'])) AS v",
Expect::V(s("")),
),
(
"RETURN right('abcdef', head([1.0/0.0, 'x'])) AS v",
Expect::Err("semantic error: NumberOutOfRange: right() length"),
),
// --- SKIP / LIMIT ---
("UNWIND [1,2,3] AS x RETURN x SKIP 1", Expect::Xs(&[2, 3])),
// Float literals keep their existing parse-time error.
(
"UNWIND [1,2,3] AS x RETURN x SKIP 1.0",
Expect::Err("syntax error: InvalidArgumentType: SKIP requires an integer value"),
),
(
"UNWIND [1,2,3] AS x RETURN x SKIP 1.5",
Expect::Err("syntax error: InvalidArgumentType: SKIP requires an integer value"),
),
// ‡ deviation rows: Neo4j rejects these constant float expressions
// at compile time (22NB1); Relate rejects them at runtime with
// the same InvalidArgumentType kind — same outcome, different phase.
(
"UNWIND [1,2,3] AS x RETURN x SKIP 0.0/0.0",
Expect::Err("type error: InvalidArgumentType: SKIP/LIMIT must be an integer"),
),
(
"UNWIND [1,2,3] AS x RETURN x SKIP 1.0/0.0",
Expect::Err("type error: InvalidArgumentType: SKIP/LIMIT must be an integer"),
),
(
"UNWIND [1,2,3] AS x RETURN x LIMIT 1.0",
Expect::Err("syntax error: InvalidArgumentType: LIMIT requires an integer value"),
),
(
"UNWIND [1,2,3] AS x RETURN x LIMIT 1.5",
Expect::Err("syntax error: InvalidArgumentType: LIMIT requires an integer value"),
),
(
"UNWIND [1,2,3] AS x RETURN x LIMIT 0.0/0.0",
Expect::Err("type error: InvalidArgumentType: SKIP/LIMIT must be an integer"),
),
(
"UNWIND [1,2,3] AS x RETURN x LIMIT 1.0/0.0",
Expect::Err("type error: InvalidArgumentType: SKIP/LIMIT must be an integer"),
),
// ANY-typed runtime floats are all rejected — 1.0 included.
(
"UNWIND [1,2,3] AS x RETURN x SKIP head([1.5, 'x'])",
Expect::Err("type error: InvalidArgumentType: SKIP/LIMIT must be an integer"),
),
(
"UNWIND [1,2,3] AS x RETURN x SKIP head([1.0, 'x'])",
Expect::Err("type error: InvalidArgumentType: SKIP/LIMIT must be an integer"),
),
(
"UNWIND [1,2,3] AS x RETURN x SKIP head([0.0/0.0, 'x'])",
Expect::Err("type error: InvalidArgumentType: SKIP/LIMIT must be an integer"),
),
// ‡ deviation row: Neo4j's constant folder refuses the Infinity
// literal at compile time (22003); Relate rejects at runtime.
(
"UNWIND [1,2,3] AS x RETURN x SKIP head([1.0/0.0, 'x'])",
Expect::Err("type error: InvalidArgumentType: SKIP/LIMIT must be an integer"),
),
(
"UNWIND [1,2,3] AS x RETURN x LIMIT head([1.5, 'x'])",
Expect::Err("type error: InvalidArgumentType: SKIP/LIMIT must be an integer"),
),
(
"UNWIND [1,2,3] AS x RETURN x LIMIT head([1.0, 'x'])",
Expect::Err("type error: InvalidArgumentType: SKIP/LIMIT must be an integer"),
),
(
"UNWIND [1,2,3] AS x RETURN x LIMIT head([0.0/0.0, 'x'])",
Expect::Err("type error: InvalidArgumentType: SKIP/LIMIT must be an integer"),
),
// ‡ deviation row (see above).
(
"UNWIND [1,2,3] AS x RETURN x LIMIT head([1.0/0.0, 'x'])",
Expect::Err("type error: InvalidArgumentType: SKIP/LIMIT must be an integer"),
),
// --- list index ---
// Float literal: plan-time rejection; every runtime float index —
// 1.0 and NaN included — is a type error (Neo4j 22N01).
(
"RETURN [1,2,3][1.0] AS v",
Expect::Err("type error: InvalidArgumentType: list index must be an integer"),
),
(
"RETURN [1,2,3][head([1.0, 'x'])] AS v",
Expect::Err("type error: InvalidArgumentType: list index must be an integer"),
),
(
"RETURN [1,2,3][head([1.5, 'x'])] AS v",
Expect::Err("type error: InvalidArgumentType: list index must be an integer"),
),
(
"RETURN [1,2,3][head([0.0/0.0, 'x'])] AS v",
Expect::Err("type error: InvalidArgumentType: list index must be an integer"),
),
// --- list slice ---
// Float literal: plan-time rejection.
(
"RETURN [1,2,3][1.0..2] AS v",
Expect::Err("type error: InvalidArgumentType: slice start must be an integer"),
),
// Bounds truncate toward zero, NaN → 0.
(
"RETURN [1,2,3][head([1.0, 'x'])..2] AS v",
Expect::V(ints(&[2])),
),
(
"RETURN [1,2,3][head([1.5, 'x'])..head([2.9, 'x'])] AS v",
Expect::V(ints(&[2])),
),
(
"RETURN [1,2,3][head([0.0/0.0, 'x'])..2] AS v",
Expect::V(ints(&[1, 2])),
),
(
"RETURN [1,2,3][1..head([0.0/0.0, 'x'])] AS v",
Expect::V(ints(&[])),
),
(
"RETURN [1,2,3][..head([1.5, 'x'])] AS v",
Expect::V(ints(&[1])),
),
(
"RETURN [1,2,3][head([1.5, 'x'])..] AS v",
Expect::V(ints(&[2, 3])),
),
// A FLOAT bound saturates into the int32 range (ADR-0631): an
// oversized bound reads as past-the-end, never a range fault.
(
"RETURN [1,2,3][head([1.0/0.0, 'x'])..2] AS v",
Expect::V(ints(&[])),
),
// Negative bounds keep the negative-index semantics.
(
"RETURN [1,2,3][head([-1.5, 'x'])..2] AS v",
Expect::V(ints(&[])),
),
(
"RETURN [1,2,3][head([2147483648.0, 'x'])..] AS v",
Expect::V(ints(&[])),
),
// An INTEGER bound is a long: it clamps across the whole i64 range
// (the harness pins 2147483648, Long.MAX and Long.MIN).
(
"RETURN [1,2,3][..2147483648] AS v",
Expect::V(ints(&[1, 2, 3])),
),
("RETURN [1,2,3][2147483648..] AS v", Expect::V(ints(&[]))),
(
"RETURN [1,2,3][..9223372036854775807] AS v",
Expect::V(ints(&[1, 2, 3])),
),
(
"RETURN [1,2,3][9223372036854775807..] AS v",
Expect::V(ints(&[])),
),
(
"RETURN [1,2,3][..(-9223372036854775807 - 1)] AS v",
Expect::V(ints(&[])),
),
(
"RETURN [1,2,3][(-9223372036854775807 - 1)..] AS v",
Expect::V(ints(&[1, 2, 3])),
),
// --- arithmetic at the i64 limits ---
(
"RETURN 9223372036854775807 + 1 AS v",
Expect::Err("type error: integer out of range"),
),
(
"RETURN (-9223372036854775807 - 1) - 1 AS v",
Expect::Err("type error: integer out of range"),
),
(
"RETURN 9223372036854775807 * 2 AS v",
Expect::Err("type error: integer out of range"),
),
(
"RETURN -(-9223372036854775807 - 1) AS v",
Expect::Err("type error: integer out of range"),
),
// MIN / -1 overflows (ADR-0569, checked like +, -, * and unary
// minus); MIN % -1 keeps its exact 0 result.
(
"RETURN (-9223372036854775807 - 1) / -1 AS v",
Expect::Err("type error: integer out of range"),
),
(
"RETURN (-9223372036854775807 - 1) % -1 AS v",
Expect::V(Value::Int(0)),
),
("RETURN 1 / 0 AS v", Expect::Err("type error: / by zero")),
("RETURN 1 % 0 AS v", Expect::Err("type error: % by zero")),
// Float division/modulo keep IEEE semantics.
(
"RETURN 1.0 / 0 AS v",
Expect::V(Value::Float(f64::INFINITY)),
),
(
"RETURN 1.0 / 0.0 AS v",
Expect::V(Value::Float(f64::INFINITY)),
),
("RETURN 1.0 % 0.0 AS v", Expect::Nan),
(
"RETURN 9223372036854775807 + 0.5 AS v",
Expect::V(Value::Float(9.223372036854776e18)),
),
];
// The table must cover every other-sites row of ADR-0175's probe table.
assert_eq!(rows.len(), 83, "one row per ADR-0175 other-sites probe row");
for (query, expect) in &rows {
check(&g, query, expect);
}
}
/// LABS-1306: a *present* start/length that is not a number is the call's
/// type rejection, never the absent-argument default. Live Neo4j
/// 2026.10.1 (probed 2026-11-10) reports a `SyntaxError` type mismatch for
/// the literal spellings and a `TypeError` for the runtime-typed ones;
/// Relate rejects the literal at plan time and the runtime value from the
/// argument coercion. A null still nulls the call first, and an absent
/// argument keeps the documented default.
#[test]
fn non_numeric_index_args_are_type_rejections() {
let g = Graph::default();
for (query, expect) in [
// Literals: plan-time rejection.
(
"RETURN substring('abcdef', 'x') AS v",
Expect::Err("type error: InvalidArgumentType: substring() start must be an integer"),
),
(
"RETURN substring('abcdef', 1, 'x') AS v",
Expect::Err("type error: InvalidArgumentType: substring() length must be an integer"),
),
(
"RETURN left('abcdef', 'x') AS v",
Expect::Err("type error: InvalidArgumentType: left() length must be an integer"),
),
(
"RETURN right('abcdef', 'x') AS v",
Expect::Err("type error: InvalidArgumentType: right() length must be an integer"),
),
(
"RETURN substring('abcdef', true) AS v",
Expect::Err("type error: InvalidArgumentType: substring() start must be an integer"),
),
// A temporal constructor call the front end folds to an eager
// value is a literal too, not an INTEGER one.
(
"RETURN substring('abcdef', date('2020-01-01')) AS v",
Expect::Err("type error: InvalidArgumentType: substring() start must be an integer"),
),
// Runtime-typed values: the coercion's rejection.
(
"RETURN substring('abcdef', head(['x', '1'])) AS v",
Expect::Err("type error: InvalidArgumentType: substring() start must be an integer"),
),
(
"RETURN substring('abcdef', 1, head(['x', '2'])) AS v",
Expect::Err("type error: InvalidArgumentType: substring() length must be an integer"),
),
(
"RETURN left('abcdef', head(['x', '1'])) AS v",
Expect::Err("type error: InvalidArgumentType: left() length must be an integer"),
),
(
"RETURN right('abcdef', head(['x', '1'])) AS v",
Expect::Err("type error: InvalidArgumentType: right() length must be an integer"),
),
// A null still nulls the call, and a missing argument keeps the
// historical default rather than erroring.
(
"RETURN substring('abcdef', head([null, 'x'])) AS v",
Expect::V(Value::Null),
),
("RETURN substring('abcdef') AS v", Expect::V(s("abcdef"))),
("RETURN left('abcdef') AS v", Expect::V(s(""))),
] {
check(&g, query, &expect);
}
}
/// ADR-0463: `range()` knows its exact element count before it allocates,
/// so an enormous result is refused up front with the expression-budget
/// capacity error (the display names the attempt and the budget). A
/// direction-inconsistent range is empty, so it allocates nothing and is
/// not refused.
/// ADR-0463 regression (round 2): an extreme range length must not wrap the
/// byte formula to a small charge. `reserved_len(len) * size_of::<Value>()`
/// overflows u64 above ~2^58 slots; saturating arithmetic turns that into
/// the typed capacity refusal instead of a wrapped pass followed by a
/// `Vec::with_capacity` abort (release) or arithmetic panic (debug).
#[test]
fn adr0463_extreme_range_length_is_a_typed_refusal_not_an_overflow() {
let g = Graph::default();
for n in [1_000_000_000_000_000_000_u64, 1_152_921_504_606_846_976_u64] {
let query = format!("RETURN range(1, {n}) AS v");
let error = try_exec_cypher(&g, &query)
.err()
.unwrap_or_else(|| panic!("range(1, {n}) must be refused"));
assert!(
matches!(
error,
Error::Capacity {
used,
limit,
kind: relate_core::CapacityKind::Expression,
} if used > limit && limit == crate::memory::EXPRESSION_BUDGET_BYTES
),
"range(1, {n}): {error}"
);
}
}
#[test]
fn adr0463_range_is_refused_before_an_over_budget_allocation() {
let g = Graph::default();
// Assert the typed refusal, not its rendered message: the budget is a
// constant, and the message rendering has its own pin.
let error = try_exec_cypher(&g, "RETURN range(1, 1000000000) AS v")
.err()
.expect("an over-budget range must be refused");
let attempted =
crate::workspace::buffer_bytes(1_000_000_000, std::mem::size_of::<Value>() as u64);
assert!(
matches!(
error,
Error::Capacity {
used,
limit,
kind: relate_core::CapacityKind::Expression,
} if used == attempted && limit == crate::memory::EXPRESSION_BUDGET_BYTES
),
"{error}"
);
// The refusal is the plain-language, three-part user message: what,
// that it is a protection, and how to raise it; GB/MB units, no jargon.
assert!(
error
.to_string()
.contains("tried to build a single value of")
&& error.to_string().contains("not a database limit")
&& error.to_string().contains("--expression-memory-limit"),
"{error}"
);
check(
&g,
"RETURN range(1000000000, 1) AS v",
&Expect::V(ints(&[])),
);
}