warble-cli 0.1.0

Warble CLI — compile profiles, dispatch to the Claude Code or Vercel target, render dashboards, emit manifests, run eval.
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
//! End-to-end golden tests: compile the real example projects through the real MDL `ContextLoader`
//! (the full host path) and assert the emitted IR equals the committed `ir.golden.json`, plus the
//! structural invariants each project is meant to demonstrate. These moved here from the core crate
//! in Phase 2 because they now depend on the binding-layer MDL adapter (core stays zero-wren).

use std::fs;
use std::path::{Path, PathBuf};

use warble_cli::compile_project_to_ir;

fn project(rel: &str) -> PathBuf {
    Path::new(env!("CARGO_MANIFEST_DIR")).join("..").join(rel)
}

fn compile(rel: &str) -> serde_json::Value {
    compile_project_to_ir(&project(rel)).unwrap_or_else(|e| panic!("{rel} must compile: {e}"))
}

fn golden(rel: &str) -> serde_json::Value {
    let path = project(rel).join("ir.golden.json");
    serde_json::from_str(&fs::read_to_string(&path).unwrap()).unwrap()
}

#[test]
fn golden_demo_agent_matches_exactly() {
    let ir = compile("examples/demo-agent");
    assert_eq!(ir, golden("examples/demo-agent"), "IR must equal golden");

    assert_eq!(ir["warble_ir_version"], "0.3");
    // Fine-grained resolved binding is present (jaffle-wren metrics/dimensions).
    assert!(ir["context_binding"]["resolved"]["metrics"].is_array());

    let render_blocks = ir["components"][0]["effect"]["render_blocks"]
        .as_array()
        .unwrap();
    assert_eq!(
        render_blocks,
        &vec![
            serde_json::json!({ "type": "chart", "fields": {} }),
            serde_json::json!({ "type": "table", "fields": {} }),
            serde_json::json!({ "type": "kpi_card", "fields": {} }),
        ],
        "bare-string render_blocks must normalize to typed objects with empty fields"
    );
}

#[test]
fn golden_render_demo_matches_exactly() {
    let ir = compile("examples/render-demo");
    assert_eq!(ir, golden("examples/render-demo"), "IR must equal golden");

    let component = &ir["components"][0];
    let guardrails = component["guardrails"].as_array().unwrap();
    assert_eq!(
        guardrails,
        &vec![
            serde_json::json!({ "name": "read_only_execution", "locked": true }),
            serde_json::json!({ "name": "artifact_write", "locked": true, "scope": "." }),
        ],
        "artifact_write guardrail must carry its scope through unchanged"
    );
    let required_capabilities = component["required_capabilities"].as_array().unwrap();
    for capability in ["render_contract", "artifact_write"] {
        assert!(
            required_capabilities.contains(&serde_json::json!(capability)),
            "required_capabilities must contain '{capability}'"
        );
    }
}

#[test]
fn golden_genbi_default_matches_exactly() {
    let ir = compile("genbi-default");
    assert_eq!(ir, golden("genbi-default"), "IR must equal golden");

    let components = ir["components"].as_array().unwrap();
    let verbs: Vec<&str> = components
        .iter()
        .map(|c| c["verb"].as_str().unwrap())
        .collect();
    assert_eq!(
        verbs,
        vec![
            "explore_model",
            "answer_query",
            "generate_dashboard",
            "explain_change"
        ]
    );

    let by_verb = |verb: &str| -> &serde_json::Value {
        components
            .iter()
            .find(|c| c["verb"] == verb)
            .unwrap_or_else(|| panic!("component '{verb}' must be present"))
    };

    // explore_model: semantic_introspection, renders nothing.
    let explore = by_verb("explore_model");
    assert!(explore["required_capabilities"]
        .as_array()
        .unwrap()
        .contains(&serde_json::json!("semantic_introspection")));
    assert_eq!(explore["effect"]["render_blocks"], serde_json::json!([]));

    // answer_query: 3-step canonical with repair_sql conditional.
    let answer = by_verb("answer_query");
    let repair = answer["llm_calls"]
        .as_array()
        .unwrap()
        .iter()
        .find(|c| c["name"] == "repair_sql")
        .expect("repair_sql step must be present");
    assert_eq!(repair["conditional"], serde_json::json!(true));
    assert_eq!(
        repair["when"],
        serde_json::json!({ "guard": "on_failure", "target": "generate_sql" }),
        "a conditional step's `when` guard (here on_failure) must compile into the IR"
    );

    // generate_dashboard: no context_precondition -- WrenAI is an orchestrator and doesn't gate
    // on data-shape/richness (has_groupable_dimension was dropped, same reasoning that already
    // dropped has_metric); that check belongs at the sub-agent level.
    let dashboard = by_verb("generate_dashboard");
    assert_eq!(
        dashboard["context_precondition"],
        serde_json::json!([]),
        "generate_dashboard declares no context_precondition"
    );
    assert_eq!(
        dashboard["precondition_result"]["checks"],
        serde_json::json!([]),
        "with no declared preconditions there is nothing to evaluate"
    );

    // explain_change: no context_precondition -- metric_additive / has_time_dimension /
    // has_groupable_dimension were all dropped for the same orchestrator-shouldn't-gate reason.
    // The per-metric additivity check still runs at runtime via the additivity_guard guardrail.
    let explain = by_verb("explain_change");
    assert_eq!(
        explain["context_precondition"],
        serde_json::json!([]),
        "explain_change declares no context_precondition"
    );
    assert_eq!(
        explain["precondition_result"]["checks"],
        serde_json::json!([]),
        "with no declared preconditions there is nothing to evaluate"
    );

    // The resolved binding surfaces the declared metric + its inferred additivity.
    let resolved_metrics = ir["context_binding"]["resolved"]["metrics"]
        .as_array()
        .unwrap();
    let total_revenue = resolved_metrics
        .iter()
        .find(|m| m["name"] == "total_revenue")
        .expect("total_revenue metric must be resolved from the revenue cube");
    assert_eq!(total_revenue["declared"], serde_json::json!(true));
    assert_eq!(total_revenue["additivity"], serde_json::json!("additive"));
}

#[test]
fn golden_mini_agent_matches_exactly() {
    let ir = compile("examples/mini-agent");
    assert_eq!(ir, golden("examples/mini-agent"), "IR must equal golden");

    let component = &ir["components"][0];
    assert_eq!(
        component["context_precondition"],
        serde_json::json!([{ "predicate": "wren_project_exists" }]),
        "structured context_precondition predicate must be carried into the IR"
    );
    assert_eq!(
        component["precondition_result"]["checks"],
        serde_json::json!([{ "predicate": "wren_project_exists", "outcome": "pass" }]),
        "wren_project_exists is evaluated (the bound project parses) and passes"
    );
    assert_eq!(
        component["params"],
        serde_json::json!([
            { "name": "style", "bind": "optional", "default": "concise" },
            { "name": "model_binding", "source": "runtime-injected" },
        ])
    );
}

/// The litmus: the first STRUCTURALLY different component compiles through the identical front-end
/// with no spine change. `monitor_freshness` is assertive / tool / scheduled / assertion, yet its IR
/// is emitted by the same compiler as the GenBI four — the assertion arm rides the existing
/// `effect.outcome` (verdict_type + emits), the scheduled trigger rides the existing `trigger.kind`,
/// and `model_has_timestamp` is really evaluated against jaffle-wren's `orders` DATE column.
#[test]
fn golden_monitor_agent_matches_exactly() {
    let ir = compile("examples/monitor-agent");
    assert_eq!(ir, golden("examples/monitor-agent"), "IR must equal golden");

    assert_eq!(ir["warble_ir_version"], "0.3");
    let c = &ir["components"][0];

    // The four structurally-new anatomy positions, all in fields the spine already had.
    assert_eq!(c["type"], "assertive");
    assert_eq!(c["realization_kind"], "tool");
    assert_eq!(c["trigger"]["kind"], "scheduled");
    assert_eq!(
        c["effect"]["outcome"],
        serde_json::json!({
            "kind": "assertion",
            "verdict_type": "freshness_verdict",
            "emits": ["freshness_breach"],
        }),
        "assertion outcome rides the existing effect.outcome arm — no new spine field"
    );
    assert_eq!(
        c["effect"]["render_blocks"],
        serde_json::json!([{ "type": "status", "fields": {} }]),
        "the verdict's presentational facet is a status block"
    );

    // The precondition is really evaluated (not a placeholder): orders carries a DATE column.
    assert_eq!(
        c["context_precondition"],
        serde_json::json!([{ "predicate": "model_has_timestamp", "args": { "model": "$param:model" } }])
    );
    assert_eq!(
        c["precondition_result"]["checks"],
        serde_json::json!([{ "predicate": "model_has_timestamp", "outcome": "pass" }]),
        "model_has_timestamp is evaluated against the bound MDL and passes"
    );

    // Borrowed transports are declared as capabilities; on-breach actions are borrowed, not owned.
    let caps = c["required_capabilities"].as_array().unwrap();
    for cap in ["scheduler", "sql_execution:read_only", "notify_channel"] {
        assert!(
            caps.contains(&serde_json::json!(cap)),
            "required_capabilities must contain {cap}"
        );
    }
    assert_eq!(
        c["borrowed_actions"],
        serde_json::json!(["notify_slack", "open_ticket"])
    );

    // assess_severity is guarded by on_flag(freshness_reading.stale) — a guarded-skip conditional
    // step carrying a closed-vocabulary `when` guard, not a bare `conditional` bool.
    let assess = c["llm_calls"]
        .as_array()
        .unwrap()
        .iter()
        .find(|call| call["name"] == "assess_severity")
        .expect("assess_severity step must be present");
    assert_eq!(assess["conditional"], serde_json::json!(true));
    assert_eq!(
        assess["when"],
        serde_json::json!({ "guard": "on_flag", "target": "freshness_reading.stale" })
    );
}

#[test]
fn golden_mutate_agent_matches_exactly() {
    let ir = compile("examples/mutate-agent");
    assert_eq!(ir, golden("examples/mutate-agent"), "IR must equal golden");

    assert_eq!(ir["warble_ir_version"], "0.3");
    let c = &ir["components"][0];

    // The +Mutating anatomy positions — all in fields the spine already carried (no new arm).
    assert_eq!(c["type"], "mutating");
    assert_eq!(c["realization_kind"], "gated-tool");
    assert_eq!(c["trigger"]["kind"], "one_shot");
    assert_eq!(
        c["effect"]["outcome"],
        serde_json::json!({
            "kind": "mutation",
            "target": "data",
            "change_type": "pipeline_definition",
        }),
        "mutation outcome rides the existing effect.outcome arm — target/change_type are facets, not new spine fields"
    );
    assert_eq!(
        c["effect"]["render_blocks"],
        serde_json::json!([{ "type": "diff", "fields": {} }]),
        "the change's presentational facet is a diff block"
    );

    // The precondition is really evaluated: jaffle-wren's lineage is resolvable, so a change's
    // blast radius can be computed and gated.
    assert_eq!(
        c["context_precondition"],
        serde_json::json!([{ "predicate": "lineage_resolvable" }])
    );
    assert_eq!(
        c["precondition_result"]["checks"],
        serde_json::json!([{ "predicate": "lineage_resolvable", "outcome": "pass" }]),
        "lineage_resolvable is evaluated against the bound MDL and passes"
    );

    // The mutating safety floor: every guardrail locked (a profile cannot weaken them).
    let guardrails = c["guardrails"].as_array().unwrap();
    for name in [
        "must_dry_run",
        "human_approval",
        "blast_radius_limit",
        "rollback_available",
        "write_authz",
    ] {
        let g = guardrails
            .iter()
            .find(|g| g["name"] == name)
            .unwrap_or_else(|| panic!("guardrail {name} must be present"));
        assert_eq!(g["locked"], true, "guardrail {name} must be locked");
    }
    // The moat gate carries its threshold through to the IR.
    let blast = guardrails
        .iter()
        .find(|g| g["name"] == "blast_radius_limit")
        .unwrap();
    assert_eq!(blast["threshold"]["max_severity"], "structural");
    assert_eq!(blast["threshold"]["max_downstream"], 5);

    // The moat + borrowed mutation capabilities are declared: human_approval (locked → fails on a
    // human-less target) and blast_radius (provided_by warble) among them.
    let caps = c["required_capabilities"].as_array().unwrap();
    for cap in [
        "blast_radius",
        "human_approval",
        "write_authz",
        "version_control",
        "sql_execution:read_only",
    ] {
        assert!(
            caps.contains(&serde_json::json!(cap)),
            "required_capabilities must contain {cap}"
        );
    }
}

#[test]
fn golden_driftwood_agent_matches_exactly() {
    let ir = compile("examples/driftwood-agent");
    assert_eq!(
        ir,
        golden("examples/driftwood-agent"),
        "IR must equal golden"
    );

    // driftwood-wren is authored in the wren CLI v5 project shape (keyed `relationships:`
    // mapping + `cubes/<name>/metadata.yml`), so this golden also exercises that adapter
    // path end-to-end — jaffle-wren covers the older bare-list + root-cubes.yml shape.
    let resolved = &ir["context_binding"]["resolved"];
    assert_eq!(
        resolved["lineage"]["resolvable"], true,
        "keyed relationships must produce a resolvable lineage"
    );
    // Cubes from the cubes/ directory reach the fine-grained binding: declared measures
    // (e.g. mrr_metrics.mrr) appear among the resolved metrics with known additivity.
    let metrics = resolved["metrics"].as_array().unwrap();
    let mrr = metrics
        .iter()
        .find(|m| m["name"] == "mrr")
        .expect("declared cube measure `mrr` must be resolved");
    assert_eq!(mrr["additivity"], "additive", "SUM measure infers additive");
}

/// The Constitutive litmus (Phase 4b): a component whose OUTPUT is the Context compiles through the
/// identical front-end, and the SPINE grows by vocabulary only. Two constitutive components mount on
/// a RAW source binding (no MDL yet); their preconditions read the new raw-shape predicates, and each
/// reuses the +Mutating `mutation` arm with `target: context` — differentiated from 4a's `target:
/// data` by that facet alone, no new outcome arm. The scoped third enforcement point (`models/` vs
/// `knowledge/`) is carried through per-component.
#[test]
fn golden_bootstrap_agent_matches_exactly() {
    let ir = compile("examples/bootstrap-agent");
    assert_eq!(
        ir,
        golden("examples/bootstrap-agent"),
        "IR must equal golden"
    );

    assert_eq!(ir["warble_ir_version"], "0.3");
    let components = ir["components"].as_array().unwrap();
    let by_verb = |verb: &str| -> &serde_json::Value {
        components
            .iter()
            .find(|c| c["verb"] == verb)
            .unwrap_or_else(|| panic!("component '{verb}' must be present"))
    };

    // bootstrap_mdl: constitutive, raw-shape precondition really evaluated against the raw source.
    let bootstrap = by_verb("bootstrap_mdl");
    assert_eq!(bootstrap["type"], "constitutive");
    assert_eq!(bootstrap["realization_kind"], "gated-tool");
    assert_eq!(
        bootstrap["context_precondition"],
        serde_json::json!([{ "predicate": "source_introspectable" }])
    );
    assert_eq!(
        bootstrap["precondition_result"]["checks"],
        serde_json::json!([{ "predicate": "source_introspectable", "outcome": "pass" }]),
        "source_introspectable is evaluated against the RAW source (not an existing MDL) and passes"
    );
    // The mutation arm is REUSED with target: context (spine stays 4-valued — no new outcome arm).
    assert_eq!(
        bootstrap["effect"]["outcome"],
        serde_json::json!({
            "kind": "mutation",
            "target": "context",
            "change_type": "mdl_bootstrap",
        }),
        "constitutive rides the +Mutating mutation arm; target: context is the facet, not a new arm"
    );
    // The third enforcement point, scoped to models/ (constitutive has NO blast_radius: it CREATES
    // lineage rather than gating an existing one).
    let bootstrap_guardrails = bootstrap["guardrails"].as_array().unwrap();
    let context_authz = bootstrap_guardrails
        .iter()
        .find(|g| g["name"] == "context_write_authz")
        .expect("context_write_authz guardrail present");
    assert_eq!(context_authz["locked"], true);
    assert_eq!(context_authz["scope"], "models/");
    assert!(
        !bootstrap_guardrails
            .iter()
            .any(|g| g["name"] == "blast_radius_limit"),
        "a constitutive create has no existing lineage to gate — no blast_radius_limit"
    );
    let bootstrap_caps = bootstrap["required_capabilities"].as_array().unwrap();
    for cap in [
        "schema_introspection",
        "context_write_authz",
        "human_approval",
    ] {
        assert!(
            bootstrap_caps.contains(&serde_json::json!(cap)),
            "bootstrap_mdl required_capabilities must contain {cap}"
        );
    }
    assert!(
        !bootstrap_caps.contains(&serde_json::json!("blast_radius")),
        "constitutive does not require blast_radius"
    );

    // enrich_knowledge: the sibling constitutive component reads the OTHER raw-shape predicate and
    // writes a DIFFERENT scope (knowledge/) — proving the scope is a per-component boundary.
    let enrich = by_verb("enrich_knowledge");
    assert_eq!(enrich["type"], "constitutive");
    assert_eq!(
        enrich["precondition_result"]["checks"],
        serde_json::json!([{ "predicate": "raw_docs_readable", "outcome": "pass" }]),
        "raw_docs_readable is evaluated against the raw docs and passes"
    );
    let enrich_scope = enrich["guardrails"]
        .as_array()
        .unwrap()
        .iter()
        .find(|g| g["name"] == "context_write_authz")
        .expect("context_write_authz guardrail present")["scope"]
        .clone();
    assert_eq!(
        enrich_scope, "knowledge/",
        "enrich_knowledge is scoped to knowledge/, NOT models/ — the scopes do not cross"
    );
}

/// genbi-setup (Phase 1 of the agentic onboarding flow): a new 5th enforcement point,
/// `setup_execution`, and two components that deliberately stay on the skill/`outcome.kind: none`
/// lifecycle rather than constitutive/gated-tool — unlike bootstrap_mdl above, there is no MDL diff
/// to gate here, only guarded onboarding actions (Bash + scoped Write), so `human_approval` never
/// enters the picture and this profile compiles clean on a headless target. Also exercises the RAW
/// binding path with an intentionally empty `raw/schema.json` (no tables) — proving the coarse
/// `is_parseable()` floor only needs a schema that parses, independent of any per-component
/// precondition (neither component here declares one).
#[test]
fn golden_genbi_setup_matches_exactly() {
    let ir = compile("genbi-setup");
    assert_eq!(ir, golden("genbi-setup"), "IR must equal golden");

    assert_eq!(ir["warble_ir_version"], "0.3");
    let components = ir["components"].as_array().unwrap();
    let verbs: Vec<&str> = components
        .iter()
        .map(|c| c["verb"].as_str().unwrap())
        .collect();
    assert_eq!(verbs, vec!["connect_source", "build_context"]);

    let by_verb = |verb: &str| -> &serde_json::Value {
        components
            .iter()
            .find(|c| c["verb"] == verb)
            .unwrap_or_else(|| panic!("component '{verb}' must be present"))
    };

    for (verb, capability) in [
        ("connect_source", "source_connect"),
        ("build_context", "context_build"),
    ] {
        let c = by_verb(verb);
        assert_eq!(c["type"], "analytical");
        assert_eq!(c["realization_kind"], "skill");
        assert_eq!(
            c["effect"]["outcome"],
            serde_json::json!({ "kind": "none" }),
            "{verb} stays on the skill lifecycle (outcome.kind: none), not gated-tool/mutation"
        );
        assert_eq!(
            c["context_precondition"],
            serde_json::json!([]),
            "{verb} declares no context_precondition — no existing semantic layer to probe yet"
        );

        // The 5th enforcement point: setup_execution, locked, scoped to the project root.
        let guardrails = c["guardrails"].as_array().unwrap();
        let setup = guardrails
            .iter()
            .find(|g| g["name"] == "setup_execution")
            .unwrap_or_else(|| panic!("{verb} must carry the setup_execution guardrail"));
        assert_eq!(
            setup["locked"], true,
            "{verb}'s setup_execution must be locked"
        );
        assert_eq!(
            setup["scope"], ".",
            "{verb}'s setup_execution scope defaults to the project root"
        );
        assert!(
            !guardrails
                .iter()
                .any(|g| g["name"] == "read_only_execution"),
            "{verb} must NOT also declare read_only_execution — setup_execution is its own flavor"
        );

        let caps = c["required_capabilities"].as_array().unwrap();
        assert!(
            caps.contains(&serde_json::json!(capability)),
            "{verb} required_capabilities must contain {capability}"
        );
    }

    // The RAW binding resolved (no MDL): context_binding.project is the raw pointer, not an MDL path.
    assert_eq!(ir["context_binding"]["project"], "raw");
}