diff options
| author | Hermes Agent <hermes@localhost> | 2026-08-12 08:26:30 +0000 |
|---|---|---|
| committer | Hermes Agent <hermes@localhost> | 2026-08-12 08:26:30 +0000 |
| commit | 21ac6ba754296000823869e3f025fbe6225e256f (patch) | |
| tree | 17e0ba6164f191cffc13ccf4720fd43f3d3f67b4 /tests | |
| parent | 9e3259b6fd163903c406b250e18782370e63c517 (diff) | |
Clean partial outputs after manifest write failure
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/build.rs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/build.rs b/tests/build.rs index c9cc59f..c31f0c2 100644 --- a/tests/build.rs +++ b/tests/build.rs @@ -87,6 +87,25 @@ impl InitramfsBuilder for MutatingInitrdBuilder { } } +struct ManifestFailingInitramfsBuilder { + manifest: std::path::PathBuf, +} + +impl InitramfsBuilder for ManifestFailingInitramfsBuilder { + fn build(&mut self, request: &InitramfsRequest) -> anyhow::Result<InitramfsResult> { + fs::write( + request + .rootfs() + .join(format!("boot/initrd-{}.img", request.kernel().as_str())), + "initrd", + )?; + let parent = self.manifest.parent().expect("manifest parent"); + fs::create_dir_all(parent)?; + fs::create_dir(&self.manifest)?; + InitramfsResult::from_rootfs(request.rootfs(), request.kernel()) + } +} + #[derive(Default)] struct FixtureInitramfsBuilder; @@ -404,3 +423,38 @@ fn removes_the_new_workspace_and_artifact_when_manifest_collection_fails() { "failed manifest collection must not leave a companion manifest" ); } + +#[test] +fn removes_the_partial_artifact_when_manifest_writing_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 workspace = fixture.path().join("work"); + let artifact = fixture.path().join("out/image.tar"); + let manifest = ArtifactManifest::path_beside(&artifact).expect("manifest path"); + let mut executor = BuildExecutor::new( + FixtureInstaller::default(), + ManifestFailingInitramfsBuilder { + manifest: manifest.clone(), + }, + ); + + let error = executor + .execute(&plan, &workspace, "profiles/apt.conf", &artifact) + .expect_err("manifest write failure must fail the build"); + + assert!(error.to_string().contains("create artifact manifest")); + assert!( + !workspace.exists(), + "failed build must not leave a workspace" + ); + assert!( + !artifact.exists(), + "failed build must not leave an artifact" + ); + assert!( + !manifest.exists(), + "failed build must remove a manifest path created during execution" + ); +} |