arcbox-cli 0.6.8

Command-line interface for ArcBox
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
use std::fmt::Write as _;
use std::path::Path;

use anyhow::{Result, bail};
use arcbox_core::boot_assets::{
    BootAssetConfig, BootAssetManifest, BootAssetProvider, CachedBinaryReport,
};
use serde::Serialize;
use sha2::{Digest, Sha256};
use tokio::io::AsyncReadExt;

use super::super::OutputFormat;
use super::StatusArgs;

#[derive(Debug, Serialize)]
struct StatusOutput {
    version: String,
    arch: String,
    cache_dir: String,
    complete: bool,
    artifacts: Vec<ArtifactStatus>,
    #[serde(skip_serializing_if = "Option::is_none")]
    manifest: Option<ManifestInfo>,
    reasons: Vec<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    repair: Option<&'static str>,
    #[serde(skip_serializing_if = "Option::is_none")]
    latest_version: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    latest_version_error: Option<String>,
    update_available: bool,
}

#[derive(Debug, Serialize)]
struct ArtifactStatus {
    name: &'static str,
    path: String,
    required: bool,
    present: bool,
    #[serde(skip_serializing_if = "Option::is_none")]
    size_bytes: Option<u64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    source_path: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    version: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    detail: Option<String>,
}

#[derive(Debug, Serialize)]
struct ManifestInfo {
    schema_version: u32,
    asset_version: String,
    built_at: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    source_sha: Option<String>,
}

pub(super) async fn status(
    root_data_dir: &Path,
    config: BootAssetConfig,
    args: StatusArgs,
    format: OutputFormat,
) -> Result<()> {
    let provider = BootAssetProvider::with_config(config.clone())?;
    let manifest = provider
        .read_cached_manifest_required()
        .await
        .map_err(|error| format!("{error:#}"));
    let runtime_bin_dir = root_data_dir
        .join("runtime")
        .join(&config.version)
        .join("bin");
    let runtime_binaries = if manifest.is_ok() {
        provider
            .validate_cached_binaries(&runtime_bin_dir)
            .await
            .map_err(|error| format!("{error:#}"))
    } else {
        Err("manifest unavailable".to_owned())
    };
    let mut report = build_report(&runtime_bin_dir, &config, manifest, runtime_binaries).await;

    if !args.offline {
        match provider.fetch_latest_version().await {
            Ok(version) => report.latest_version = version,
            Err(error) => report.latest_version_error = Some(format!("{error:#}")),
        }
    }
    report.update_available = report
        .latest_version
        .as_ref()
        .is_some_and(|latest| latest != &report.version);

    match format {
        OutputFormat::Json => println!("{}", serde_json::to_string(&report)?),
        OutputFormat::Table => println!("{}", render_table(&report)),
        OutputFormat::Quiet => bail!("quiet output is not supported for boot status"),
    }
    if !report.complete {
        bail!("boot assets are incomplete");
    }
    Ok(())
}

async fn build_report(
    runtime_bin_dir: &Path,
    config: &BootAssetConfig,
    manifest_result: std::result::Result<BootAssetManifest, String>,
    runtime_binaries: std::result::Result<CachedBinaryReport, String>,
) -> StatusOutput {
    let version_dir = config.version_cache_dir();
    let kernel_path = config
        .custom_kernel
        .clone()
        .unwrap_or_else(|| version_dir.join("kernel"));
    let mut artifacts = vec![
        inspect_artifact("manifest", &version_dir.join("manifest.json"), true),
        inspect_artifact("kernel", &kernel_path, true),
        inspect_artifact("rootfs", &version_dir.join("rootfs.erofs"), true),
    ];
    let mut reasons = Vec::new();
    let mut manifest_info = None;

    match manifest_result {
        Err(error) => {
            artifacts[0].detail = Some(error.clone());
            if artifacts[0].present {
                reasons.push(format!("manifest: {error}"));
            }
        }
        Ok(manifest) => {
            manifest_info = Some(ManifestInfo {
                schema_version: manifest.schema_version,
                asset_version: manifest.asset_version.clone(),
                built_at: manifest.built_at.clone(),
                source_sha: manifest.source_sha.clone(),
            });
            if manifest.asset_version != config.version {
                reasons.push(format!(
                    "manifest selects version {}, expected {}",
                    manifest.asset_version, config.version
                ));
            }
            match manifest.targets.get(&config.arch) {
                Some(target) => {
                    if config.custom_kernel.is_none() {
                        artifacts[1].source_path = Some(target.kernel.path.clone());
                        artifacts[1].version.clone_from(&target.kernel.version);
                        verify_artifact_checksum(
                            &mut artifacts[1],
                            &kernel_path,
                            &target.kernel.sha256,
                            &mut reasons,
                        )
                        .await;
                    } else if artifacts[1].present {
                        artifacts[1].detail = Some("configured custom kernel".to_owned());
                    }
                    artifacts[2].source_path = Some(target.rootfs.path.clone());
                    artifacts[2].version.clone_from(&target.rootfs.version);
                    verify_artifact_checksum(
                        &mut artifacts[2],
                        &version_dir.join("rootfs.erofs"),
                        &target.rootfs.sha256,
                        &mut reasons,
                    )
                    .await;
                    if let Some(runtime) = &target.runtime {
                        let mut artifact =
                            inspect_artifact("runtime", &version_dir.join("runtime.erofs"), false);
                        artifact.source_path = Some(runtime.path.clone());
                        artifact.version.clone_from(&runtime.version);
                        artifact.detail = Some(
                            "legacy manifest entry; current ArcBox uses guest-cached runtime binaries"
                                .to_owned(),
                        );
                        artifacts.push(artifact);
                    }
                }
                None => reasons.push(format!(
                    "manifest has no target for architecture {}",
                    config.arch
                )),
            }
        }
    }

    // Permission drift is repaired by the next daemon start, so it is a detail
    // on a present artifact — never a reason to report the cache incomplete
    // and send the user into a full re-download.
    let (present, detail) = match runtime_binaries {
        Ok(report) if report.is_clean() => (true, None),
        Ok(report) => (true, Some(repairable_detail(&report))),
        Err(error) => (false, Some(error)),
    };
    artifacts.push(ArtifactStatus {
        name: "runtime-binaries",
        path: runtime_bin_dir.display().to_string(),
        required: true,
        present,
        size_bytes: None,
        source_path: None,
        version: manifest_info
            .as_ref()
            .map(|manifest| manifest.asset_version.clone()),
        detail,
    });

    for artifact in artifacts.iter().filter(|artifact| artifact.required) {
        if !artifact.present {
            reasons.push(format!(
                "{}: {}",
                artifact.name,
                artifact
                    .detail
                    .as_deref()
                    .unwrap_or("missing required artifact")
            ));
        }
    }
    let complete = reasons.is_empty();
    StatusOutput {
        version: config.version.clone(),
        arch: config.arch.clone(),
        cache_dir: version_dir.display().to_string(),
        complete,
        artifacts,
        manifest: manifest_info,
        reasons,
        repair: (!complete)
            .then_some("Fix the reported path or run `abctl boot prefetch --force`."),
        latest_version: None,
        latest_version_error: None,
        update_available: false,
    }
}

fn repairable_detail(report: &CachedBinaryReport) -> String {
    let names = report
        .not_executable
        .iter()
        .filter_map(|path| path.file_name())
        .map(|name| name.to_string_lossy().into_owned())
        .collect::<Vec<_>>()
        .join(", ");
    format!("executable bit missing on {names}; the daemon repairs this on its next start")
}

async fn verify_artifact_checksum(
    artifact: &mut ArtifactStatus,
    path: &Path,
    expected: &str,
    reasons: &mut Vec<String>,
) {
    if !artifact.present {
        return;
    }
    let detail = match sha256_file(path).await {
        Ok(actual) if actual == expected => return,
        Ok(actual) => format!("SHA-256 mismatch: expected {expected}, got {actual}"),
        Err(error) => format!("could not calculate SHA-256: {error}"),
    };
    reasons.push(format!("{}: {detail}", artifact.name));
    artifact.detail = Some(detail);
}

async fn sha256_file(path: &Path) -> std::io::Result<String> {
    let mut file = tokio::fs::File::open(path).await?;
    let mut hasher = Sha256::new();
    let mut buffer = vec![0; 1024 * 1024];
    loop {
        let read = file.read(&mut buffer).await?;
        if read == 0 {
            break;
        }
        hasher.update(&buffer[..read]);
    }
    Ok(format!("{:x}", hasher.finalize()))
}

fn inspect_artifact(name: &'static str, path: &Path, required: bool) -> ArtifactStatus {
    let metadata = std::fs::metadata(path)
        .ok()
        .filter(|metadata| metadata.is_file() && metadata.len() > 0);
    let present = metadata.is_some();
    ArtifactStatus {
        name,
        path: path.display().to_string(),
        required,
        present,
        size_bytes: metadata.map(|metadata| metadata.len()),
        source_path: None,
        version: None,
        detail: (path.exists() && !present)
            .then(|| "artifact is empty or is not a regular file".to_owned()),
    }
}

fn render_table(report: &StatusOutput) -> String {
    let mut output = String::from("Boot Asset Status\n=================\n\n");
    writeln!(output, "Cache directory: {}", report.cache_dir)
        .expect("writing to a String cannot fail");
    writeln!(output, "Current version: {}", report.version)
        .expect("writing to a String cannot fail");
    writeln!(output, "Architecture:    {}", report.arch).expect("writing to a String cannot fail");
    if let Some(latest) = &report.latest_version {
        writeln!(output, "Latest version:  {latest}").expect("writing to a String cannot fail");
    }
    if let Some(error) = &report.latest_version_error {
        writeln!(output, "Latest version:  unavailable ({error})")
            .expect("writing to a String cannot fail");
    }
    writeln!(
        output,
        "\nStatus: {}",
        if report.complete {
            "complete"
        } else {
            "incomplete"
        }
    )
    .expect("writing to a String cannot fail");

    for artifact in &report.artifacts {
        write!(
            output,
            "  [{}] {:<10} {}",
            if artifact.present { "+" } else { "-" },
            artifact.name,
            artifact.path
        )
        .expect("writing to a String cannot fail");
        if let Some(size) = artifact.size_bytes {
            write!(output, " ({size} bytes)").expect("writing to a String cannot fail");
        }
        if !artifact.required {
            output.push_str(" [legacy, not required]");
        }
        if let Some(detail) = &artifact.detail {
            write!(output, " — {detail}").expect("writing to a String cannot fail");
        }
        output.push('\n');
    }
    for reason in &report.reasons {
        writeln!(output, "  Reason: {reason}").expect("writing to a String cannot fail");
    }
    if let Some(repair) = report.repair {
        writeln!(output, "\nRepair: {repair}").expect("writing to a String cannot fail");
    }
    output.trim_end().to_owned()
}

#[cfg(test)]
mod tests {
    use super::*;

    const KERNEL: &[u8] = b"kernel";
    const ROOTFS: &[u8] = b"rootfs.erofs";

    fn runtime_bin_dir(root_data_dir: &Path, config: &BootAssetConfig) -> std::path::PathBuf {
        root_data_dir
            .join("runtime")
            .join(&config.version)
            .join("bin")
    }

    fn config(root_data_dir: &Path) -> BootAssetConfig {
        let mut config =
            BootAssetConfig::with_cache_dir(root_data_dir.join("boot")).with_version("0.8.4");
        config.arch = "arm64".to_owned();
        config
    }

    fn write_required_assets(config: &BootAssetConfig) {
        let version_dir = config.version_cache_dir();
        std::fs::create_dir_all(&version_dir).unwrap();
        std::fs::write(version_dir.join("manifest.json"), "{}").unwrap();
        std::fs::write(version_dir.join("kernel"), KERNEL).unwrap();
        std::fs::write(version_dir.join("rootfs.erofs"), ROOTFS).unwrap();
    }

    fn manifest(runtime: bool) -> BootAssetManifest {
        let kernel_sha256 = format!("{:x}", Sha256::digest(KERNEL));
        let rootfs_sha256 = format!("{:x}", Sha256::digest(ROOTFS));
        let runtime = if runtime {
            r#", "runtime": {"path": "arm64/runtime.erofs", "sha256": "03", "version": "29.0"}"#
        } else {
            ""
        };
        serde_json::from_str(&format!(
            r#"{{
                "schema_version": 0,
                "asset_version": "0.8.4",
                "built_at": "2026-08-10T00:00:00Z",
                "targets": {{
                    "arm64": {{
                        "kernel": {{"path": "arm64/kernel", "sha256": "{kernel_sha256}"}},
                        "rootfs": {{"path": "arm64/rootfs.erofs", "sha256": "{rootfs_sha256}"}},
                        "kernel_cmdline": "console=hvc0"{runtime}
                    }}
                }},
                "binaries": []
            }}"#
        ))
        .unwrap()
    }

    #[tokio::test]
    async fn missing_required_artifact_is_reported_in_json_and_table() {
        let directory = tempfile::tempdir().unwrap();
        let config = config(directory.path());
        let version_dir = config.version_cache_dir();
        std::fs::create_dir_all(&version_dir).unwrap();
        std::fs::write(version_dir.join("manifest.json"), "{}").unwrap();
        std::fs::write(version_dir.join("kernel"), KERNEL).unwrap();
        let report = build_report(
            &runtime_bin_dir(directory.path(), &config),
            &config,
            Ok(manifest(false)),
            Ok(CachedBinaryReport::default()),
        )
        .await;

        assert!(!report.complete);
        assert!(
            report
                .reasons
                .contains(&"rootfs: missing required artifact".to_owned())
        );
        assert!(render_table(&report).contains("Reason: rootfs: missing required artifact"));
        let json = serde_json::to_value(report).unwrap();
        assert_eq!(json["complete"], false);
        assert_eq!(json["reasons"][0], "rootfs: missing required artifact");
    }

    #[tokio::test]
    async fn corrupt_required_artifacts_are_reported_in_json_and_table() {
        for (file_name, artifact_name) in [("kernel", "kernel"), ("rootfs.erofs", "rootfs")] {
            let directory = tempfile::tempdir().unwrap();
            let config = config(directory.path());
            write_required_assets(&config);
            std::fs::write(config.version_cache_dir().join(file_name), b"corrupt").unwrap();

            let report = build_report(
                &runtime_bin_dir(directory.path(), &config),
                &config,
                Ok(manifest(false)),
                Ok(CachedBinaryReport::default()),
            )
            .await;

            assert!(!report.complete);
            let artifact = report
                .artifacts
                .iter()
                .find(|artifact| artifact.name == artifact_name)
                .unwrap();
            assert!(artifact.present);
            assert!(
                artifact
                    .detail
                    .as_deref()
                    .is_some_and(|detail| detail.starts_with("SHA-256 mismatch:"))
            );
            let reason = format!("Reason: {artifact_name}: SHA-256 mismatch:");
            assert!(render_table(&report).contains(&reason));
            let json = serde_json::to_value(report).unwrap();
            assert_eq!(json["complete"], false);
            let reason = format!("{artifact_name}: SHA-256 mismatch:");
            assert!(json["reasons"][0].as_str().unwrap().starts_with(&reason));
        }
    }

    #[tokio::test]
    async fn legacy_runtime_entry_is_enumerated_but_not_required() {
        let directory = tempfile::tempdir().unwrap();
        let config = config(directory.path());
        write_required_assets(&config);
        let report = build_report(
            &runtime_bin_dir(directory.path(), &config),
            &config,
            Ok(manifest(true)),
            Ok(CachedBinaryReport::default()),
        )
        .await;

        assert!(report.complete);
        let runtime = report
            .artifacts
            .iter()
            .find(|artifact| artifact.name == "runtime")
            .unwrap();
        assert!(!runtime.required);
        assert!(!runtime.present);
        assert_eq!(runtime.version.as_deref(), Some("29.0"));
    }

    /// The daemon repairs a missing executable bit on its next start, so
    /// reporting it as an incomplete cache would send the user into a
    /// re-download for drift that fixes itself. The reported path must also be
    /// the directory validation actually walked, since `repair` tells the user
    /// to fix it.
    #[tokio::test]
    async fn repairable_permission_drift_is_reported_without_failing_the_cache() {
        let directory = tempfile::tempdir().unwrap();
        let config = config(directory.path());
        write_required_assets(&config);
        let bin_dir = runtime_bin_dir(directory.path(), &config);

        let report = build_report(
            &bin_dir,
            &config,
            Ok(manifest(false)),
            Ok(CachedBinaryReport {
                not_executable: vec![bin_dir.join("dockerd")],
            }),
        )
        .await;

        assert!(report.complete);
        assert_eq!(report.repair, None);
        let runtime = report
            .artifacts
            .iter()
            .find(|artifact| artifact.name == "runtime-binaries")
            .unwrap();
        assert!(runtime.present);
        assert_eq!(runtime.path, bin_dir.display().to_string());
        assert_eq!(
            runtime.detail.as_deref(),
            Some("executable bit missing on dockerd; the daemon repairs this on its next start")
        );
        assert!(report.reasons.is_empty());
    }

    #[tokio::test]
    async fn runtime_binary_validation_is_part_of_the_status_contract() {
        let directory = tempfile::tempdir().unwrap();
        let config = config(directory.path());
        write_required_assets(&config);
        let validation_error =
            "cached runtime binary validation failed: binary 'dockerd' not found".to_owned();

        let report = build_report(
            &runtime_bin_dir(directory.path(), &config),
            &config,
            Ok(manifest(false)),
            Err(validation_error.clone()),
        )
        .await;

        assert!(!report.complete);
        let runtime = report
            .artifacts
            .iter()
            .find(|artifact| artifact.name == "runtime-binaries")
            .unwrap();
        assert!(runtime.required);
        assert!(!runtime.present);
        assert_eq!(runtime.detail.as_deref(), Some(validation_error.as_str()));
        assert_eq!(
            report.reasons,
            [format!("runtime-binaries: {validation_error}")]
        );
        let table = render_table(&report);
        assert!(table.contains("[-] runtime-binaries"));
        assert!(table.contains(&format!("Reason: runtime-binaries: {validation_error}")));
        let json = serde_json::to_value(report).unwrap();
        assert_eq!(json["complete"], false);
        assert_eq!(
            json["reasons"][0],
            format!("runtime-binaries: {validation_error}")
        );
    }

    #[tokio::test]
    async fn configured_custom_kernel_is_reported_without_release_checksum_validation() {
        let directory = tempfile::tempdir().unwrap();
        let custom_kernel = directory.path().join("custom-kernel");
        let mut config = config(directory.path());
        config.custom_kernel = Some(custom_kernel.clone());
        let version_dir = config.version_cache_dir();
        std::fs::create_dir_all(&version_dir).unwrap();
        std::fs::write(version_dir.join("manifest.json"), "{}").unwrap();
        std::fs::write(version_dir.join("rootfs.erofs"), ROOTFS).unwrap();
        std::fs::write(&custom_kernel, b"custom kernel with a different checksum").unwrap();

        let report = build_report(
            &runtime_bin_dir(directory.path(), &config),
            &config,
            Ok(manifest(false)),
            Ok(CachedBinaryReport::default()),
        )
        .await;

        assert!(report.complete);
        let kernel = report
            .artifacts
            .iter()
            .find(|artifact| artifact.name == "kernel")
            .unwrap();
        assert_eq!(kernel.path, custom_kernel.display().to_string());
        assert!(kernel.present);
        assert_eq!(kernel.source_path, None);
        assert_eq!(kernel.version, None);
        assert_eq!(kernel.detail.as_deref(), Some("configured custom kernel"));
        let table = render_table(&report);
        assert!(table.contains(&custom_kernel.display().to_string()));
        assert!(table.contains("configured custom kernel"));
        let json = serde_json::to_value(report).unwrap();
        let kernel = json["artifacts"]
            .as_array()
            .unwrap()
            .iter()
            .find(|artifact| artifact["name"] == "kernel")
            .unwrap();
        assert_eq!(kernel["path"], custom_kernel.display().to_string());
        assert_eq!(kernel["detail"], "configured custom kernel");

        std::fs::remove_file(&custom_kernel).unwrap();
        std::fs::create_dir(&custom_kernel).unwrap();
        let report = build_report(
            &runtime_bin_dir(directory.path(), &config),
            &config,
            Ok(manifest(false)),
            Ok(CachedBinaryReport::default()),
        )
        .await;
        assert!(!report.complete);
        let kernel = report
            .artifacts
            .iter()
            .find(|artifact| artifact.name == "kernel")
            .unwrap();
        assert_eq!(
            kernel.detail.as_deref(),
            Some("artifact is empty or is not a regular file")
        );
        assert!(
            report
                .reasons
                .iter()
                .any(|reason| { reason == "kernel: artifact is empty or is not a regular file" })
        );

        std::fs::remove_dir(&custom_kernel).unwrap();
        let report = build_report(
            &runtime_bin_dir(directory.path(), &config),
            &config,
            Ok(manifest(false)),
            Ok(CachedBinaryReport::default()),
        )
        .await;
        assert!(!report.complete);
        assert!(
            report
                .reasons
                .contains(&"kernel: missing required artifact".to_owned())
        );
    }

    #[tokio::test]
    async fn runtime_binaries_remain_required_when_the_manifest_is_unavailable() {
        let directory = tempfile::tempdir().unwrap();
        let config = config(directory.path());

        let report = build_report(
            &runtime_bin_dir(directory.path(), &config),
            &config,
            Err("manifest pin validation failed".to_owned()),
            Err("manifest unavailable".to_owned()),
        )
        .await;

        let runtime = report
            .artifacts
            .iter()
            .find(|artifact| artifact.name == "runtime-binaries")
            .unwrap();
        assert!(runtime.required);
        assert!(!runtime.present);
        assert_eq!(runtime.version, None);
        assert_eq!(runtime.detail.as_deref(), Some("manifest unavailable"));
        assert!(
            report
                .reasons
                .contains(&"runtime-binaries: manifest unavailable".to_owned())
        );
        assert_eq!(
            report.reasons,
            [
                "manifest: manifest pin validation failed".to_owned(),
                "kernel: missing required artifact".to_owned(),
                "rootfs: missing required artifact".to_owned(),
                "runtime-binaries: manifest unavailable".to_owned(),
            ]
        );
    }
}