amiss-bootstrap 0.4.0

Trusted CI wrapper that validates and launches a verified Amiss engine
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
#![expect(
    clippy::unwrap_used,
    clippy::expect_used,
    reason = "integration harness over asserted fixture shapes"
)]

use std::fs;
use std::path::Path;
use std::process::Command;

use amiss_bootstrap::build::{StagedArtifact, StagedBuild, StagedFile, build_manifest};
use amiss_bootstrap::{Refusal, validate};
use amiss_git::{GitLimits, GitResources, Repository};
use amiss_wire::action::host_platform;
use amiss_wire::controls::{ConstraintPlatform, ExecutionConstraintDescriptor};
use amiss_wire::digest::{Digest, hb};
use amiss_wire::json::{Value, canonical};
use amiss_wire::manifest::{ReleaseManifest, RuntimeRole};
use amiss_wire::model::ObjectFormat;
use tempfile::TempDir;

fn git(dir: &Path, args: &[&str]) -> String {
    let output = Command::new("git")
        .args(args)
        .current_dir(dir)
        .env("GIT_CONFIG_NOSYSTEM", "1")
        .env("GIT_CONFIG_GLOBAL", dir.join("absent-global-config"))
        .env("GIT_AUTHOR_NAME", "t")
        .env("GIT_AUTHOR_EMAIL", "t@example.invalid")
        .env("GIT_AUTHOR_DATE", "2026-01-01T00:00:00Z")
        .env("GIT_COMMITTER_NAME", "t")
        .env("GIT_COMMITTER_EMAIL", "t@example.invalid")
        .env("GIT_COMMITTER_DATE", "2026-01-01T00:00:00Z")
        .output()
        .expect("run git");
    assert!(
        output.status.success(),
        "git {args:?}: {}",
        String::from_utf8_lossy(&output.stderr)
    );
    String::from_utf8(output.stdout).expect("git output")
}

/// A plausible engine binary for the running platform: the real header bytes
/// the bootstrap derives the target from, padded with body content so the
/// digests are not degenerate.
fn engine_bytes(platform: ConstraintPlatform) -> Vec<u8> {
    let mut bytes = match platform {
        ConstraintPlatform::LinuxX8664 | ConstraintPlatform::LinuxAarch64 => {
            let machine: [u8; 2] = if platform == ConstraintPlatform::LinuxX8664 {
                [0x3e, 0x00]
            } else {
                [0xb7, 0x00]
            };
            let mut header = vec![0x7f, b'E', b'L', b'F', 2, 1, 1, 0];
            header.extend_from_slice(&[0; 8]);
            header.extend_from_slice(&[0x02, 0x00]);
            header.extend_from_slice(&machine);
            header
        }
        ConstraintPlatform::MacosX8664 | ConstraintPlatform::MacosAarch64 => {
            let cpu: [u8; 4] = if platform == ConstraintPlatform::MacosX8664 {
                [0x07, 0x00, 0x00, 0x01]
            } else {
                [0x0c, 0x00, 0x00, 0x01]
            };
            let mut header = vec![0xcf, 0xfa, 0xed, 0xfe];
            header.extend_from_slice(&cpu);
            header
        }
        ConstraintPlatform::WindowsX8664 | ConstraintPlatform::WindowsAarch64 => {
            let machine: [u8; 2] = if platform == ConstraintPlatform::WindowsX8664 {
                [0x64, 0x86]
            } else {
                [0x64, 0xaa]
            };
            let mut header = vec![b'M', b'Z'];
            header.resize(0x3c, 0);
            header.extend_from_slice(&0x40_u32.to_le_bytes());
            header.extend_from_slice(b"PE\0\0");
            header.extend_from_slice(&machine);
            header
        }
    };
    bytes.extend_from_slice(&[0x90; 512]);
    bytes
}

/// The launcher this repository ships, so the closure these tests validate is
/// the closure a release publishes, byte for byte.
const LAUNCHER: &[u8] = include_bytes!("../../../action/launcher.js");

/// The reviewed action definition, pinned the same way: the closure the
/// bootstrap validates is the closure a release publishes, byte for byte.
const ACTION: &[u8] = include_bytes!("../../../action/action.yml");

struct Release {
    dir: TempDir,
    commit: String,
    tree: String,
    manifest_digest: Digest,
    engine_digest: Digest,
    platform: ConstraintPlatform,
}

/// Stages a real action tree: the canonical `action.yml`, the generated
/// manifest, the launcher, and the platform binary, committed to a git
/// repository exactly as a release would publish it.
fn release(mutate: impl FnOnce(&Path)) -> Release {
    let platform = host_platform().expect("a supported test platform");
    let dir = TempDir::new().unwrap();
    let root = dir.path();
    git(root, &["init", "-q"]);

    let binary = engine_bytes(platform);
    let launcher = LAUNCHER.to_vec();
    let lock = b"# Cargo.lock fixture\nversion = 4\n".to_vec();
    let binary_path = format!("dist/amiss-{}", platform.as_str());

    let mut artifacts = vec![StagedArtifact {
        platform,
        artifact_name: format!("amiss-{}", platform.as_str()),
        files: vec![
            StagedFile {
                path: binary_path.clone(),
                role: RuntimeRole::Executable,
                executable: true,
                bytes: &binary,
            },
            StagedFile {
                path: "dist/launcher.js".to_owned(),
                role: RuntimeRole::Launcher,
                executable: false,
                bytes: &launcher,
            },
            StagedFile {
                path: "action.yml".to_owned(),
                role: RuntimeRole::RuntimeData,
                executable: false,
                bytes: ACTION,
            },
        ],
    }];
    let build = StagedBuild {
        engine_version: "0.1.0-experimental".to_owned(),
        owner: "hardmax71".to_owned(),
        repository: "amiss".to_owned(),
        object_format: "sha1",
        commit_oid: "a".repeat(40),
        locks: vec![("Cargo.lock".to_owned(), &lock)],
    };
    let (manifest_bytes, manifest_digest) = build_manifest(&build, &mut artifacts).unwrap();
    let engine_digest = hb(amiss_bootstrap::ENGINE_DOMAIN, &binary);

    fs::create_dir_all(root.join("dist")).unwrap();
    fs::write(root.join("action.yml"), ACTION).unwrap();
    fs::write(root.join("release-manifest.json"), &manifest_bytes).unwrap();
    fs::write(root.join("dist/launcher.js"), &launcher).unwrap();
    fs::write(root.join(&binary_path), &binary).unwrap();
    fs::write(root.join("Cargo.lock"), &lock).unwrap();
    mutate(root);

    git(root, &["add", "-A"]);
    executable(root, &binary_path);
    git(root, &["commit", "-qm", "release"]);
    let commit = git(root, &["rev-parse", "HEAD"]).trim().to_owned();
    let tree = git(root, &["rev-parse", "HEAD^{tree}"]).trim().to_owned();
    Release {
        dir,
        commit,
        tree,
        manifest_digest,
        engine_digest,
        platform,
    }
}

/// The engine's tree entry must be mode 100755. The bit is set on the index
/// entry, after staging: unix carries it in the worktree, which `git add`
/// reads and would otherwise overwrite, and Windows has no such bit at all. A
/// mutation that replaces the engine with something other than a regular file
/// has no executable bit to set, and says so by leaving the entry alone.
fn executable(root: &Path, path: &str) {
    if fs::symlink_metadata(root.join(path)).is_ok_and(|entry| entry.is_file()) {
        git(root, &["update-index", "--chmod=+x", "--", path]);
    }
}

fn string(text: &str) -> Value {
    Value::String(text.to_owned())
}

fn object(members: Vec<(&str, Value)>) -> Value {
    Value::Object(
        members
            .into_iter()
            .map(|(key, value)| (key.to_owned(), value))
            .collect(),
    )
}

/// The execution constraint the required workflow protects, pinning this
/// exact action commit, tree, manifest digest, platform, and bootstrap.
fn constraint(release: &Release) -> ExecutionConstraintDescriptor {
    let value = object(vec![
        ("schema", string("amiss/scanner-execution-constraint/v1")),
        (
            "action_repository",
            object(vec![
                ("host", string("github.com")),
                ("owner", string("hardmax71")),
                ("name", string("amiss")),
            ]),
        ),
        ("action_object_format", string("sha1")),
        ("action_commit_oid", string(&release.commit)),
        ("action_tree_oid", string(&release.tree)),
        ("manifest_path", string("release-manifest.json")),
        (
            "release_manifest_digest",
            string(&release.manifest_digest.to_string()),
        ),
        ("selected_platform", string(release.platform.as_str())),
        ("required_status_name", string("amiss / assure")),
        ("bootstrap_contract", string("amiss-action-bootstrap-v1")),
        (
            "bootstrap_digest",
            string(&hb(amiss_bootstrap::BOOTSTRAP_DOMAIN, BOOTSTRAP).to_string()),
        ),
    ]);
    ExecutionConstraintDescriptor::parse(&canonical(&value)).expect("the constraint parses")
}

fn attempt(release: &Release, bootstrap: &[u8]) -> Result<amiss_bootstrap::Validated, Refusal> {
    let repo = Repository::open(release.dir.path(), ObjectFormat::Sha1).expect("open action tree");
    let mut resources = GitResources::new(GitLimits::CONTRACT);
    validate(&repo, &mut resources, &constraint(release), bootstrap)
}

const BOOTSTRAP: &[u8] = b"the exact protected bootstrap bytes";

#[test]
fn the_pinned_release_validates_end_to_end() {
    let release = release(|_root| {});
    let validated = attempt(&release, BOOTSTRAP).expect("the staged release validates");
    assert_eq!(validated.platform, release.platform);
    assert_eq!(validated.engine_digest, release.engine_digest);
    assert_eq!(validated.manifest.engine_version, "0.1.0-experimental");
    assert_eq!(validated.artifact.runtime_files.len(), 3);
    assert!(
        validated.artifact.runtime_files.iter().any(|file| {
            file.role == RuntimeRole::RuntimeData && file.path.as_str() == "action.yml"
        }),
        "the runnable action definition is a pinned closure row"
    );
    assert_eq!(
        validated.manifest.dependency_lock.files.len(),
        1,
        "the lock set carries every build lockfile"
    );
}

#[test]
fn the_generated_manifest_reparses_to_its_pinned_digest() {
    let release = release(|_root| {});
    let bytes = fs::read(release.dir.path().join("release-manifest.json")).unwrap();
    assert_eq!(bytes.last(), Some(&b'\n'), "the manifest blob ends in LF");
    let parsed = ReleaseManifest::parse(&bytes).expect("the generated manifest parses");
    assert_eq!(parsed.digest, release.manifest_digest);
    assert_eq!(
        canonical(&amiss_wire::json::parse(bytes.strip_suffix(b"\n").unwrap()).unwrap()),
        bytes.strip_suffix(b"\n").unwrap(),
        "the manifest blob is exactly its own canonicalization"
    );
}

/// `runs.main` is what GitHub executes if a consumer writes
/// `uses: owner/amiss@sha`, so it is the one file in the tree that can report a
/// result without running the engine. It may fail and it may explain itself. It
/// may never exit 0, because a green check nobody earned is the failure this
/// whole project exists to refuse. Node ships on every runner image the release
/// targets, so a missing interpreter is a broken environment, not a skip.
#[test]
fn the_shipped_launcher_refuses_instead_of_passing() {
    let output = Command::new("node")
        .arg(concat!(
            env!("CARGO_MANIFEST_DIR"),
            "/../../action/launcher.js"
        ))
        .output()
        .expect("node runs the launcher; every runner image ships it");
    assert_eq!(
        output.status.code(),
        Some(2),
        "the launcher checked nothing, so it owes exit 2"
    );
    let said = String::from_utf8(output.stderr).expect("the launcher explains itself in UTF-8");
    assert!(
        said.contains("nothing was checked"),
        "the refusal says what did not happen: {said}"
    );
}

#[test]
fn a_bootstrap_whose_bytes_differ_refuses_before_anything_else() {
    let release = release(|_root| {});
    let outcome = attempt(&release, b"a different bootstrap binary");
    assert_eq!(outcome.err(), Some(Refusal::BootstrapDigest));
}

/// A file that is a symlink, which only a privileged Windows process can
/// create. The directory sides of the same law run on every platform, in
/// `amiss-git`'s `boundary.rs`.
#[cfg(unix)]
#[test]
fn a_symlinked_engine_path_refuses() {
    let release = release(|root| {
        let platform = host_platform().unwrap();
        let staged = root.join(format!("dist/amiss-{}", platform.as_str()));
        fs::remove_file(&staged).unwrap();
        std::os::unix::fs::symlink("../Cargo.lock", &staged).unwrap();
    });
    let outcome = attempt(&release, BOOTSTRAP);
    assert_eq!(
        outcome.err(),
        Some(Refusal::PathNotRegularBlob),
        "a symlink at the artifact path is never followed"
    );
}

/// Strips every `launcher` runtime row, wherever it appears. What is left is a
/// manifest a careless or hostile release could publish: internally consistent,
/// correctly digested, and silent about the one file `runs.main` names.
fn strip_launcher_rows(value: &mut Value) {
    match value {
        Value::Array(items) => {
            items.retain(|item| !is_launcher_row(item));
            for item in items.iter_mut() {
                strip_launcher_rows(item);
            }
        }
        Value::Object(members) => {
            for (_key, member) in members.iter_mut() {
                strip_launcher_rows(member);
            }
        }
        Value::Null | Value::Bool(_) | Value::Integer(_) | Value::String(_) => {}
    }
}

fn is_launcher_row(value: &Value) -> bool {
    let Value::Object(members) = value else {
        return false;
    };
    members.iter().any(|(key, member)| {
        key == "role" && matches!(member, Value::String(role) if role == "launcher")
    })
}

fn strip_action_rows(value: &mut Value) {
    match value {
        Value::Array(items) => {
            items.retain(|item| !is_action_row(item));
            for item in items.iter_mut() {
                strip_action_rows(item);
            }
        }
        Value::Object(members) => {
            for (_key, member) in members.iter_mut() {
                strip_action_rows(member);
            }
        }
        Value::Null | Value::Bool(_) | Value::Integer(_) | Value::String(_) => {}
    }
}

fn is_action_row(value: &Value) -> bool {
    let Value::Object(members) = value else {
        return false;
    };
    members.iter().any(|(key, member)| {
        key == "role" && matches!(member, Value::String(role) if role == "runtime-data")
    })
}

/// The action definition is what a `uses:` workflow actually executes, so a
/// manifest whose closure fails to pin it must refuse even when its digest
/// is self-consistent: otherwise the one runnable file at the tree root is
/// the one file nothing checks.
#[test]
fn a_manifest_that_omits_the_action_row_is_refused() {
    let mut restripped: Option<Digest> = None;
    let mut release = release(|root| {
        let path = root.join("release-manifest.json");
        let bytes = fs::read(&path).unwrap();
        let mut value =
            amiss_wire::json::parse(bytes.strip_suffix(b"\n").expect("the manifest ends in LF"))
                .expect("the manifest parses");
        strip_action_rows(&mut value);
        restripped = Some(amiss_wire::digest::hj(
            amiss_wire::manifest::MANIFEST_DOMAIN,
            &value,
        ));
        let mut out = canonical(&value);
        out.push(b'\n');
        fs::write(&path, out).unwrap();
    });
    release.manifest_digest = restripped.expect("the stripped manifest was digested");

    let outcome = attempt(&release, BOOTSTRAP);
    assert_eq!(
        outcome.err(),
        Some(Refusal::ActionMetadata),
        "an unpinned action definition is a refusal, not a runnable file"
    );
}

/// `runs.main` is the one file a `uses:` consumer executes, and pinning its
/// bytes is the whole reason the runtime closure exists. A manifest may not
/// stay silent about it: the row is required, exactly one, and mode `100644`.
/// Without this the manifest below validates clean while the launcher it points
/// at is never resolved in the tree at all.
#[test]
fn a_manifest_that_omits_the_launcher_row_is_refused() {
    let mut restripped: Option<Digest> = None;
    let mut release = release(|root| {
        let path = root.join("release-manifest.json");
        let bytes = fs::read(&path).unwrap();
        let mut value =
            amiss_wire::json::parse(bytes.strip_suffix(b"\n").expect("the manifest ends in LF"))
                .expect("the manifest parses");
        strip_launcher_rows(&mut value);
        restripped = Some(amiss_wire::digest::hj(
            amiss_wire::manifest::MANIFEST_DOMAIN,
            &value,
        ));
        let mut out = canonical(&value);
        out.push(b'\n');
        fs::write(&path, out).unwrap();
    });
    release.manifest_digest = restripped.expect("the stripped manifest was digested");

    let outcome = attempt(&release, BOOTSTRAP);
    assert_eq!(
        outcome.err(),
        Some(Refusal::ManifestUnreadable),
        "a manifest whose closure omits the launcher is not a manifest"
    );
}

#[test]
fn a_tampered_runtime_file_refuses_on_its_checksum() {
    let release = release(|root| {
        fs::write(root.join("dist/launcher.js"), b"// swapped after staging\n").unwrap();
    });
    let outcome = attempt(&release, BOOTSTRAP);
    assert_eq!(outcome.err(), Some(Refusal::RuntimeClosure));
}

#[test]
fn a_manifest_from_another_tree_refuses_on_its_digest() {
    let mut release = release(|_root| {});
    release.manifest_digest = hb("amiss/scanner-release-manifest/v1", b"another tree");
    let outcome = attempt(&release, BOOTSTRAP);
    assert_eq!(outcome.err(), Some(Refusal::ManifestDigest));
}

#[test]
fn an_engine_whose_header_names_another_platform_refuses() {
    let platform = host_platform().unwrap();
    let other = match platform {
        ConstraintPlatform::LinuxX8664
        | ConstraintPlatform::MacosX8664
        | ConstraintPlatform::MacosAarch64
        | ConstraintPlatform::WindowsX8664
        | ConstraintPlatform::WindowsAarch64 => ConstraintPlatform::LinuxAarch64,
        ConstraintPlatform::LinuxAarch64 => ConstraintPlatform::LinuxX8664,
    };
    let dir = TempDir::new().unwrap();
    let root = dir.path();
    git(root, &["init", "-q"]);

    let binary = engine_bytes(other);
    let launcher = LAUNCHER.to_vec();
    let lock = b"# Cargo.lock fixture\nversion = 4\n".to_vec();
    let binary_path = format!("dist/amiss-{}", platform.as_str());
    let mut artifacts = vec![StagedArtifact {
        platform,
        artifact_name: format!("amiss-{}", platform.as_str()),
        files: vec![
            StagedFile {
                path: binary_path.clone(),
                role: RuntimeRole::Executable,
                executable: true,
                bytes: &binary,
            },
            StagedFile {
                path: "dist/launcher.js".to_owned(),
                role: RuntimeRole::Launcher,
                executable: false,
                bytes: &launcher,
            },
            StagedFile {
                path: "action.yml".to_owned(),
                role: RuntimeRole::RuntimeData,
                executable: false,
                bytes: ACTION,
            },
        ],
    }];
    let build = StagedBuild {
        engine_version: "0.1.0-experimental".to_owned(),
        owner: "hardmax71".to_owned(),
        repository: "amiss".to_owned(),
        object_format: "sha1",
        commit_oid: "a".repeat(40),
        locks: vec![("Cargo.lock".to_owned(), &lock)],
    };
    let (manifest_bytes, manifest_digest) = build_manifest(&build, &mut artifacts).unwrap();
    fs::create_dir_all(root.join("dist")).unwrap();
    fs::write(root.join("action.yml"), ACTION).unwrap();
    fs::write(root.join("release-manifest.json"), &manifest_bytes).unwrap();
    fs::write(root.join("dist/launcher.js"), &launcher).unwrap();
    fs::write(root.join(&binary_path), &binary).unwrap();
    fs::write(root.join("Cargo.lock"), &lock).unwrap();
    git(root, &["add", "-A"]);
    executable(root, &binary_path);
    git(root, &["commit", "-qm", "mismatched"]);

    let release = Release {
        commit: git(root, &["rev-parse", "HEAD"]).trim().to_owned(),
        tree: git(root, &["rev-parse", "HEAD^{tree}"]).trim().to_owned(),
        dir,
        manifest_digest,
        engine_digest: hb(amiss_bootstrap::ENGINE_DOMAIN, &binary),
        platform,
    };
    let outcome = attempt(&release, BOOTSTRAP);
    assert_eq!(
        outcome.err(),
        Some(Refusal::PlatformBinding),
        "the target comes from the executable header, not the manifest label"
    );
}

/// The execution constraint the required workflow protects pins the exact action
/// commit and the exact tree that commit must carry. The bootstrap resolves the
/// commit and refuses unless its tree is the pinned one, which is what stops a
/// verified workflow from being pointed at a commit whose tree was swapped under
/// it. Two ways to miss: a constraint whose tree OID is not the commit's real
/// tree, and a constraint whose commit OID names no object at all. Both are one
/// refusal, `ActionTree`, because both mean the pinned action is not the action
/// on disk.
#[test]
fn a_constraint_whose_commit_or_tree_does_not_match_refuses_on_the_action_tree() {
    let mut with_wrong_tree = release(|_root| {});
    assert_ne!(
        with_wrong_tree.tree,
        "b".repeat(40),
        "the bogus tree is not the real one"
    );
    with_wrong_tree.tree = "b".repeat(40);
    assert_eq!(
        attempt(&with_wrong_tree, BOOTSTRAP).err(),
        Some(Refusal::ActionTree),
        "the commit is real, but its tree is not the one the constraint pinned"
    );

    let mut with_absent_commit = release(|_root| {});
    with_absent_commit.commit = "c".repeat(40);
    assert_eq!(
        attempt(&with_absent_commit, BOOTSTRAP).err(),
        Some(Refusal::ActionTree),
        "the constraint pins a commit the action repository does not hold"
    );
}

/// The manifest records every build lockfile by path and raw-byte digest, and
/// its parse binds that set to the set digest, so the recorded numbers cannot
/// disagree with each other. What nothing checked until now is the tree: the
/// shipped Cargo.lock could carry any bytes at all, and validation would echo
/// the manifest's story about it. The lockfile is not executed, but it is the
/// one file that says which dependencies built the engine, so a release whose
/// lock bytes drifted from their recorded digest refuses instead of validating.
#[test]
fn a_tampered_lockfile_refuses_on_its_recorded_digest() {
    let release = release(|root| {
        fs::write(
            root.join("Cargo.lock"),
            b"# a different lock\nversion = 4\n",
        )
        .unwrap();
    });
    assert_eq!(
        attempt(&release, BOOTSTRAP).err(),
        Some(Refusal::DependencyLock),
        "the tree's lock bytes do not recompute to the manifest's digest"
    );
}

/// The absent twin: a release tree that dropped the lockfile entirely. The
/// path comes from the manifest, the resolution walks the pinned tree, and an
/// entry that is not there is the same refusal as any other path the closure
/// names and the tree cannot produce.
#[test]
fn a_release_missing_its_lockfile_refuses_on_the_path() {
    let release = release(|root| {
        fs::remove_file(root.join("Cargo.lock")).unwrap();
    });
    assert_eq!(
        attempt(&release, BOOTSTRAP).err(),
        Some(Refusal::PathNotRegularBlob),
        "a lockfile the manifest records and the tree lacks is not a lockfile"
    );
}