From b9d43cb9d3dc4becec598ec83614c3561d7fc771 Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Wed, 12 Aug 2026 07:58:08 +0000 Subject: Clean workspace when native packaging fails --- tests/build.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'tests/build.rs') diff --git a/tests/build.rs b/tests/build.rs index 7d67b29..2fcd1bf 100644 --- a/tests/build.rs +++ b/tests/build.rs @@ -59,6 +59,20 @@ impl InitramfsBuilder for FailingInitramfsBuilder { } } +struct ArchiveFailingInstaller; + +impl PackageInstaller for ArchiveFailingInstaller { + fn install(&self, request: &PackageRequest) -> anyhow::Result<()> { + let rootfs = request.workdir().join("chroot"); + fs::create_dir_all(rootfs.join("boot"))?; + fs::write(rootfs.join("boot/vmlinuz-6.12.0-rt1"), "kernel")?; + std::os::unix::net::UnixListener::bind(rootfs.join("unsupported.socket")) + .expect("create unsupported socket fixture") + .set_nonblocking(true)?; + Ok(()) + } +} + #[derive(Default)] struct FixtureInitramfsBuilder; @@ -310,3 +324,34 @@ fn removes_the_new_workspace_when_initramfs_build_fails() { ); assert!(!artifact.exists()); } + +#[test] +fn removes_the_new_workspace_and_partial_artifact_when_packaging_fails() { + let fixture = tempdir().expect("fixture directory"); + let spec = ImageSpec::load(std::path::Path::new("profiles/alt-controller.toml")) + .expect("load controller spec"); + let plan = BuildPlan::compile(spec).expect("compile build plan"); + let mut executor = BuildExecutor::new(ArchiveFailingInstaller, FixtureInitramfsBuilder); + let workspace = fixture.path().join("work"); + let artifact = fixture.path().join("out/image.tar"); + + let error = executor + .execute(&plan, &workspace, "profiles/apt.conf", &artifact) + .expect_err("unsupported rootfs entry must fail packaging"); + + assert!(error.to_string().contains("unsupported rootfs entry type")); + assert!( + !workspace.exists(), + "failed build must not leave a workspace" + ); + assert!( + !artifact.exists(), + "failed packaging must not leave an artifact" + ); + assert!( + !ArtifactManifest::path_beside(&artifact) + .expect("manifest path") + .exists(), + "failed packaging must not leave a companion manifest" + ); +} -- cgit v1.2.3