fix(artifacts): retain failed DMG cleanup state and diagnostics (#1103)
This commit is contained in:
@@ -1,8 +1,15 @@
|
||||
import { chmod, mkdir, readFile, realpath, writeFile } from "node:fs/promises";
|
||||
import {
|
||||
chmod,
|
||||
mkdir,
|
||||
readFile,
|
||||
realpath,
|
||||
rm,
|
||||
writeFile,
|
||||
} from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { build } from "plist";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { describe, expect, it, onTestFinished } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "../../../fixtures/temporaryDirectory.js";
|
||||
import { execFileOutput } from "../../../../src/process/ExecFileOutput.js";
|
||||
@@ -456,8 +463,81 @@ describe("APFS disk image detach", () => {
|
||||
undefined,
|
||||
host,
|
||||
);
|
||||
await expect(reader.close()).rejects.toThrow(
|
||||
"DMG detach or mount-root cleanup failed",
|
||||
await expect(reader.close()).rejects.toMatchObject({
|
||||
reason: "unavailable",
|
||||
message: expect.stringContaining("No such file or directory"),
|
||||
});
|
||||
});
|
||||
|
||||
it("retains a failed attachment and its mount root until a later close detaches it", async () => {
|
||||
let mountRoot: string | undefined;
|
||||
let busy = true;
|
||||
let attached = true;
|
||||
onTestFinished(async () => {
|
||||
if (mountRoot !== undefined)
|
||||
await rm(mountRoot, { recursive: true, force: true });
|
||||
});
|
||||
const host: NativeDmgHost = {
|
||||
async run(args) {
|
||||
if (args[0] === "attach") {
|
||||
mountRoot = args[args.indexOf("-mountroot") + 1];
|
||||
if (mountRoot === undefined) throw new Error("missing mount root");
|
||||
const mountPoint = join(mountRoot, "Fixture");
|
||||
await mkdir(mountPoint);
|
||||
await writeFile(join(mountPoint, "hello.txt"), "owned observation");
|
||||
return {
|
||||
stdout: build({
|
||||
"system-entities": [
|
||||
{ "dev-entry": "/dev/disk7", "mount-point": mountPoint },
|
||||
],
|
||||
}),
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
if (args[0] === "info")
|
||||
return {
|
||||
stdout: build({
|
||||
images: attached
|
||||
? [{ "system-entities": [{ "dev-entry": "/dev/disk7" }] }]
|
||||
: [],
|
||||
}),
|
||||
exitCode: 0,
|
||||
};
|
||||
if (args[0] === "detach") {
|
||||
if (busy)
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: "hdiutil: detach failed - Resource busy",
|
||||
exitCode: 16,
|
||||
};
|
||||
attached = false;
|
||||
}
|
||||
return { stdout: "", exitCode: 0 };
|
||||
},
|
||||
};
|
||||
const reader = await NativeDmgArtifactReader.create(
|
||||
"/tmp/image.dmg",
|
||||
undefined,
|
||||
host,
|
||||
);
|
||||
await expect(reader.close()).rejects.toMatchObject({
|
||||
reason: "unavailable",
|
||||
});
|
||||
if (mountRoot === undefined) throw new Error("missing owned mount root");
|
||||
expect
|
||||
.soft(
|
||||
await readFile(join(mountRoot, "Fixture", "hello.txt"), "utf8").catch(
|
||||
() => undefined,
|
||||
),
|
||||
)
|
||||
.toBe("owned observation");
|
||||
busy = false;
|
||||
await reader.close();
|
||||
expect.soft(attached).toBe(false);
|
||||
await expect(
|
||||
readFile(join(mountRoot, "Fixture", "hello.txt")),
|
||||
).rejects.toMatchObject({
|
||||
code: "ENOENT",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user