cuttlefish-core 0.0.10

Cuttlefish.spec parsing and the typed job description
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
//! A spec grants capabilities, so what this parser *rejects* matters more than
//! what it accepts. Most of these tests are refusals: a spec that half-parses
//! would run a job under permissions nobody wrote down.

use cuttlefish_core::graph::{AcceptCheck, InputExpr, Rung};
use cuttlefish_core::spec::{parse_spec, DataPolicy, ModelRef, SpecError};
use std::path::PathBuf;

const SAMPLE: &str = r#"
spec summarize_docs = {
  description = "Use when the agent needs a summary of a local file.";
  model = Path "./models/stub.gguf";
  data_policy = Local_only;
  capabilities = [ Read "./docs" ];
  block = "../blocks/echo-summarize";
}
"#;

#[test]
fn parses_every_field_of_the_sample() {
    let spec = parse_spec(SAMPLE).expect("the sample must parse");

    assert_eq!(spec.name, "summarize_docs");
    assert!(spec.description.starts_with("Use when"));
    assert_eq!(spec.model, ModelRef::new("path", "./models/stub.gguf"));
    assert_eq!(spec.data_policy, DataPolicy::LocalOnly);
    assert_eq!(spec.read_roots, vec![PathBuf::from("./docs")]);
    assert_eq!(spec.nodes.nodes.len(), 1);
    let (_, node) = &spec.nodes.nodes[0];
    assert_eq!(node.block, PathBuf::from("../blocks/echo-summarize"));
}

#[test]
fn accepts_several_capabilities() {
    let src = SAMPLE.replace(
        r#"[ Read "./docs" ]"#,
        r#"[ Read "./docs", Read "./notes" ]"#,
    );
    let spec = parse_spec(&src).unwrap();
    assert_eq!(
        spec.read_roots,
        vec![PathBuf::from("./docs"), PathBuf::from("./notes")]
    );
}

#[test]
fn accepts_an_empty_capability_list() {
    // Granting nothing is meaningful and must not be confused with granting
    // everything — a spec that reads no files is a legitimate spec.
    let src = SAMPLE.replace(r#"[ Read "./docs" ]"#, "[ ]");
    let spec = parse_spec(&src).unwrap();
    assert!(spec.read_roots.is_empty());
}

#[test]
fn rejects_a_missing_required_field() {
    let src = SAMPLE.replace(r#"  block = "../blocks/echo-summarize";"#, "");
    let err = parse_spec(&src).unwrap_err();
    assert!(
        matches!(err, SpecError::MissingField("block")),
        "the error must name the missing field, got: {err}"
    );
}

#[test]
fn rejects_an_unknown_field_rather_than_ignoring_it() {
    // Silently skipping an unrecognised key is how a typo'd `capabilities`
    // becomes a spec with no capabilities that still runs.
    let src = SAMPLE.replace("  block =", "  frobnicate = 3;\n  block =");
    let err = parse_spec(&src).unwrap_err();
    assert!(
        matches!(&err, SpecError::UnknownField(f) if f == "frobnicate"),
        "the error must name the unknown field, got: {err}"
    );
}

#[test]
fn rejects_a_misspelled_capability_kind() {
    let src = SAMPLE.replace(r#"Read "./docs""#, r#"Write "./docs""#);
    let err = parse_spec(&src).unwrap_err();
    assert!(
        err.to_string().contains("Write"),
        "the unsupported capability must be named, got: {err}"
    );
}

#[test]
fn any_provider_name_parses() {
    // The parser deliberately does not know which providers exist — inference
    // can come from Ollama, an HTTP endpoint, an embedded runtime, or something
    // not written yet. Whether a provider is available is the host's question,
    // answered when the model is resolved, so a spec naming an unknown one is
    // syntactically fine and fails later with a list of what *is* registered.
    let src = SAMPLE.replace(r#"Path "./models/stub.gguf""#, r#"SomethingNew "whatever""#);
    let spec = parse_spec(&src).unwrap();
    assert_eq!(spec.model, ModelRef::new("somethingnew", "whatever"));
}

#[test]
fn provider_names_are_case_insensitive() {
    // `Ollama`, `ollama`, and `OLLAMA` must name the same provider; a spec
    // should not fail over capitalisation.
    for spelling in ["Ollama", "ollama", "OLLAMA"] {
        let src = SAMPLE.replace(
            r#"Path "./models/stub.gguf""#,
            &format!(r#"{spelling} "llama3.2:1b""#),
        );
        let spec = parse_spec(&src).unwrap();
        assert_eq!(spec.model.provider, "ollama", "for spelling {spelling}");
    }
}

#[test]
fn rejects_a_provider_name_that_is_not_an_identifier() {
    let src = SAMPLE.replace(r#"Path "./models/stub.gguf""#, r#""quoted" "target""#);
    assert!(parse_spec(&src).is_err());
}

#[test]
fn rejects_a_model_with_no_target() {
    let src = SAMPLE.replace(r#"model = Path "./models/stub.gguf""#, "model = Ollama");
    assert!(parse_spec(&src).is_err());
}

#[test]
fn parses_an_ollama_model_reference() {
    let src = SAMPLE.replace(r#"Path "./models/stub.gguf""#, r#"Ollama "llama3.2:1b""#);
    let spec = parse_spec(&src).unwrap();
    assert_eq!(spec.model, ModelRef::new("ollama", "llama3.2:1b"));
}

#[test]
fn an_ollama_tag_keeps_its_colon() {
    // Ollama model names carry a `:tag` suffix. If the parser ever splits on
    // punctuation, `llama3.2:1b` silently becomes `llama3.2` — a different
    // model that may well exist locally, so nothing would visibly break.
    let src = SAMPLE.replace(
        r#"Path "./models/stub.gguf""#,
        r#"Ollama "qwen2.5:7b-instruct-q4_K_M""#,
    );
    let spec = parse_spec(&src).unwrap();
    assert_eq!(
        spec.model,
        ModelRef::new("ollama", "qwen2.5:7b-instruct-q4_K_M")
    );
}

#[test]
fn rejects_an_unknown_data_policy() {
    let src = SAMPLE.replace("data_policy = Local_only;", "data_policy = Whatever;");
    let err = parse_spec(&src).unwrap_err();
    assert!(err.to_string().contains("Whatever"), "got: {err}");
}

#[test]
fn rejects_an_unquoted_string_field() {
    let src = SAMPLE.replace(r#"block = "../blocks/echo-summarize""#, "block = bare_word");
    assert!(parse_spec(&src).is_err());
}

#[test]
fn rejects_a_capability_list_that_is_not_a_list() {
    let src = SAMPLE.replace(
        r#"capabilities = [ Read "./docs" ]"#,
        r#"capabilities = "docs""#,
    );
    assert!(parse_spec(&src).is_err());
}

#[test]
fn rejects_input_with_no_spec_block() {
    assert!(parse_spec("").is_err());
    assert!(parse_spec("spec foo =").is_err());
    assert!(parse_spec("just some prose").is_err());
}

#[test]
fn rejects_a_spec_with_no_name() {
    let src = SAMPLE.replace("spec summarize_docs =", "spec =");
    assert!(parse_spec(&src).is_err());
}

#[test]
fn tolerates_extra_whitespace_and_a_trailing_semicolon() {
    let src = r#"
        spec   tidy   =   {
            description = "d" ;
            model = Path "m" ;
            data_policy = Any ;
            capabilities = [ ] ;
            block = "b" ;
        }
    "#;
    let spec = parse_spec(src).unwrap();
    assert_eq!(spec.name, "tidy");
    assert_eq!(spec.data_policy, DataPolicy::Any);
}

#[test]
fn the_repository_example_spec_parses() {
    // Guards against the shipped example drifting away from the parser, which
    // would otherwise only be noticed by someone following the README.
    let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
        .join("../../examples/summarize.cuttlefish");
    let src = std::fs::read_to_string(&path)
        .unwrap_or_else(|e| panic!("reading {}: {e}", path.display()));

    let spec = parse_spec(&src).expect("the shipped example must parse");
    assert_eq!(spec.name, "summarize_docs");
    assert_eq!(spec.data_policy, DataPolicy::LocalOnly);
}

#[test]
fn block_is_sugar_for_a_one_node_graph() {
    let spec = parse_spec(SAMPLE).unwrap();
    assert_eq!(spec.nodes.nodes.len(), 1);
    let (_, node) = &spec.nodes.nodes[0];
    assert_eq!(node.block, PathBuf::from("../blocks/echo-summarize"));
}

#[test]
fn a_nodes_block_with_fan_in_parses() {
    let src = SAMPLE.replace(
        r#"block = "../blocks/echo-summarize";"#,
        r#"nodes = {
             chunk = { block = "../blocks/chunk" };
             summarize = { block = "../blocks/summarize"; in = chunk.out; };
           };"#,
    );
    let spec = parse_spec(&src).unwrap();
    assert_eq!(spec.nodes.nodes.len(), 2);
    assert_eq!(
        spec.nodes.get("summarize").unwrap().input,
        Some(InputExpr::FromNode("chunk".into()))
    );
}

#[test]
fn an_empty_nodes_block_is_rejected() {
    let src = SAMPLE.replace(r#"block = "../blocks/echo-summarize";"#, "nodes = { };");
    assert!(parse_spec(&src).is_err());
}

#[test]
fn pipeline_field_is_no_longer_recognized() {
    let src = SAMPLE.replace(
        r#"block = "../blocks/echo-summarize";"#,
        r#"pipeline = [ "../blocks/chunk", "../blocks/summarize" ];"#,
    );
    assert!(matches!(
        parse_spec(&src),
        Err(SpecError::UnknownField(f)) if f == "pipeline"
    ));
}

// -- things the old character-splitting parser got wrong --------------------

#[test]
fn a_semicolon_inside_a_description_is_just_text() {
    // The bug that motivated a real lexer. Descriptions are prose, so they
    // contain semicolons routinely; splitting statements on `;` cut this in
    // half and blamed the description for not being a quoted string.
    let src = SAMPLE.replace(
        r#"description = "Use when the agent needs a summary of a local file.";"#,
        r#"description = "Use when summarizing; especially long files.";"#,
    );
    let spec = parse_spec(&src).expect("a semicolon in prose must parse");
    assert_eq!(
        spec.description,
        "Use when summarizing; especially long files."
    );
}

#[test]
fn a_comma_inside_a_path_is_just_text() {
    // Same failure, different separator: capability lists split on `,`.
    let src = SAMPLE.replace(r#"Read "./docs""#, r#"Read "./my,docs""#);
    let spec = parse_spec(&src).unwrap();
    assert_eq!(spec.read_roots, vec![PathBuf::from("./my,docs")]);
}

#[test]
fn braces_and_brackets_inside_strings_do_not_confuse_the_parser() {
    let src = SAMPLE.replace(
        r#"description = "Use when the agent needs a summary of a local file.";"#,
        r#"description = "Use when the input looks like { a: [1] }.";"#,
    );
    let spec = parse_spec(&src).unwrap();
    assert!(
        spec.description.contains("{ a: [1] }"),
        "{}",
        spec.description
    );
}

#[test]
fn escapes_are_resolved() {
    let src = SAMPLE.replace(
        r#"description = "Use when the agent needs a summary of a local file.";"#,
        r#"description = "Say \"hello\"\nthen stop.";"#,
    );
    let spec = parse_spec(&src).unwrap();
    assert_eq!(spec.description, "Say \"hello\"\nthen stop.");
}

#[test]
fn comments_are_ignored() {
    let src = format!("# what this job is for\n{SAMPLE}\n# trailing note\n");
    let spec = parse_spec(&src).expect("comments must not break parsing");
    assert_eq!(spec.name, "summarize_docs");
}

#[test]
fn a_trailing_semicolon_is_optional() {
    let src = SAMPLE.replace(
        r#"block = "../blocks/echo-summarize";"#,
        r#"block = "../blocks/echo-summarize""#,
    );
    assert!(parse_spec(&src).is_ok());
}

#[test]
fn an_unterminated_string_is_reported_with_a_position() {
    // "malformed spec" with no location is a poor error for a hand-edited file.
    let src = SAMPLE.replace(
        r#""../blocks/echo-summarize";"#,
        r#""../blocks/echo-summarize;"#,
    );
    let err = parse_spec(&src).unwrap_err().to_string();
    assert!(err.contains("unterminated"), "{err}");
    assert!(err.contains("line"), "the error should say where: {err}");
}

#[test]
fn a_syntax_error_says_what_was_expected_and_where() {
    let src = SAMPLE.replace("data_policy = Local_only;", "data_policy Local_only;");
    let err = parse_spec(&src).unwrap_err().to_string();
    assert!(err.contains("expected `=`"), "{err}");
    assert!(err.contains("line"), "{err}");
}

#[test]
fn an_unknown_escape_is_rejected_rather_than_silently_kept() {
    let src = SAMPLE.replace(
        r#"description = "Use when the agent needs a summary of a local file.";"#,
        r#"description = "a \q b";"#,
    );
    assert!(parse_spec(&src).is_err());
}

// --- Fan-out (`over`) ---------------------------------------------------
//
// A fan-out node runs its block once per manifest line instead of once. The
// manifest is read by the *host*, so the refusals below matter for the same
// reason every other refusal in this file does: a spec that half-parses runs
// a job touching paths nobody granted.

#[test]
fn a_node_can_declare_over_for_fan_out() {
    let spec = parse_spec(
        r#"spec s = {
  description = "d"; model = Stub "x"; data_policy = Any;
  capabilities = [ Read "./corpus" ];
  nodes = { a = { block = "a@1"; over = "./corpus/manifest.jsonl"; }; };
}"#,
    )
    .expect("a node with `over` must parse");
    let node = spec.nodes.get("a").expect("node `a`");
    assert_eq!(
        node.over.as_deref(),
        Some(std::path::Path::new("./corpus/manifest.jsonl"))
    );
}

#[test]
fn over_and_repeat_until_on_one_node_is_rejected() {
    let err = parse_spec(
        r#"spec s = {
  description = "d"; model = Stub "x"; data_policy = Any;
  capabilities = [ Read "./corpus" ];
  nodes = { a = { block = "a@1"; over = "./corpus/m.jsonl"; repeat_until = "done"; max_iterations = 3; }; };
}"#,
    )
    .expect_err("over + repeat_until must be rejected");
    let msg = err.to_string();
    assert!(msg.contains("over"), "{msg}");
    assert!(msg.contains("repeat_until"), "{msg}");
}

#[test]
fn a_manifest_outside_every_read_root_is_rejected() {
    // The check now runs on resolved paths, so parsing succeeds and
    // `validate_host_read_paths` is what refuses. Both sides here are
    // relative and stay comparable, which is the case that always worked.
    let spec = parse_spec(
        r#"spec s = {
  description = "d"; model = Stub "x"; data_policy = Any;
  capabilities = [ Read "./corpus" ];
  nodes = { a = { block = "a@1"; over = "./elsewhere/manifest.jsonl"; }; };
}"#,
    )
    .expect("this parses; the path check is a separate step");

    let err = spec
        .validate_host_read_paths()
        .expect_err("a manifest outside the read roots must be rejected");
    let msg = err.to_string();
    assert!(msg.contains("elsewhere/manifest.jsonl"), "{msg}");
    assert!(msg.contains("capabilities"), "{msg}");
    // The granted roots are listed, because the failure is nearly always a
    // path that looks right and differs by a symlink or by being relative.
    assert!(
        msg.contains("./corpus"),
        "must name what was granted: {msg}"
    );
}

/// An absolute grant with a relative manifest is ordinary, and used to be
/// rejected outright.
///
/// This is the bug that surfaced running a real OCR pipeline: `capabilities
/// = [ Read "/tmp/work" ]` with `over = "./corpus/m.jsonl"` failed with
/// "outside every path granted", which reads as a permissions mistake. It is
/// not — lexically a relative path can never begin with an absolute one, so
/// *every* spec of this shape was refused no matter where the files were.
/// Resolving both against the spec's directory first is what makes the
/// question answerable at all.
#[test]
fn an_absolute_grant_covers_a_relative_manifest_once_both_are_resolved() {
    let dir = tempfile::tempdir().unwrap();
    let root = std::fs::canonicalize(dir.path()).unwrap();
    std::fs::create_dir_all(root.join("corpus")).unwrap();
    std::fs::write(root.join("corpus/m.jsonl"), "{}\n").unwrap();

    let mut spec = parse_spec(&format!(
        r#"spec s = {{
  description = "d"; model = Stub "x"; data_policy = Any;
  capabilities = [ Read "{}" ];
  nodes = {{ a = {{ block = "a@1"; over = "./corpus/m.jsonl"; }}; }};
}}"#,
        root.display()
    ))
    .expect("a spec of this shape must parse");

    // What cuttlefishd does before validating: resolve everything against
    // the spec's own directory, then canonicalize.
    spec.read_roots = spec
        .read_roots
        .iter()
        .map(|r| std::fs::canonicalize(root.join(r)).unwrap_or_else(|_| root.join(r)))
        .collect();
    for (_, node) in spec.nodes.nodes.iter_mut() {
        if let Some(m) = node.over.take() {
            node.over = Some(std::fs::canonicalize(root.join(&m)).unwrap_or(root.join(m)));
        }
    }

    spec.validate_host_read_paths()
        .expect("an absolute grant covering the manifest's real location must pass");
}

/// `./corpus` and `corpus` name the same directory. A naive
/// `Path::starts_with` says otherwise (a leading `./` is a real
/// `Component::CurDir`), which would reject perfectly ordinary specs.
#[test]
fn a_leading_dot_slash_does_not_change_whether_a_manifest_is_covered() {
    for (root, manifest) in [
        ("./corpus", "./corpus/m.jsonl"),
        ("corpus", "./corpus/m.jsonl"),
        ("./corpus", "corpus/m.jsonl"),
    ] {
        parse_spec(&format!(
            r#"spec s = {{
  description = "d"; model = Stub "x"; data_policy = Any;
  capabilities = [ Read "{root}" ];
  nodes = {{ a = {{ block = "a@1"; over = "{manifest}"; }}; }};
}}"#
        ))
        .unwrap_or_else(|e| panic!("Read {root:?} must cover {manifest:?}: {e}"));
    }
}

// --- Acceptance checks (`accept`) ---------------------------------------
//
// What "done" means beyond a node's declared type. Ordered and
// short-circuiting: Schema is deterministic and free, Judge costs a whole
// inference, so a schema-first list never pays for a judge on structurally
// broken output.

#[test]
fn a_node_can_declare_accept_checks() {
    let spec = parse_spec(
        r#"spec s = {
  description = "d"; model = Stub "x"; data_policy = Any;
  capabilities = [ Read "./schemas" ];
  nodes = { a = { block = "a@1";
                  accept = [ Schema "./schemas/v.json", Judge "is it good?" ]; }; };
}"#,
    )
    .expect("accept must parse");
    let node = spec.nodes.get("a").unwrap();
    assert_eq!(node.accept.len(), 2);
    assert!(matches!(node.accept[0], AcceptCheck::Schema(_)));
    match &node.accept[1] {
        AcceptCheck::Judge { model, prompt } => {
            assert!(model.is_none(), "a bare Judge uses the spec's own model");
            assert_eq!(prompt, "is it good?");
        }
        other => panic!("expected a Judge, got {other:?}"),
    }
}

#[test]
fn a_judge_can_name_its_own_model() {
    // The form that actually works: a slow, strong model grading a fast
    // one's bulk output.
    let spec = parse_spec(
        r#"spec s = {
  description = "d"; model = Stub "x"; data_policy = Any; capabilities = [ ];
  nodes = { a = { block = "a@1";
                  accept = [ Judge { model = Ollama "llama3.3:70b"; prompt = "grade it"; } ]; }; };
}"#,
    )
    .expect("the record form of Judge must parse");
    match &spec.nodes.get("a").unwrap().accept[0] {
        AcceptCheck::Judge { model, prompt } => {
            assert_eq!(
                model.as_ref().unwrap(),
                &ModelRef::new("ollama", "llama3.3:70b")
            );
            assert_eq!(prompt, "grade it");
        }
        other => panic!("expected a Judge, got {other:?}"),
    }
}

#[test]
fn a_node_without_accept_has_no_checks() {
    // The default must stay exactly today's behaviour: the declared type is
    // the only contract.
    let spec = parse_spec(SAMPLE).unwrap();
    assert!(spec.nodes.get("block").unwrap().accept.is_empty());
}

// --- Recovery ladder (`on_fail`) ----------------------------------------

/// Build a one-node spec whose `on_fail` is `ladder`.
fn ladder_spec(ladder: &str) -> Result<cuttlefish_core::spec::Spec, SpecError> {
    parse_spec(&format!(
        r#"spec s = {{
  description = "d"; model = Stub "x"; data_policy = Any; capabilities = [ ];
  nodes = {{ a = {{ block = "a@1"; on_fail = {ladder}; }}; }};
}}"#
    ))
}

#[test]
fn a_node_can_declare_an_on_fail_ladder() {
    let spec = ladder_spec(r#"[ retry 2, reroute Ollama "llama3.3:70b", escalate ]"#)
        .expect("an on_fail ladder must parse");
    let rungs = &spec.nodes.get("a").unwrap().on_fail;
    assert_eq!(rungs.len(), 3);
    assert_eq!(rungs[0], Rung::Retry(2));
    assert_eq!(
        rungs[1],
        Rung::Reroute(ModelRef::new("ollama", "llama3.3:70b"))
    );
    assert_eq!(rungs[2], Rung::Escalate);
}

#[test]
fn escalate_must_be_the_last_rung() {
    // Anything after a terminal rung is unreachable. Accepting it would mean
    // a spec whose second half is decorative and whose author doesn't know.
    let err = ladder_spec("[ escalate, retry 2 ]").expect_err("must be rejected");
    assert!(err.to_string().contains("escalate"), "{err}");
}

#[test]
fn a_ladder_cannot_escalate_twice() {
    let err = ladder_spec("[ escalate, escalate ]").expect_err("must be rejected");
    assert!(err.to_string().contains("escalate"), "{err}");
}

#[test]
fn retry_zero_is_rejected() {
    // Expresses nothing: the author meant `retry 1`, or no rung at all.
    let err = ladder_spec("[ retry 0 ]").expect_err("must be rejected");
    assert!(err.to_string().contains("retry 0"), "{err}");
}

#[test]
fn a_node_without_on_fail_has_no_ladder() {
    let spec = parse_spec(SAMPLE).unwrap();
    assert!(spec.nodes.get("block").unwrap().on_fail.is_empty());
}

#[test]
fn a_schema_path_outside_every_read_root_is_rejected() {
    // Same move as the manifest check: parsing succeeds, and the path check
    // is its own step on resolved paths.
    let spec = parse_spec(
        r#"spec s = {
  description = "d"; model = Stub "x"; data_policy = Any;
  capabilities = [ Read "./corpus" ];
  nodes = { a = { block = "a@1"; accept = [ Schema "./elsewhere/v.json" ]; }; };
}"#,
    )
    .expect("this parses; the path check is a separate step");

    let err = spec
        .validate_host_read_paths()
        .expect_err("a schema outside the read roots must be rejected");
    let msg = err.to_string();
    assert!(msg.contains("elsewhere/v.json"), "{msg}");
    assert!(msg.contains("capabilities"), "{msg}");
}