axon-lang 4.2.0

AXON — the formal cognitive language: a deterministic, proof-carrying AI runtime. Native Rust lexer/parser/type-checker/IR generator (re-exported from axon-frontend) plus the runtime: typed channels (π-calculus mobility, capability extrusion), algebraic effects via Free Monad CPS handlers, lease kernel + reconcile loop, the Epistemic Security Kernel, Trust Types, Proof-Carrying Code (independently verifiable proof objects), and the closed-catalog extension mechanism. Crate publishes as `axon-lang`; library import is `use axon::*` so existing call sites keep working unchanged.
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
//! v2.81.0 — this suite exercises the HTTP server surface (the `axum`
//! router, the tenant extractor, the session carriers, the SSE dialect
//! adapters), which lives behind the `server` feature. Gated at the file level:
//! the core suites keep running in a `cli`-only build.
#![cfg(feature = "server")]

//! v2.8.0 — Real tool dispatch on the SSE / streaming path.
//!
//! Closes the last half of brief #22: the streaming dispatcher's
//! `use_tool` handler (`flow_dispatcher::lambda_tools::run_use_tool`)
//! used to return the static placeholder `"tool:<name>(<arg>)"`
//! (`invoke_tool`). After v2.8.0 it dispatches REAL against the
//! request-scoped `ctx.tool_registry` (wired by
//! `run_streaming_via_dispatcher` since v1.31.0), assembling the
//! STRUCTURED JSON body from `use Tool(k = v, …)` named args with the
//! SAME type-driven coercion the synchronous server path applies
//! (v2.8.0), reading the typed input schema carried on the
//! `ToolEntry` (v2.8.0 piece 1).
//!
//! Sections:
//! section 1 — real dispatch via the registry (stub provider, deterministic)
//! section 2 — D5 placeholder fall-backs (no registry / unregistered /
//!        LLM-routed provider) stay byte-for-byte unchanged
//! section 3 — D10 per-request isolation (registry is ctx-local)
//! section 4 — HTTP E2E: the structured JSON body reaches the wire with
//!        type-driven coercion (piece 1 + piece 2 end-to-end)

#![allow(clippy::needless_return)]

use std::sync::Arc;
use std::time::Duration;

use axon::cancel_token::CancellationFlag;
use axon::flow_dispatcher::lambda_tools::run_use_tool;
use axon::flow_dispatcher::{DispatchCtx, NodeOutcome};
use axon::flow_execution_event::FlowExecutionEvent;
use axon::ir_nodes::*;
use axon::tool_registry::{ToolEntry, ToolRegistry, ToolSource};

use axum::body::Body;
use axum::extract::{Request, State};
use axum::http::{header, Response, StatusCode};
use axum::routing::post;
use axum::Router;
use tokio::net::TcpListener;
use tokio::sync::mpsc;

// ────────────────────────────────────────────────────────────────────
//  Scaffolding
// ────────────────────────────────────────────────────────────────────

/// A `ToolEntry` with the `stub` provider — `ToolRegistry::dispatch`
/// returns `[stub] <name>(<arg>)` for it WITHOUT any network, so we can
/// prove "real dispatch through the registry, not the placeholder"
/// deterministically. `parameters` carries the typed input schema.
fn stub_entry(name: &str, parameters: Vec<(String, String)>) -> ToolEntry {
    ToolEntry {
        name: name.to_string(),
        provider: "stub".to_string(),
        timeout: String::new(),
        runtime: String::new(),
        resource_ref: String::new(),
        substrate: None,
        capacity: None,
        sandbox: None,
        max_results: None,
        output_schema: String::new(),
        effect_row: Vec::new(),
        parameters,
        secret: String::new(),
        secret_partition: String::new(),
        source: ToolSource::Program,
        is_streaming: false,
        scrape: None,
    }
}

fn http_entry(name: &str, url: &str, parameters: Vec<(String, String)>) -> ToolEntry {
    ToolEntry {
        name: name.to_string(),
        provider: "http".to_string(),
        timeout: "5s".to_string(),
        runtime: url.to_string(),
        resource_ref: String::new(),
        substrate: None,
        capacity: None,
        sandbox: None,
        max_results: None,
        output_schema: String::new(),
        effect_row: vec!["network".to_string()],
        parameters,
        secret: String::new(),
        secret_partition: String::new(),
        source: ToolSource::Program,
        is_streaming: false,
        scrape: None,
    }
}

fn named(args: &[(&str, &str)]) -> Vec<IRNamedArg> {
    args.iter()
        .map(|(n, v)| IRNamedArg {
            name: n.to_string(),
            value: v.to_string(),
            // v2.10.0 — these fixtures pass literals / `${…}` interpolation.
            value_kind: "literal".to_string(),
        })
        .collect()
}

fn use_node(tool_name: &str, argument: &str, named_args: Vec<IRNamedArg>) -> IRUseToolStep {
    IRUseToolStep {
        node_type: "use_tool",
        source_line: 0,
        source_column: 0,
        tool_name: tool_name.to_string(),
        argument: argument.to_string(),
        named_args,
    }
}

/// Build a fresh ctx; `registry` is `None` to exercise the D5
/// placeholder fall-back, `Some(reg)` to exercise real dispatch.
fn ctx_with(
    registry: Option<ToolRegistry>,
) -> (DispatchCtx, mpsc::UnboundedReceiver<FlowExecutionEvent>) {
    let (tx, rx) = mpsc::unbounded_channel();
    let mut ctx = DispatchCtx::new("TestFlow", "stub", "", CancellationFlag::new(), tx);
    if let Some(reg) = registry {
        ctx = ctx.with_tool_registry(Arc::new(reg));
    }
    (ctx, rx)
}

fn drain(rx: &mut mpsc::UnboundedReceiver<FlowExecutionEvent>) -> Vec<FlowExecutionEvent> {
    let mut out = Vec::new();
    while let Ok(e) = rx.try_recv() {
        out.push(e);
    }
    out
}

fn step_complete_success(events: &[FlowExecutionEvent]) -> Option<bool> {
    events.iter().find_map(|e| match e {
        FlowExecutionEvent::StepComplete { success, .. } => Some(*success),
        _ => None,
    })
}

// ════════════════════════════════════════════════════════════════════
// section 1 — Real dispatch via the registry (stub provider)
// ════════════════════════════════════════════════════════════════════

#[tokio::test]
async fn named_args_dispatch_real_structured_body_via_registry() {
    // A registered stub tool with a typed schema. The keyword form
    // assembles a structured JSON body and dispatches REAL — the
    // output is the registry's stub response, NOT the placeholder.
    let mut reg = ToolRegistry::new();
    reg.register(stub_entry(
        "Search",
        vec![
            ("query".to_string(), "String".to_string()),
            ("max_results".to_string(), "Int".to_string()),
        ],
    ));
    let (mut ctx, mut rx) = ctx_with(Some(reg));
    let node = use_node(
        "Search",
        "",
        named(&[("query", "Acme"), ("max_results", "5")]),
    );

    let outcome = run_use_tool(&node, &mut ctx).await.unwrap();
    let output = match outcome {
        NodeOutcome::Completed { output, .. } => output,
        other => panic!("expected Completed, got {other:?}"),
    };

    // Real dispatch: stub provider echoes the dispatched body, which is
    // the STRUCTURED JSON object — not `tool:Search(...)`.
    assert!(
        output.starts_with("[stub] Search("),
        "expected real stub dispatch, got: {output}"
    );
    assert!(
        !output.starts_with("tool:"),
        "placeholder must NOT be used when the tool dispatches real: {output}"
    );
    // The dispatched argument is the structured JSON body with
    // type-driven coercion (max_results is a NUMBER, query a STRING).
    let inner = output
        .strip_prefix("[stub] Search(")
        .and_then(|s| s.strip_suffix(")"))
        .expect("stub wrapper");
    let body: serde_json::Value = serde_json::from_str(inner).expect("structured JSON body");
    assert_eq!(body["query"], serde_json::json!("Acme"));
    assert_eq!(body["max_results"], serde_json::json!(5));

    // Result bound under the canonical key for downstream steps.
    assert_eq!(ctx.let_bindings.get("Search_result").unwrap(), &output);
    // StepComplete carries the real success flag.
    assert_eq!(step_complete_success(&drain(&mut rx)), Some(true));
}

#[tokio::test]
async fn named_args_interpolate_from_let_bindings() {
    // Named-arg VALUES interpolate `${name}` against ctx.let_bindings,
    // mirroring the synchronous path's ExecContext::interpolate.
    let mut reg = ToolRegistry::new();
    reg.register(stub_entry(
        "Search",
        vec![("query".to_string(), "String".to_string())],
    ));
    let (mut ctx, _rx) = ctx_with(Some(reg));
    ctx.let_bindings
        .insert("topic".to_string(), "quantum computing".to_string());
    let node = use_node("Search", "", named(&[("query", "${topic}")]));

    let outcome = run_use_tool(&node, &mut ctx).await.unwrap();
    let output = match outcome {
        NodeOutcome::Completed { output, .. } => output,
        other => panic!("expected Completed, got {other:?}"),
    };
    assert!(output.contains("quantum computing"), "got: {output}");
}

#[tokio::test]
async fn legacy_positional_arg_dispatches_real_when_registered() {
    // The legacy `use Tool on <arg>` form (D5) ALSO reaches real
    // dispatch when the tool is registered — the interpolated single
    // argument is the dispatched body.
    let mut reg = ToolRegistry::new();
    reg.register(stub_entry("Calc", Vec::new()));
    let (mut ctx, _rx) = ctx_with(Some(reg));
    ctx.let_bindings
        .insert("expr".to_string(), "2+2".to_string());
    let node = use_node("Calc", "${expr}", Vec::new());

    let outcome = run_use_tool(&node, &mut ctx).await.unwrap();
    let output = match outcome {
        NodeOutcome::Completed { output, .. } => output,
        other => panic!("expected Completed, got {other:?}"),
    };
    assert_eq!(output, "[stub] Calc(2+2)");
}

#[tokio::test]
async fn builtin_calculator_dispatches_real_on_streaming_path() {
    // A fresh registry carries the native built-ins; Calculator
    // evaluates natively (real dispatch) on the streaming path.
    let reg = ToolRegistry::new();
    let (mut ctx, _rx) = ctx_with(Some(reg));
    let node = use_node("Calculator", "2 + 3", Vec::new());

    let outcome = run_use_tool(&node, &mut ctx).await.unwrap();
    let output = match outcome {
        NodeOutcome::Completed { output, .. } => output,
        other => panic!("expected Completed, got {other:?}"),
    };
    assert_eq!(output, "5");
}

// ════════════════════════════════════════════════════════════════════
// section 2 — D5 placeholder fall-backs (unchanged from pre-58)
// ════════════════════════════════════════════════════════════════════

#[tokio::test]
async fn no_registry_falls_back_to_placeholder() {
    // No registry on the ctx → the canonical placeholder, byte-for-byte
    // the pre-58 behavior.
    let (mut ctx, mut rx) = ctx_with(None);
    ctx.let_bindings
        .insert("q".to_string(), "weather".to_string());
    let node = use_node("web_search", "q", Vec::new());

    let outcome = run_use_tool(&node, &mut ctx).await.unwrap();
    let output = match outcome {
        NodeOutcome::Completed { output, .. } => output,
        other => panic!("expected Completed, got {other:?}"),
    };
    assert_eq!(output, "tool:web_search(weather)");
    assert_eq!(step_complete_success(&drain(&mut rx)), Some(true));
}

#[tokio::test]
async fn unregistered_tool_falls_back_to_placeholder() {
    // Registry present but the tool is not registered → placeholder.
    let reg = ToolRegistry::new(); // builtins only
    let (mut ctx, _rx) = ctx_with(Some(reg));
    let node = use_node("UnknownTool", "arg", Vec::new());

    let outcome = run_use_tool(&node, &mut ctx).await.unwrap();
    let output = match outcome {
        NodeOutcome::Completed { output, .. } => output,
        other => panic!("expected Completed, got {other:?}"),
    };
    assert_eq!(output, "tool:UnknownTool(arg)");
}

#[tokio::test]
async fn llm_routed_provider_falls_back_to_placeholder() {
    // v2.69.0 — an LLM-ROUTED tool: no provider (the tool IS the model). `dispatch`
    // returns None → the caller uses the D5 placeholder. This used to be spelled
    // `provider: "brave"` — a non-empty *unknown* provider that fell through to the
    // LLM. Post-v2.69.0 an unknown provider is refused at compile, and the honest
    // way to say "route this to the model" is to OMIT the provider, validated by
    // its absence.
    let mut reg = ToolRegistry::new();
    reg.register(ToolEntry {
        name: "WebSearch".to_string(),
        provider: String::new(),
        timeout: String::new(),
        runtime: String::new(),
        resource_ref: String::new(),
        substrate: None,
        capacity: None,
        sandbox: None,
        max_results: Some(5),
        output_schema: String::new(),
        effect_row: Vec::new(),
        parameters: Vec::new(),
        secret: String::new(),
        secret_partition: String::new(),
        source: ToolSource::Program,
        is_streaming: false,
        scrape: None,
    });
    let (mut ctx, _rx) = ctx_with(Some(reg));
    let node = use_node("WebSearch", "cats", Vec::new());

    let outcome = run_use_tool(&node, &mut ctx).await.unwrap();
    let output = match outcome {
        NodeOutcome::Completed { output, .. } => output,
        other => panic!("expected Completed, got {other:?}"),
    };
    assert_eq!(output, "tool:WebSearch(cats)");
}

#[tokio::test]
async fn cancelled_ctx_short_circuits_before_dispatch() {
    let cancel = CancellationFlag::new();
    cancel.cancel();
    let (tx, _rx) = mpsc::unbounded_channel();
    let mut reg = ToolRegistry::new();
    reg.register(stub_entry("Search", Vec::new()));
    let mut ctx = DispatchCtx::new("F", "stub", "", cancel, tx).with_tool_registry(Arc::new(reg));
    let node = use_node("Search", "x", Vec::new());

    assert!(matches!(
        run_use_tool(&node, &mut ctx).await,
        Err(axon::flow_dispatcher::DispatchError::UpstreamCancelled)
    ));
}

// ════════════════════════════════════════════════════════════════════
// section 3 — D10 per-request isolation (registry is ctx-local)
// ════════════════════════════════════════════════════════════════════

#[tokio::test]
async fn registry_is_per_request_no_cross_contamination() {
    // Tenant A's ctx registers `Secret`; Tenant B's ctx does not.
    // B must NOT see A's tool — it falls back to the placeholder.
    let mut reg_a = ToolRegistry::new();
    reg_a.register(stub_entry("Secret", Vec::new()));
    let (mut ctx_a, _rx_a) = ctx_with(Some(reg_a));
    let (mut ctx_b, _rx_b) = ctx_with(Some(ToolRegistry::new())); // builtins only

    let node = use_node("Secret", "payload", Vec::new());

    let out_a = match run_use_tool(&node, &mut ctx_a).await.unwrap() {
        NodeOutcome::Completed { output, .. } => output,
        other => panic!("got {other:?}"),
    };
    let out_b = match run_use_tool(&node, &mut ctx_b).await.unwrap() {
        NodeOutcome::Completed { output, .. } => output,
        other => panic!("got {other:?}"),
    };

    assert_eq!(out_a, "[stub] Secret(payload)", "A dispatches real");
    assert_eq!(
        out_b, "tool:Secret(payload)",
        "B has no such tool → placeholder; no cross-tenant leakage"
    );
}

// ════════════════════════════════════════════════════════════════════
// section 4 — HTTP E2E: structured JSON body on the wire (piece 1 + 2)
// ════════════════════════════════════════════════════════════════════

type Captured = Arc<tokio::sync::Mutex<Option<String>>>;

async fn capture_handler(State(cap): State<Captured>, req: Request) -> Response<Body> {
    let bytes = axum::body::to_bytes(req.into_body(), usize::MAX)
        .await
        .unwrap_or_default();
    *cap.lock().await = Some(String::from_utf8_lossy(&bytes).to_string());
    Response::builder()
        .status(StatusCode::OK)
        .header(header::CONTENT_TYPE, "text/plain")
        .body(Body::from("RESULT_OK"))
        .expect("response")
}

async fn spawn_capture_server() -> (String, Captured) {
    let cap: Captured = Arc::new(tokio::sync::Mutex::new(None));
    let router = Router::new()
        .route("/", post(capture_handler))
        .with_state(cap.clone());
    let listener = TcpListener::bind("127.0.0.1:0").await.expect("bind");
    let addr = listener.local_addr().expect("addr");
    tokio::spawn(async move {
        let _ = axum::serve(listener, router).await;
    });
    tokio::time::sleep(Duration::from_millis(20)).await;
    (format!("http://{addr}/"), cap)
}

#[tokio::test]
async fn http_tool_receives_structured_typed_body_end_to_end() {
    let (url, cap) = spawn_capture_server().await;

    let mut reg = ToolRegistry::new();
    reg.register(http_entry(
        "CrmRadar",
        &url,
        vec![
            ("company".to_string(), "String".to_string()),
            ("max_results".to_string(), "Int".to_string()),
            ("active".to_string(), "Bool".to_string()),
            // A String param whose value is all-digits MUST stay a
            // string (no shape-guessing — type-driven coercion only).
            ("account_id".to_string(), "String".to_string()),
        ],
    ));
    let (mut ctx, _rx) = ctx_with(Some(reg));
    let node = use_node(
        "CrmRadar",
        "",
        named(&[
            ("company", "Acme Corp"),
            ("max_results", "5"),
            ("active", "true"),
            ("account_id", "007"),
        ]),
    );

    let outcome = run_use_tool(&node, &mut ctx).await.unwrap();
    let output = match outcome {
        NodeOutcome::Completed { output, .. } => output,
        other => panic!("expected Completed, got {other:?}"),
    };

    // Real HTTP response flowed back as the bound result.
    assert_eq!(output, "RESULT_OK");
    assert_eq!(
        ctx.let_bindings.get("CrmRadar_result").unwrap(),
        "RESULT_OK"
    );

    // The endpoint received the STRUCTURED, TYPE-COERCED JSON body.
    let received = cap.lock().await.clone().expect("server captured a body");
    let body: serde_json::Value =
        serde_json::from_str(&received).expect("server received valid JSON object");
    assert_eq!(body["company"], serde_json::json!("Acme Corp"));
    assert_eq!(body["max_results"], serde_json::json!(5)); // Int → number
    assert_eq!(body["active"], serde_json::json!(true)); // Bool → bool
    assert_eq!(body["account_id"], serde_json::json!("007")); // String → "007", not 7
                                                              // It is NOT the flat `{"input": …}` legacy envelope.
    assert!(
        body.get("input").is_none(),
        "must be structured, not flat input: {received}"
    );
}

#[tokio::test]
async fn http_legacy_positional_arg_wraps_as_input_envelope() {
    // D5: a legacy single-arg dispatch to an HTTP tool still wraps as
    // the `{"input": <arg>}` envelope (http_tool's non-JSON path).
    let (url, cap) = spawn_capture_server().await;
    let mut reg = ToolRegistry::new();
    reg.register(http_entry("Echo", &url, Vec::new()));
    let (mut ctx, _rx) = ctx_with(Some(reg));
    let node = use_node("Echo", "hello world", Vec::new());

    let outcome = run_use_tool(&node, &mut ctx).await.unwrap();
    let output = match outcome {
        NodeOutcome::Completed { output, .. } => output,
        other => panic!("got {other:?}"),
    };
    assert_eq!(output, "RESULT_OK");

    let received = cap.lock().await.clone().expect("captured body");
    let body: serde_json::Value = serde_json::from_str(&received).expect("valid JSON");
    assert_eq!(body["input"], serde_json::json!("hello world"));
}

// ════════════════════════════════════════════════════════════════════
// v2.10.0 — kwarg REFERENCE values resolve from the bindings
// ════════════════════════════════════════════════════════════════════

#[tokio::test]
async fn named_arg_reference_resolves_step_output_at_dispatch() {
    // v2.10.0 — a `"reference"` kwarg value (`ExtractTopic.output`) is
    // resolved against the bindings (the prior step's output, bound under its
    // step name) — NOT passed as the literal name (the pre-60 bug).
    let mut reg = ToolRegistry::new();
    reg.register(stub_entry(
        "Search",
        vec![("query".to_string(), "String".to_string())],
    ));
    let (mut ctx, _rx) = ctx_with(Some(reg));
    // A prior step `ExtractTopic` bound its output under its step name.
    ctx.let_bindings
        .insert("ExtractTopic".to_string(), "quantum computing".to_string());

    let node = use_node(
        "Search",
        "",
        vec![IRNamedArg {
            name: "query".to_string(),
            value: "ExtractTopic.output".to_string(),
            value_kind: "reference".to_string(),
        }],
    );

    let outcome = run_use_tool(&node, &mut ctx).await.unwrap();
    let output = match outcome {
        NodeOutcome::Completed { output, .. } => output,
        other => panic!("expected Completed, got {other:?}"),
    };
    let inner = output
        .strip_prefix("[stub] Search(")
        .and_then(|s| s.strip_suffix(")"))
        .expect("stub wrapper");
    let body: serde_json::Value = serde_json::from_str(inner).expect("structured JSON body");
    // The RESOLVED value reached the wire — not the literal "ExtractTopic.output".
    assert_eq!(body["query"], serde_json::json!("quantum computing"));
}

#[tokio::test]
async fn named_arg_reference_to_flow_param_resolves() {
    let mut reg = ToolRegistry::new();
    reg.register(stub_entry(
        "Search",
        vec![("query".to_string(), "String".to_string())],
    ));
    let (mut ctx, _rx) = ctx_with(Some(reg));
    ctx.let_bindings
        .insert("company".to_string(), "Acme".to_string());

    let node = use_node(
        "Search",
        "",
        vec![IRNamedArg {
            name: "query".to_string(),
            value: "company".to_string(),
            value_kind: "reference".to_string(),
        }],
    );

    let outcome = run_use_tool(&node, &mut ctx).await.unwrap();
    let output = match outcome {
        NodeOutcome::Completed { output, .. } => output,
        other => panic!("got {other:?}"),
    };
    let inner = output
        .strip_prefix("[stub] Search(")
        .and_then(|s| s.strip_suffix(")"))
        .expect("stub wrapper");
    let body: serde_json::Value = serde_json::from_str(inner).expect("JSON");
    assert_eq!(body["query"], serde_json::json!("Acme"));
}