test(artifacts): retire simulated mounts after detach failures

This commit is contained in:
morluto
2026-10-09 04:12:49 +08:00
parent a0784c0d2c
commit f591e37a1e
@@ -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 = { const host: NativeDmgHost = {
run(arguments_) { run(arguments_) {
if (arguments_[0] === "detach") if (arguments_[0] === "detach")
@@ -92,6 +97,8 @@ describe("native DMG artifact reader", () => {
}); });
if (arguments_[0] !== "attach") if (arguments_[0] !== "attach")
return Promise.resolve({ stdout: "", exitCode: 0 }); return Promise.resolve({ stdout: "", exitCode: 0 });
mountRoot = arguments_[arguments_.indexOf("-mountroot") + 1];
if (mountRoot === undefined) throw new Error("missing mount root");
return Promise.resolve({ return Promise.resolve({
stdout: build({ stdout: build({
"system-entities": [ "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 synthesized APFS container separately;
// hdiutil reports the image disk and its synthesized APFS container as two // detaching the container can already eject the image disk.
// whole disks; detaching the container ejects the image disk as well. const apfsHost = (stillListed: readonly string[]) => {
const apfsHost = (stillListed: readonly string[]) => { const calls: string[][] = [];
const calls: string[][] = []; let mountRoot: string | undefined;
const host: NativeDmgHost = { onTestFinished(async () => {
async run(arguments_) { if (mountRoot !== undefined)
calls.push([...arguments_]); await rm(mountRoot, { recursive: true, force: true });
if (arguments_[0] === "detach" && arguments_[1] === "/dev/disk4") });
throw new Error("hdiutil: detach failed - No such file or directory"); const host: NativeDmgHost = {
if (arguments_[0] === "info") async run(arguments_) {
return { calls.push([...arguments_]);
stdout: build({ if (arguments_[0] === "detach" && arguments_[1] === "/dev/disk4")
images: throw new Error("hdiutil: detach failed - No such file or directory");
stillListed.length === 0 if (arguments_[0] === "info")
? []
: [
{
"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);
return { return {
stdout: build({ stdout: build({
"system-entities": [ images:
{ "dev-entry": "/dev/disk4" }, stillListed.length === 0
{ "dev-entry": "/dev/disk4s1" }, ? []
{ "dev-entry": "/dev/disk5s1", "mount-point": mountPoint }, : [
{ "dev-entry": "/dev/disk5" }, {
], "system-entities": stillListed.map((device) => ({
"dev-entry": device,
})),
},
],
}), }),
exitCode: 0, exitCode: 0,
}; };
}, if (arguments_[0] !== "attach") return { stdout: "", exitCode: 0 };
}; mountRoot = arguments_[arguments_.indexOf("-mountroot") + 1];
return { calls, host }; 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 () => { it("accepts an image disk that its container detach already ejected", async () => {
const { calls, host } = apfsHost([]); const { calls, host } = apfsHost([]);
const reader = await NativeDmgArtifactReader.create( const reader = await NativeDmgArtifactReader.create(