aion-cli 0.31.0

The `aion` command line: operate Aion durable workflows over gRPC and run the Aion server.
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
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
//! Tests for harness resolution and per-harness configuration.
//!
//! The resolution tests are written against whatever this build actually carries, so
//! they hold under every feature combination rather than only the default one: a build
//! that carries the declared kind resolves it, a build that does not refuses naming what
//! it does, and a build with none resolves to nothing without erroring. The
//! configuration tests are feature-gated, because a setting for an adapter this build
//! does not link has nothing to be built into.
//!
//! Every configuration here comes from a `CompiledHarness` — the checked `harness`
//! section of a worker document. There is no flag left to test: the launch flags were
//! DELETED when the section shipped, and the tests that exercised them went with them
//! rather than being kept alongside as a second surface nothing serves.

use std::path::{Path, PathBuf};
use std::time::Duration;

use aion_awl::{CompiledHarness, CompiledHarnessKind, CwdSource, HarnessPermission};
use aion_integrations::HarnessWorkspace;

use super::catalogue;
// Named only by the tests that configure a specific adapter; a build with none carries
// no such test.
#[cfg(any(feature = "norn", feature = "acp"))]
use super::catalogue::HarnessKind;

type TestResult = Result<(), Box<dyn std::error::Error>>;

/// The document path every refusal names. Never read: these tests build a
/// [`CompiledHarness`] directly, which is what the compile seam hands the resolver.
fn document() -> PathBuf {
    PathBuf::from("/srv/flows/assistant.awl")
}

/// A declared launch of `kind`, with the kind-independent settings filled in.
fn declared(kind: CompiledHarnessKind) -> CompiledHarness {
    CompiledHarness {
        concurrency: 4,
        reconnect_initial_backoff: Duration::from_secs(5),
        reconnect_max_backoff: Duration::from_secs(120),
        reconnect_max_attempts: 100,
        env_pass: vec![String::from("PATH"), String::from("HOME")],
        args: Vec::new(),
        kind,
    }
}

/// A `cwd` as a document writes it when it names a path.
fn literal(path: &str) -> CwdSource {
    CwdSource::Literal(PathBuf::from(path))
}

/// A declared ACP launch.
fn acp() -> CompiledHarness {
    declared(CompiledHarnessKind::Acp {
        command: PathBuf::from("/usr/local/bin/claude-code-acp"),
        cwd: literal("/srv/agents/workspace"),
        permission: HarnessPermission::Deny,
        exit_grace: Duration::from_secs(10),
    })
}

/// A declared Norn launch.
fn norn() -> CompiledHarness {
    declared(CompiledHarnessKind::Norn {
        binary: None,
        cwd: literal("/srv/agents/workspace"),
    })
}

/// The declared launch for whichever kind this build carries first, so a test about the
/// RESOLUTION rule runs under every feature combination.
#[cfg(any(feature = "norn", feature = "acp"))]
fn declared_for(kind: HarnessKind) -> CompiledHarness {
    match kind {
        #[cfg(feature = "norn")]
        HarnessKind::Norn => norn(),
        #[cfg(feature = "acp")]
        HarnessKind::Acp => acp(),
    }
}

/// The resolution rule, checked against what this build actually carries: a declared
/// kind the build links resolves; a build with no adapter resolves to nothing without
/// erroring, because `--check` must still report a surface it could not serve.
#[test]
fn a_declared_kind_resolves_against_the_adapters_this_build_links() -> TestResult {
    let compiled = catalogue::compiled();
    if compiled.is_empty() {
        let resolved = catalogue::resolve("norn", &document())?;
        assert!(
            resolved.is_none(),
            "a build with no adapter resolves to nothing rather than erroring, so the \
             action surface is still reported"
        );
        return Ok(());
    }
    for kind in compiled {
        let resolved = catalogue::resolve(kind.name(), &document())?;
        assert_eq!(
            resolved,
            Some(kind),
            "a declared kind this build links must resolve to it"
        );
    }
    Ok(())
}

#[test]
fn an_uncompiled_harness_name_is_refused_naming_what_is_compiled_in() -> TestResult {
    let compiled = catalogue::compiled();
    if compiled.is_empty() {
        // Nothing to be refused AGAINST: a build with no adapter resolves to nothing for
        // every name, which the test above pins.
        return Ok(());
    }
    let Err(error) = catalogue::resolve("gemini-cli", &document()) else {
        return Err("a kind this build does not carry must be refused".into());
    };
    let message = error.to_string();
    assert!(
        message.contains("gemini-cli"),
        "the refusal names what was declared: {message}"
    );
    assert!(
        message.contains("assistant.awl"),
        "the refusal names the document that declared it: {message}"
    );
    for kind in compiled {
        assert!(
            message.contains(kind.name()),
            "the refusal names `{}`, which this build does carry: {message}",
            kind.name()
        );
    }
    Ok(())
}

/// The declared `env_pass` list becomes the child's WHOLE environment, and a launch
/// reads no setting from a flag or an ambient variable.
#[cfg(any(feature = "norn", feature = "acp"))]
#[test]
fn the_declared_env_pass_list_is_the_childs_whole_environment() -> TestResult {
    let Some(kind) = catalogue::compiled().first().copied() else {
        return Ok(());
    };
    let mut launch = declared_for(kind);
    launch.env_pass = vec![String::from("PATH")];
    let Some(resolved) = super::settings::resolve(&launch, &document())? else {
        return Err("a build carrying an adapter must resolve the declared kind".into());
    };
    let environment = environment_of(&resolved.config);

    // The PRESENCE twin. This resolution reads THIS process's environment, so the
    // absence assertion below is only worth something if the process really carries
    // something that did not cross — otherwise it would pass just as well against an
    // implementation that resolved nothing at all. Cargo sets `CARGO_PKG_NAME` on every
    // test process, and it is not declared.
    assert!(
        std::env::var_os("CARGO_PKG_NAME").is_some(),
        "this test needs a variable the launching process really carries, or the \
         absence assertion below proves nothing"
    );
    assert!(
        environment.carries("PATH"),
        "the declared variable IS carried, so an absent reading cannot come from an \
         environment that resolved nothing: {:?}",
        environment.pairs()
    );
    assert_eq!(
        environment.declared(),
        ["PATH"],
        "the declaration is exactly what the document wrote"
    );
    assert!(
        !environment.carries("CARGO_PKG_NAME"),
        "a variable this process really carries, and the document does not name, does \
         not cross: {:?}",
        environment.pairs()
    );
    assert!(
        !environment.carries("CLAUDECODE"),
        "a variable the document does not name is absent whatever this process carries"
    );
    Ok(())
}

/// The child environment a configuration carries, whichever adapter it configures.
#[cfg(any(feature = "norn", feature = "acp"))]
fn environment_of(config: &super::settings::HarnessConfig) -> &aion_integrations::ChildEnvironment {
    match config {
        #[cfg(feature = "norn")]
        super::settings::HarnessConfig::Norn(norn) => &norn.environment,
        #[cfg(feature = "acp")]
        super::settings::HarnessConfig::Acp(acp) => &acp.environment,
    }
}

/// An `env_pass` entry that is a `KEY=VALUE` pair rather than a name is refused at the
/// launch boundary too, not only by the checker: a `CompiledHarness` can also reach this
/// code from a document compiled by an older binary.
#[cfg(any(feature = "norn", feature = "acp"))]
#[test]
fn an_env_pass_entry_carrying_a_value_is_refused_at_the_launch_boundary() -> TestResult {
    let Some(kind) = catalogue::compiled().first().copied() else {
        return Ok(());
    };
    let mut launch = declared_for(kind);
    launch.env_pass = vec![String::from("ANTHROPIC_API_KEY=sk-live")];
    let Err(error) = super::settings::resolve(&launch, &document()) else {
        return Err("a KEY=VALUE entry is not a pass-through name".into());
    };
    let message = format!("{error:#}");
    assert!(
        message.contains("ANTHROPIC_API_KEY=sk-live"),
        "the refusal quotes the entry: {message}"
    );
    assert!(
        message.contains("assistant.awl"),
        "the refusal names the document: {message}"
    );
    Ok(())
}

#[cfg(feature = "acp")]
#[test]
fn a_declared_acp_launch_reaches_the_adapter_verbatim() -> TestResult {
    let mut launch = acp();
    launch.args = vec![String::from("--acp")];
    launch.kind = CompiledHarnessKind::Acp {
        command: PathBuf::from("/opt/gemini/bin/gemini"),
        cwd: literal("/srv/agents/gemini"),
        permission: HarnessPermission::AllowOnce,
        exit_grace: Duration::from_secs(0),
    };
    let Some(resolved) = super::settings::resolve(&launch, &document())? else {
        return Err("this build links the acp adapter".into());
    };
    assert_eq!(resolved.kind, HarnessKind::Acp);
    let super::settings::HarnessConfig::Acp(config) = resolved.config else {
        return Err("an acp declaration must produce an acp configuration".into());
    };
    assert_eq!(config.command, Path::new("/opt/gemini/bin/gemini"));
    assert_eq!(config.args, vec![String::from("--acp")]);
    assert_eq!(
        config.workspace,
        HarnessWorkspace::Fixed(PathBuf::from("/srv/agents/gemini"))
    );
    assert_eq!(
        config.permission,
        aion_integration_acp::PermissionPolicy::AllowOnce
    );
    assert_eq!(
        config.exit_grace,
        Duration::ZERO,
        "zero is a legitimate grace and means close stdin, then kill at once"
    );
    Ok(())
}

#[cfg(feature = "acp")]
#[test]
fn each_permission_spelling_resolves_to_the_adapters_policy() -> TestResult {
    for (declared, expected) in [
        (
            HarnessPermission::Deny,
            aion_integration_acp::PermissionPolicy::Deny,
        ),
        (
            HarnessPermission::AllowOnce,
            aion_integration_acp::PermissionPolicy::AllowOnce,
        ),
    ] {
        let mut launch = acp();
        launch.kind = CompiledHarnessKind::Acp {
            command: PathBuf::from("/usr/local/bin/claude-code-acp"),
            cwd: literal("/srv/agents/workspace"),
            permission: declared,
            exit_grace: Duration::from_secs(1),
        };
        let Some(resolved) = super::settings::resolve(&launch, &document())? else {
            return Err("this build links the acp adapter".into());
        };
        let super::settings::HarnessConfig::Acp(config) = resolved.config else {
            return Err("an acp declaration must produce an acp configuration".into());
        };
        assert_eq!(
            config.permission, expected,
            "the document's policy and the adapter's must be one decision, not two"
        );
    }
    Ok(())
}

#[cfg(feature = "norn")]
#[test]
fn the_norn_binary_is_optional_and_the_absence_takes_the_adapters_own_default() -> TestResult {
    let Some(resolved) = super::settings::resolve(&norn(), &document())? else {
        return Err("this build links the norn adapter".into());
    };
    let super::settings::HarnessConfig::Norn(config) = resolved.config else {
        return Err("a norn declaration must produce a norn configuration".into());
    };
    assert_eq!(
        config.binary, None,
        "an omitted `binary` takes the adapter's own documented `norn`-on-PATH default, \
         which is the library's value rather than one invented at this boundary"
    );

    let mut declared_binary = norn();
    declared_binary.kind = CompiledHarnessKind::Norn {
        binary: Some(PathBuf::from("/opt/norn/bin/norn")),
        cwd: literal("/srv/agents/workspace"),
    };
    let Some(resolved) = super::settings::resolve(&declared_binary, &document())? else {
        return Err("this build links the norn adapter".into());
    };
    let super::settings::HarnessConfig::Norn(config) = resolved.config else {
        return Err("a norn declaration must produce a norn configuration".into());
    };
    assert_eq!(
        config.binary.as_deref(),
        Some(Path::new("/opt/norn/bin/norn"))
    );
    Ok(())
}

/// A document written to be correct on more than one machine round-trips: the checker's
/// second accepted form reaches this root as the literal placeholder, and what the
/// adapter is handed is the ABSOLUTE directory this box's own root makes of it.
///
/// The root is STATED rather than resolved from the process. Reading the real one would
/// make the assertion a restatement of whatever box the suite runs on — the pin has to
/// know the answer independently of the code under test, which is what
/// [`super::settings::resolve_against`] exists for.
#[cfg(feature = "norn")]
#[test]
fn a_workspace_rooted_cwd_is_expanded_against_this_boxs_own_root() -> TestResult {
    let scratch = tempfile::tempdir()?;
    let root = scratch.path().join("clones");
    let workspace = aion_server::worker::WorkspaceRoot::from_resolution(Ok(root.clone()));

    let mut launch = norn();
    launch.kind = CompiledHarnessKind::Norn {
        binary: None,
        cwd: literal("{workspace_root}/assistant"),
    };
    let Some(resolved) = super::settings::resolve_against(&launch, &document(), &workspace)? else {
        return Err("this build links the norn adapter".into());
    };
    let super::settings::HarnessConfig::Norn(config) = resolved.config else {
        return Err("a norn declaration must produce a norn configuration".into());
    };
    assert_eq!(
        config.workspace,
        HarnessWorkspace::Fixed(root.join("assistant")),
        "the placeholder must be replaced by THIS box's root, so one shipped document is \
         correct on every machine that runs it"
    );
    assert!(
        config.workspace.fixed().is_some_and(Path::is_absolute),
        "expansion does not soften the absolute rule; it is what makes it satisfiable for a \
         document that cannot name any one machine's path"
    );
    Ok(())
}

/// The worker says where its agents stand, and what it says is the value it will actually
/// spawn in.
///
/// This is the third channel the brief names. A document writing `{workspace_root}` is
/// DELIBERATELY silent about the path — that is the point of the placeholder, and it means
/// the document can no longer answer "where did my agent run". The startup line is the only
/// place the resolved answer exists, so it has to be the resolved answer: read through the
/// same [`super::settings::ResolvedHarness`] the adapter is handed, never re-derived from
/// the written value.
///
/// The written value is the mutation this pin exists to kill. An accessor that returned the
/// document's own string would look right in the source and log `{workspace_root}/assistant`
/// on every box — a report that names no directory at all, while the child stands somewhere
/// else entirely.
#[cfg(feature = "norn")]
#[test]
fn the_reported_launch_directory_is_the_one_the_child_will_stand_in() -> TestResult {
    let scratch = tempfile::tempdir()?;
    let root = scratch.path().join("clones");
    let workspace = aion_server::worker::WorkspaceRoot::from_resolution(Ok(root.clone()));

    let mut launch = norn();
    launch.kind = CompiledHarnessKind::Norn {
        binary: None,
        cwd: literal("{workspace_root}/assistant"),
    };
    let Some(resolved) = super::settings::resolve_against(&launch, &document(), &workspace)? else {
        return Err("this build links the norn adapter".into());
    };

    let reported = resolved.launch_directory_report();
    let super::settings::HarnessConfig::Norn(config) = resolved.config else {
        return Err("a norn declaration must produce a norn configuration".into());
    };
    assert_eq!(
        Some(Path::new(&reported)),
        config.workspace.fixed(),
        "the operator's report and the adapter's spawn must read ONE value — a report the \
         child can disagree with is worth less than no report"
    );
    assert_eq!(
        Path::new(&reported),
        root.join("assistant"),
        "and that one value is the EXPANDED directory, not the placeholder the document wrote"
    );
    Ok(())
}

/// The per-run form at the composition root: a document that BINDS its directory to an
/// action parameter resolves to the per-run workspace carrying that parameter's name, and
/// the startup line reports the parameter rather than inventing a directory.
///
/// The control is the whole test above: with a written path, the same code answers a
/// directory. A resolver that had collapsed both forms into one would fail one or the
/// other, and the two tests differ only in what the document declared.
#[cfg(feature = "norn")]
#[test]
fn a_bound_cwd_resolves_to_the_parameter_the_job_will_carry() -> TestResult {
    let scratch = tempfile::tempdir()?;
    let workspace =
        aion_server::worker::WorkspaceRoot::from_resolution(Ok(scratch.path().join("clones")));

    let mut launch = norn();
    launch.kind = CompiledHarnessKind::Norn {
        binary: None,
        cwd: CwdSource::Bound(String::from("repo")),
    };
    let Some(resolved) = super::settings::resolve_against(&launch, &document(), &workspace)? else {
        return Err("this build links the norn adapter".into());
    };
    let reported = resolved.launch_directory_report();
    assert_eq!(
        resolved.launch_workspace(),
        &HarnessWorkspace::PerRun(String::from("repo"))
    );
    assert!(
        reported.contains("repo"),
        "the startup line names the parameter each job's directory arrives in: {reported}"
    );
    assert_eq!(
        resolved.launch_workspace().fixed(),
        None,
        "a per-run workspace has no directory to report before a job exists, and must not \
         invent one — the whole hazard is an agent standing somewhere nobody chose"
    );
    Ok(())
}

/// Waffles' condition 2, at the end that spawns: expanding does not replace the absolute
/// requirement, it precedes it. Both arms are values the CHECKER would have refused — a
/// bare relative path, and a placeholder that cannot lead — and both must be refused here
/// too, because a `CompiledHarness` also reaches this root from a document compiled by an
/// older binary.
///
/// The root is RESOLVABLE for both, so neither refusal can be the root's fault, and the
/// test above is the presence twin: with this very shape of root, an accepted form
/// resolves. Without that pairing this would pass just as well against a boundary that
/// refused every `cwd` there is.
#[cfg(feature = "norn")]
#[test]
fn a_cwd_that_cannot_be_absolute_is_refused_at_the_composition_root() -> TestResult {
    let scratch = tempfile::tempdir()?;
    let workspace =
        aion_server::worker::WorkspaceRoot::from_resolution(Ok(scratch.path().join("clones")));

    for written in ["agents/workspace", "agents/{workspace_root}"] {
        let mut launch = norn();
        launch.kind = CompiledHarnessKind::Norn {
            binary: None,
            cwd: literal(written),
        };
        let Err(error) = super::settings::resolve_against(&launch, &document(), &workspace) else {
            return Err(
                format!("`cwd \"{written}\"` cannot name one place on every launch").into(),
            );
        };
        let message = format!("{error:#}");
        assert!(
            message.contains("not an absolute path"),
            "the refusal names the rule that was broken: {message}"
        );
        assert!(
            message.contains(written),
            "the refusal quotes what the document wrote: {message}"
        );
        assert!(
            message.contains("assistant.awl"),
            "the refusal names the document: {message}"
        );
    }
    Ok(())
}

/// Waffles' condition 4(c): a document carrying the placeholder, on a box whose home
/// cannot be resolved, refuses HERE — loudly, by name, carrying the resolution's own
/// reason — rather than spawning an agent somewhere nobody chose.
///
/// A document naming its own absolute path is untouched by the same unresolvable root,
/// which is the control: the refusal is scoped to values that actually need the root.
#[cfg(feature = "norn")]
#[test]
fn a_workspace_rooted_cwd_on_a_box_with_no_root_refuses_before_anything_spawns() -> TestResult {
    let workspace = aion_server::worker::WorkspaceRoot::from_resolution(Err(
        aion_server::worker::WorkspaceRootError::Unresolvable {
            reason: String::from("AION_HOME must not be empty"),
        },
    ));

    let mut launch = norn();
    launch.kind = CompiledHarnessKind::Norn {
        binary: None,
        cwd: literal("{workspace_root}/assistant"),
    };
    let Err(error) = super::settings::resolve_against(&launch, &document(), &workspace) else {
        return Err("a box that cannot say where its workspaces live cannot launch there".into());
    };
    let message = format!("{error:#}");
    assert!(
        message.contains("{workspace_root}/assistant"),
        "the refusal quotes what the document wrote: {message}"
    );
    assert!(
        message.contains("AION_HOME must not be empty"),
        "the refusal carries the resolution's own reason, so the operator knows what to fix: \
         {message}"
    );
    assert!(
        message.contains("assistant.awl"),
        "the refusal names the document: {message}"
    );

    // The control: the same unresolvable root launches an absolutely-written document
    // exactly as it did before expansion existed.
    let Some(resolved) = super::settings::resolve_against(&norn(), &document(), &workspace)? else {
        return Err("this build links the norn adapter".into());
    };
    let super::settings::HarnessConfig::Norn(config) = resolved.config else {
        return Err("a norn declaration must produce a norn configuration".into());
    };
    assert_eq!(
        config.workspace,
        HarnessWorkspace::Fixed(PathBuf::from("/srv/agents/workspace")),
        "a document that names its own path asks this box for nothing"
    );
    Ok(())
}

#[cfg(feature = "norn")]
#[test]
fn the_declared_argv_reaches_the_child_expanded_and_in_order() -> TestResult {
    use aion_core::{ActivityId, ContentType, Payload, RunId, WorkflowId};
    use aion_integrations::AgentRunSpec;

    let mut launch = norn();
    // Exactly what the document's `args` list carries, one entry per element.
    launch.args = [
        "--workspace-root",
        "/tmp/{workflow_id}/repo",
        "-C",
        "/tmp/{workflow_id}/repo",
        "--session-id",
        "{workflow_id}-{activity_type}",
        "--resume-if-exists",
        "--account",
        "default",
        "--fast",
    ]
    .map(str::to_owned)
    .to_vec();
    launch.env_pass = vec![String::from("PATH")];

    let Some(resolved) = super::settings::resolve(&launch, &document())? else {
        return Err("this build links the norn adapter".into());
    };
    let super::settings::HarnessConfig::Norn(config) = resolved.config else {
        return Err("a norn declaration must produce a norn configuration".into());
    };

    let harness = super::compose::build_norn(&config);
    let workflow_id = WorkflowId::new_v4();
    let spec = AgentRunSpec::new(
        workflow_id.clone(),
        RunId::new_v4(),
        ActivityId::from_sequence_position(1),
        1,
        "assistant",
        Payload::new(ContentType::Json, b"\"prompt\"".to_vec()),
    );
    let invocation = harness.invocation(&spec)?;

    let clone = format!("/tmp/{workflow_id}/repo");
    assert_eq!(
        invocation.argv,
        vec![
            String::from("--protocol"),
            String::from("jsonrpc"),
            String::from("--workspace-root"),
            clone.clone(),
            String::from("-C"),
            clone,
            String::from("--session-id"),
            format!("{workflow_id}-assistant"),
            String::from("--resume-if-exists"),
            String::from("--account"),
            String::from("default"),
            String::from("--fast"),
        ],
        "the child argv must be the document's arguments, in order, with the \
         run-identity placeholders expanded"
    );
    let Some(environment) = invocation.declared_environment else {
        return Err("the document's env_pass must reach the child as a declaration".into());
    };
    assert_eq!(
        environment.declared(),
        ["PATH"],
        "the declaration reaches the previewable invocation, so what this root composed \
         is what the spawn performs"
    );
    Ok(())
}

/// The name a harness is RESOLVED by and the name a document DECLARES must be the same
/// string.
///
/// The AWL side spells the two kinds in `aion_awl::HARNESS_KIND_*`; this side spells
/// them in [`HarnessKind::name`]. If they ever drifted, a document declaring a kind this
/// binary carries would be refused as one it does not, which is the exact failure the
/// resolution exists to prevent.
#[test]
fn the_document_vocabulary_and_the_catalogue_vocabulary_are_one_table() {
    let language = [aion_awl::HARNESS_KIND_ACP, aion_awl::HARNESS_KIND_NORN];
    for harness in catalogue::compiled() {
        assert!(
            language.contains(&harness.name()),
            "the catalogue carries `{}`, which no document can declare",
            harness.name()
        );
    }
}

#[test]
fn each_harness_advertises_its_adapters_published_capabilities() {
    for harness in catalogue::compiled() {
        let advertised = harness.registration_capabilities();
        let published = match harness.name() {
            #[cfg(feature = "norn")]
            "norn" => aion_integration_norn::registration_capabilities(),
            #[cfg(feature = "acp")]
            "acp" => aion_integration_acp::registration_capabilities(),
            other => unreachable!("unknown harness `{other}`"),
        };
        assert_eq!(
            advertised, published,
            "the root must publish the ADAPTER's set, never one of its own"
        );
    }
}

#[test]
fn a_build_with_no_harness_advertises_the_empty_set() {
    assert_eq!(
        super::registration_capabilities(None),
        aion_core::InterventionCapabilities::none(),
        "an empty advertisement is first-class: a build with no harness supports no \
         interventions and the console offers none"
    );
}

/// Every compiled-in harness composes into something the worker SDK can bind.
///
/// Nothing is spawned: constructing an adapter only captures its configuration, which is
/// what makes this a composition-root test rather than an agent test.
#[cfg(all(any(feature = "norn", feature = "acp"), feature = "liminal-transport"))]
#[test]
fn every_compiled_harness_composes() {
    for harness in catalogue::compiled() {
        let config = harness.test_config();
        // The composed value is accepted by the worker SDK's own agent binding, which is
        // the only thing the serve path requires of it: an `Arc<dyn DynAgentHarness>`
        // the worker can drive without knowing which adapter it got.
        let advertised = aion_worker::AgentHarnessConfig::new(
            super::compose::build(&config),
            [String::from("review")],
            catalogue::registration_capabilities(Some(harness)),
        );
        assert!(
            advertised.agent_activity_types().contains("review"),
            "`{}` must compose into a harness the worker binds",
            harness.name()
        );
    }
}