arvin 0.2.0

A staged cutoff for agent runs, where a run keeps its tools, budget, and sandbox only while it keeps proving progress. Three triggers move the stage, an operator pull, a budget ceiling, and missed proofs.
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
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
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
//! Replay pins for the recorded escalation corpus of Round 3.
//!
//! Each recorded case of tests/fixtures/escalation is rebuilt
//! from its construction script in corpus.json and judged again
//! offline, twice. The first replay runs through the subprocess
//! transport against a scripted helper that hands back the
//! recorded reply body, which pins the parsing of the recorded
//! body and the writing of its record, and the payload the
//! transport builds is compared byte for byte against the
//! recorded request. The second replay runs the same reply
//! through the fixture transport in typed form, and the two
//! replays must land the same record and the same state bytes.
//! The record of each replay is also compared against the
//! recorded outcome in manifest.json, and its stage against an
//! independent walk of the combination rule of DM-15 stated in
//! this file. The tests assert nothing about whether the model
//! was right, because a recorded reply is a fact and its quality
//! is the business of the landing evaluation, not of the gate.
//! No test in this file performs a network call.

use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicUsize, Ordering};

use arvin::{
    consultation_from_reply_body, Consultation, FixtureTransport, Instant, Record,
    SubprocessTransport, Switch, Value, Verdict, DE_ESCALATION_BAR, ESCALATION_BAR,
    LEGACY_MODEL_NAME, MODEL_NAME, STAGES,
};

// The small JSON reader and the stage ladder helpers stand in
// one home, tests/common/mod.rs (DM-A10).
mod common;

use common::{missed_warrant_index, stage_index, Json, Parser};

// ----------------------------------------------------------------
// Corpus and manifest loading.
// ----------------------------------------------------------------

fn fixtures_dir() -> PathBuf {
    Path::new(env!("CARGO_MANIFEST_DIR"))
        .join("tests")
        .join("fixtures")
        .join("escalation")
}

fn read_json(path: &Path) -> Json {
    let text = std::fs::read_to_string(path).expect("a fixture file reads");
    Parser::parse(&text).expect("a fixture file parses")
}

struct Case {
    id: String,
    run_id: String,
    interval: i64,
    limit: i64,
    soft: Option<i64>,
    hard: Option<i64>,
    spend_total: i64,
    ops: Vec<Op>,
    judge_at: i64,
    context: String,
    stage_before: String,
    missed: i64,
    seat: String,
    expected_record: Recorded,
    stage_after: String,
}

enum Op {
    Prove { at: i64, note: String },
    Spend { at: i64, amount: i64 },
    Stage { at: i64 },
}

struct Recorded {
    model_name: Option<String>,
    model_verdict: Option<String>,
    model_confidence: Option<f64>,
    model_score: Option<f64>,
    fallback_taken: Option<String>,
}

fn opt_str(json: &Json, key: &str) -> Option<String> {
    json.get(key).and_then(Json::as_str).map(str::to_string)
}

fn load_case(id: &str) -> Case {
    let corpus = read_json(&fixtures_dir().join("corpus.json"));
    let manifest = read_json(&fixtures_dir().join("manifest.json"));
    let item = corpus
        .get("cases")
        .and_then(Json::as_array)
        .expect("the corpus carries cases")
        .iter()
        .find(|case| case.get("id").and_then(Json::as_str) == Some(id))
        .unwrap_or_else(|| panic!("case {id} stands in the corpus"));
    let entry = manifest
        .get("cases")
        .and_then(Json::as_array)
        .expect("the manifest carries cases")
        .iter()
        .find(|case| case.get("id").and_then(Json::as_str) == Some(id))
        .unwrap_or_else(|| panic!("case {id} stands in the manifest"));
    let register = item.get("register").expect("a case carries its register");
    let facts = item.get("facts").expect("a case carries its facts");
    let judge = item.get("judge").expect("a case carries its judge");
    let recorded = entry.get("recorded").expect("an entry carries its record");
    let mut ops = Vec::new();
    let mut spend_total = 0i64;
    for op in item
        .get("ops")
        .and_then(Json::as_array)
        .expect("a case carries ops")
    {
        let at = op
            .get("at")
            .and_then(Json::as_i64)
            .expect("an op carries its instant");
        match op
            .get("op")
            .and_then(Json::as_str)
            .expect("an op carries its kind")
        {
            "prove" => ops.push(Op::Prove {
                at,
                note: op
                    .get("note")
                    .and_then(Json::as_str)
                    .unwrap_or("")
                    .to_string(),
            }),
            "spend" => {
                let amount = op
                    .get("amount")
                    .and_then(Json::as_i64)
                    .expect("a spend carries its amount");
                spend_total += amount;
                ops.push(Op::Spend { at, amount });
            }
            "stage" => ops.push(Op::Stage { at }),
            other => panic!("unknown op {other}"),
        }
    }
    Case {
        id: id.to_string(),
        run_id: register
            .get("run_id")
            .and_then(Json::as_str)
            .expect("a register carries its run id")
            .to_string(),
        interval: register
            .get("proof_interval_seconds")
            .and_then(Json::as_i64)
            .expect("interval"),
        limit: register
            .get("missed_proof_limit")
            .and_then(Json::as_i64)
            .expect("limit"),
        soft: register.get("soft_ceiling").and_then(Json::as_i64),
        hard: register.get("hard_ceiling").and_then(Json::as_i64),
        spend_total,
        ops,
        judge_at: judge
            .get("at")
            .and_then(Json::as_i64)
            .expect("judge instant"),
        context: judge
            .get("context")
            .and_then(Json::as_str)
            .expect("judge context")
            .to_string(),
        stage_before: facts
            .get("stage_before")
            .and_then(Json::as_str)
            .expect("stage before")
            .to_string(),
        missed: facts.get("missed").and_then(Json::as_i64).expect("missed"),
        seat: facts
            .get("seat")
            .and_then(Json::as_str)
            .expect("seat")
            .to_string(),
        expected_record: Recorded {
            model_name: opt_str(recorded, "model_name"),
            model_verdict: opt_str(recorded, "model_verdict"),
            model_confidence: recorded.get("model_confidence").and_then(Json::as_f64),
            model_score: recorded.get("model_score").and_then(Json::as_f64),
            fallback_taken: opt_str(recorded, "fallback_taken"),
        },
        stage_after: entry
            .get("stage_after")
            .and_then(Json::as_str)
            .expect("stage after")
            .to_string(),
    }
}

// ----------------------------------------------------------------
// Construction, in the same shape the recording harness drives.
// ----------------------------------------------------------------

static COUNTER: AtomicUsize = AtomicUsize::new(0);

struct TestDir(PathBuf);

impl TestDir {
    fn new(name: &str) -> TestDir {
        let unique = COUNTER.fetch_add(1, Ordering::SeqCst);
        let path = std::env::temp_dir().join(format!(
            "arvin-escalation-{}-{name}-{unique}",
            std::process::id()
        ));
        std::fs::create_dir_all(&path).expect("test dir is created");
        TestDir(path)
    }

    fn path(&self) -> &Path {
        &self.0
    }
}

impl Drop for TestDir {
    fn drop(&mut self) {
        let _ = std::fs::remove_dir_all(&self.0);
    }
}

fn t0() -> Instant {
    Instant::from_civil(2031, 5, 4, 12, 0, 0, 0, Some(0)).expect("the test instant is in range")
}

fn text(value: &str) -> Value {
    Value::Str(value.to_string())
}

fn int(value: i64) -> Value {
    Value::Int(value as i128)
}

fn build_document(case: &Case, dir: &TestDir, name: &str) -> (Switch, PathBuf) {
    let state_path = dir.path().join(name);
    let switch = Switch::new(state_path.clone());
    let base = t0();
    switch
        .register(
            &text(&case.run_id),
            &base,
            &int(case.interval),
            &int(case.limit),
            &case.soft.map_or(Value::Null, int),
            &case.hard.map_or(Value::Null, int),
        )
        .expect("registration succeeds");
    for op in &case.ops {
        match op {
            Op::Prove { at, note } => switch
                .prove(&text(&case.run_id), &text(note), &base.plus_seconds(*at))
                .expect("the proof posts"),
            Op::Spend { at, amount } => {
                switch
                    .spend(&text(&case.run_id), &int(*amount), &base.plus_seconds(*at))
                    .expect("the spend posts");
            }
            Op::Stage { at } => {
                switch
                    .stage(&text(&case.run_id), &base.plus_seconds(*at))
                    .expect("the evaluation runs");
            }
        }
    }
    (switch, state_path)
}

fn write_helper(dir: &TestDir, name: &str, body: &str) -> PathBuf {
    let path = dir.path().join(name);
    std::fs::write(&path, body).expect("the helper is written");
    // Portability adaptation because POSIX execute bits apply only on Unix,
    // while Windows dispatches batch helpers by file extension.
    #[cfg(unix)]
    {
        use std::os::unix::fs::PermissionsExt;
        std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o755))
            .expect("the helper is executable");
    }
    path
}

/// The combination rule of DM-15 walked independently of the
/// library, giving the stage a recorded outcome must leave
/// standing under the facts of its case.
fn mirror_stage_after(case: &Case) -> String {
    let before = stage_index(&case.stage_before);
    let recorded = &case.expected_record;
    let after = match (
        case.seat.as_str(),
        recorded.model_verdict.as_deref(),
        recorded.model_confidence,
    ) {
        ("held", Some("escalate"), Some(value)) if value >= ESCALATION_BAR => before + 1,
        ("fall", Some("de-escalate"), Some(value))
            if value >= DE_ESCALATION_BAR
                && missed_warrant_index(case.missed, case.limit) < before
                && case.soft.is_none_or(|ceiling| case.spend_total < ceiling)
                && case.hard.is_none_or(|ceiling| case.spend_total < ceiling) =>
        {
            before - 1
        }
        _ => before,
    };
    STAGES[after].to_string()
}

fn assert_record_matches(case: &Case, record: &Record) {
    let expected = &case.expected_record;
    assert_eq!(
        record.kind, "stage",
        "{}: the consultation record is a stage record",
        case.id
    );
    assert_eq!(
        record.model_name, expected.model_name,
        "{}: model name",
        case.id
    );
    assert_eq!(
        record.model_verdict, expected.model_verdict,
        "{}: verdict",
        case.id
    );
    assert_eq!(
        record.model_confidence, expected.model_confidence,
        "{}: confidence",
        case.id
    );
    assert_eq!(
        record.model_score, expected.model_score,
        "{}: score",
        case.id
    );
    assert_eq!(
        record.fallback_taken, expected.fallback_taken,
        "{}: fallback",
        case.id
    );
    assert_eq!(
        record.model_ancestry, None,
        "{}: ancestry stands null on every recorded case",
        case.id
    );
    assert_eq!(
        record.stage, case.stage_after,
        "{}: recorded stage",
        case.id
    );
    assert_eq!(
        mirror_stage_after(case),
        case.stage_after,
        "{}: the recorded stage after matches the combination rule mirror",
        case.id
    );
}

fn recorded_consultation(case: &Case) -> Consultation {
    let recorded = &case.expected_record;
    if let Some(class) = &recorded.fallback_taken {
        return match class.as_str() {
            "abstention" => Consultation::Abstention {
                model_name: recorded
                    .model_name
                    .clone()
                    .expect("a fallback names its model"),
            },
            "call failed" => Consultation::CallFailed,
            "silence" => Consultation::Silence,
            "malformed reply" => Consultation::MalformedReply,
            other => panic!("unknown fallback class {other}"),
        };
    }
    if let Some(verdict) = &recorded.model_verdict {
        let verdict = match verdict.as_str() {
            "hold" => Verdict::Hold,
            "escalate" => Verdict::Escalate,
            "de-escalate" => Verdict::DeEscalate,
            other => panic!("unknown verdict {other}"),
        };
        return Consultation::Verdict {
            model_name: recorded
                .model_name
                .clone()
                .expect("a verdict names its model"),
            verdict,
            confidence: recorded
                .model_confidence
                .expect("a verdict carries its confidence"),
            score: recorded.model_score.expect("a verdict carries its score"),
        };
    }
    Consultation::Abstention {
        model_name: recorded
            .model_name
            .clone()
            .expect("an abstention names its model"),
    }
}

fn replay(case_id: &str) {
    let case = load_case(case_id);
    let dir = TestDir::new("replay");
    // The wire replay. A scripted helper captures the payload it
    // is handed and prints the recorded reply body.
    let (switch, state_path) = build_document(&case, &dir, "wire.json");
    let capture = dir.path().join("payload.json");
    let reply_path = fixtures_dir()
        .join("replies")
        .join(format!("{case_id}.json"));
    // Portability adaptation selects the host script helper for wire replay.
    #[cfg(unix)]
    let helper = write_helper(
        &dir,
        "reply.sh",
        &format!(
            "#!/bin/sh\ncp \"$2\" \"{}\"\ncat \"{}\"\n",
            capture.display(),
            reply_path.display()
        ),
    );
    // Portability adaptation selects the host script helper for wire replay.
    #[cfg(windows)]
    let helper = write_helper(
        &dir,
        "reply.bat",
        &format!(
            "@echo off\r\ncopy /Y %2 \"{}\" >NUL\r\ntype \"{}\"\r\n",
            capture.display(),
            reply_path.display()
        ),
    );
    // Mechanical consequence of DM-24 advancing MODEL_NAME to
    // jev-1.14.0 while replaying the frozen Round 4 corpus under
    // LEGACY_MODEL_NAME so every recorded request and reply file
    // stands byte for byte unchanged.
    let transport = SubprocessTransport::with_model(
        helper,
        Vec::new(),
        std::time::Duration::from_secs(10),
        LEGACY_MODEL_NAME,
    )
    .expect("the legacy model name stands valid");
    let report = switch
        .stage_with_model(
            &text(&case.run_id),
            &t0().plus_seconds(case.judge_at),
            Some(&transport),
            Some(&case.context),
        )
        .expect("the judgment runs");
    assert_eq!(
        report.stage, case.stage_after,
        "{case_id}: the report stage"
    );
    let payload = std::fs::read(&capture).expect("the helper captured the payload");
    let recorded_request = std::fs::read(
        fixtures_dir()
            .join("requests")
            .join(format!("{case_id}.json")),
    )
    .expect("the recorded request reads");
    assert_eq!(
        payload, recorded_request,
        "{case_id}: the payload the library builds matches the recorded request byte for byte"
    );
    let log = switch.log(&text(&case.run_id)).expect("the log reads");
    let record = log.last().expect("the log carries the consultation record");
    assert_record_matches(&case, record);
    let wire_bytes = std::fs::read(&state_path).expect("the state file reads");
    // The typed replay. The same reply through the fixture
    // transport must land the same record and the same bytes.
    let (typed_switch, typed_path) = build_document(&case, &dir, "typed.json");
    let fixture = FixtureTransport::new(
        case.expected_record
            .model_name
            .as_deref()
            .expect("the record names its model"),
        vec![recorded_consultation(&case)],
    );
    let typed_report = typed_switch
        .stage_with_model(
            &text(&case.run_id),
            &t0().plus_seconds(case.judge_at),
            Some(&fixture),
            Some(&case.context),
        )
        .expect("the typed judgment runs");
    assert_eq!(
        typed_report.stage, case.stage_after,
        "{case_id}: the typed report stage"
    );
    let typed_log = typed_switch
        .log(&text(&case.run_id))
        .expect("the typed log reads");
    let typed_record = typed_log.last().expect("the typed log carries its record");
    assert_record_matches(&case, typed_record);
    assert_eq!(
        typed_record, record,
        "{case_id}: the two replays land the same record"
    );
    let typed_bytes = std::fs::read(&typed_path).expect("the typed state file reads");
    assert_eq!(
        wire_bytes, typed_bytes,
        "{case_id}: the two replays land the same state bytes"
    );
}

macro_rules! replay_case {
    ($name:ident, $id:literal) => {
        #[test]
        fn $name() {
            replay($id);
        }
    };
}

replay_case!(replay_dm_e01, "DM-E01");
replay_case!(replay_dm_e02, "DM-E02");
replay_case!(replay_dm_e03, "DM-E03");
replay_case!(replay_dm_e04, "DM-E04");
replay_case!(replay_dm_e05, "DM-E05");
replay_case!(replay_dm_e06, "DM-E06");
replay_case!(replay_dm_e07, "DM-E07");
replay_case!(replay_dm_e08, "DM-E08");
replay_case!(replay_dm_e09, "DM-E09");
replay_case!(replay_dm_e10, "DM-E10");
replay_case!(replay_dm_e11, "DM-E11");
replay_case!(replay_dm_e12, "DM-E12");
replay_case!(replay_dm_h01, "DM-H01");
replay_case!(replay_dm_h02, "DM-H02");
replay_case!(replay_dm_h03, "DM-H03");
replay_case!(replay_dm_h04, "DM-H04");
replay_case!(replay_dm_h05, "DM-H05");
replay_case!(replay_dm_h06, "DM-H06");
replay_case!(replay_dm_h07, "DM-H07");
replay_case!(replay_dm_h08, "DM-H08");
replay_case!(replay_dm_h09, "DM-H09");
replay_case!(replay_dm_h10, "DM-H10");
replay_case!(replay_dm_h11, "DM-H11");
replay_case!(replay_dm_h12, "DM-H12");
replay_case!(replay_dm_d01, "DM-D01");
replay_case!(replay_dm_d02, "DM-D02");
replay_case!(replay_dm_d03, "DM-D03");
replay_case!(replay_dm_d04, "DM-D04");
replay_case!(replay_dm_d05, "DM-D05");
replay_case!(replay_dm_d06, "DM-D06");
replay_case!(replay_dm_d07, "DM-D07");
replay_case!(replay_dm_d08, "DM-D08");
replay_case!(replay_dm_d09, "DM-D09");
replay_case!(replay_dm_d10, "DM-D10");
replay_case!(replay_dm_d11, "DM-D11");
replay_case!(replay_dm_d12, "DM-D12");
replay_case!(replay_dm_x01, "DM-X01");
replay_case!(replay_dm_x02, "DM-X02");
replay_case!(replay_dm_x03, "DM-X03");
replay_case!(replay_dm_x04, "DM-X04");
replay_case!(replay_dm_x05, "DM-X05");
replay_case!(replay_dm_x06, "DM-X06");
replay_case!(replay_dm_x07, "DM-X07");
replay_case!(replay_dm_x08, "DM-X08");
replay_case!(replay_dm_x09, "DM-X09");
replay_case!(replay_dm_x10, "DM-X10");
replay_case!(replay_dm_x11, "DM-X11");
replay_case!(replay_dm_x12, "DM-X12");

/// A recorded case replayed twice from its construction lands
/// byte identical state, the determinism claim of DM-20 read
/// against a recorded reply.
#[test]
fn a_recorded_case_replays_to_identical_state_bytes() {
    let case = load_case("DM-E01");
    let dir = TestDir::new("determinism");
    let mut states = Vec::new();
    for name in ["one.json", "two.json"] {
        let (switch, state_path) = build_document(&case, &dir, name);
        let fixture = FixtureTransport::new(
            case.expected_record
                .model_name
                .as_deref()
                .expect("the record names its model"),
            vec![recorded_consultation(&case)],
        );
        switch
            .stage_with_model(
                &text(&case.run_id),
                &t0().plus_seconds(case.judge_at),
                Some(&fixture),
                Some(&case.context),
            )
            .expect("the judgment runs");
        states.push(std::fs::read(&state_path).expect("the state file reads"));
    }
    assert_eq!(
        states[0], states[1],
        "two replays of one recorded case land identical bytes"
    );
}

/// The reply grammar the subprocess transport reads through
/// stands public under the Round 5 amendment, and over the
/// recorded reply body of every corpus case it returns the
/// consultation the manifest record describes, so a grammar
/// exposed wrongly, or a wrapper that translates instead of
/// delegating, fails against the corpus it claims to share
/// with the transport.
#[test]
fn the_public_reply_grammar_reads_every_recorded_reply() {
    let corpus = read_json(&fixtures_dir().join("corpus.json"));
    let cases = corpus
        .get("cases")
        .and_then(Json::as_array)
        .expect("the corpus carries cases");
    assert_eq!(cases.len(), 48, "the corpus stands at 48 cases");
    for item in cases {
        let id = item
            .get("id")
            .and_then(Json::as_str)
            .expect("a case carries its id");
        let case = load_case(id);
        let body =
            std::fs::read_to_string(fixtures_dir().join("replies").join(format!("{id}.json")))
                .expect("the recorded reply body reads");
        // Mechanical consequence of DM-24 advancing MODEL_NAME to
        // jev-1.14.0 while keeping the frozen Round 4 reply corpus
        // byte identical under LEGACY_MODEL_NAME.
        assert_eq!(
            consultation_from_reply_body(body.trim(), LEGACY_MODEL_NAME),
            recorded_consultation(&case),
            "{id}: the public grammar reads the recorded consultation"
        );
    }
}

/// A body naming a model other than the pinned name, and a
/// body standing as no document, each parse to the malformed
/// reply class through the public grammar, the two shapes the
/// command line fixture route must not mistake for a script.
/// An empty body stands in the second shape here, because the
/// fixture route makes no call and silence names a completed
/// call, so its empty script reads malformed and not silent.
#[test]
fn the_public_reply_grammar_refuses_a_foreign_model_and_no_document() {
    let foreign = "{\"model\": \"other-1.0\", \"choice\": {\"label\": null}}";
    assert_eq!(
        consultation_from_reply_body(foreign, MODEL_NAME),
        Consultation::MalformedReply,
        "a foreign model name is a malformed reply"
    );
    assert_eq!(
        consultation_from_reply_body("not a document", MODEL_NAME),
        Consultation::MalformedReply,
        "a body standing as no document is a malformed reply"
    );
    assert_eq!(
        consultation_from_reply_body("", MODEL_NAME),
        Consultation::MalformedReply,
        "an empty body handed to the grammar is a malformed reply"
    );
}