From f591e37a1e45d9b7179ed788c4e7ee77a708c6b0 Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Fri, 9 Oct 2026 04:03:54 +0800 Subject: [PATCH] test(artifacts): retire simulated mounts after detach failures --- .../native/nativeDmgArtifactReader.test.ts | 92 +++++++++++-------- 1 file changed, 52 insertions(+), 40 deletions(-) diff --git a/tests/boundary/providers/native/nativeDmgArtifactReader.test.ts b/tests/boundary/providers/native/nativeDmgArtifactReader.test.ts index 6de633813..8b0df2730 100644 --- a/tests/boundary/providers/native/nativeDmgArtifactReader.test.ts +++ b/tests/boundary/providers/native/nativeDmgArtifactReader.test.ts @@ -77,6 +77,11 @@ describe("native DMG artifact reader", () => { ), }); + let mountRoot: string | undefined; + onTestFinished(async () => { + if (mountRoot !== undefined) + await rm(mountRoot, { recursive: true, force: true }); + }); const host: NativeDmgHost = { run(arguments_) { if (arguments_[0] === "detach") @@ -92,6 +97,8 @@ describe("native DMG artifact reader", () => { }); if (arguments_[0] !== "attach") return Promise.resolve({ stdout: "", exitCode: 0 }); + mountRoot = arguments_[arguments_.indexOf("-mountroot") + 1]; + if (mountRoot === undefined) throw new Error("missing mount root"); return Promise.resolve({ stdout: build({ "system-entities": [ @@ -387,53 +394,58 @@ it("owns the canonical mount root and detaches each observed whole image once", ]); }); -describe("APFS disk image detach", () => { - // hdiutil reports the image disk and its synthesized APFS container as two - // whole disks; detaching the container ejects the image disk as well. - const apfsHost = (stillListed: readonly string[]) => { - const calls: string[][] = []; - const host: NativeDmgHost = { - async run(arguments_) { - calls.push([...arguments_]); - if (arguments_[0] === "detach" && arguments_[1] === "/dev/disk4") - throw new Error("hdiutil: detach failed - No such file or directory"); - if (arguments_[0] === "info") - return { - stdout: build({ - images: - stillListed.length === 0 - ? [] - : [ - { - "system-entities": stillListed.map((device) => ({ - "dev-entry": device, - })), - }, - ], - }), - exitCode: 0, - }; - if (arguments_[0] !== "attach") return { stdout: "", exitCode: 0 }; - const mountRoot = arguments_[arguments_.indexOf("-mountroot") + 1]; - if (mountRoot === undefined) throw new Error("missing mount root"); - const mountPoint = join(mountRoot, "Fixture"); - await mkdir(mountPoint); +// hdiutil reports the image disk and synthesized APFS container separately; +// detaching the container can already eject the image disk. +const apfsHost = (stillListed: readonly string[]) => { + const calls: string[][] = []; + let mountRoot: string | undefined; + onTestFinished(async () => { + if (mountRoot !== undefined) + await rm(mountRoot, { recursive: true, force: true }); + }); + const host: NativeDmgHost = { + async run(arguments_) { + calls.push([...arguments_]); + if (arguments_[0] === "detach" && arguments_[1] === "/dev/disk4") + throw new Error("hdiutil: detach failed - No such file or directory"); + if (arguments_[0] === "info") return { stdout: build({ - "system-entities": [ - { "dev-entry": "/dev/disk4" }, - { "dev-entry": "/dev/disk4s1" }, - { "dev-entry": "/dev/disk5s1", "mount-point": mountPoint }, - { "dev-entry": "/dev/disk5" }, - ], + images: + stillListed.length === 0 + ? [] + : [ + { + "system-entities": stillListed.map((device) => ({ + "dev-entry": device, + })), + }, + ], }), exitCode: 0, }; - }, - }; - return { calls, host }; + if (arguments_[0] !== "attach") return { stdout: "", exitCode: 0 }; + mountRoot = arguments_[arguments_.indexOf("-mountroot") + 1]; + if (mountRoot === undefined) throw new Error("missing mount root"); + const mountPoint = join(mountRoot, "Fixture"); + await mkdir(mountPoint); + return { + stdout: build({ + "system-entities": [ + { "dev-entry": "/dev/disk4" }, + { "dev-entry": "/dev/disk4s1" }, + { "dev-entry": "/dev/disk5s1", "mount-point": mountPoint }, + { "dev-entry": "/dev/disk5" }, + ], + }), + exitCode: 0, + }; + }, }; + return { calls, host }; +}; +describe("APFS disk image detach", () => { it("accepts an image disk that its container detach already ejected", async () => { const { calls, host } = apfsHost([]); const reader = await NativeDmgArtifactReader.create(