fix(artifacts): classify changed admission as integrity failure

This commit is contained in:
64579525
2026-10-13 16:07:11 +08:00
parent 577d6c3e9b
commit 96608517ba
3 changed files with 24 additions and 5 deletions
@@ -35,11 +35,17 @@ export const openRootArtifact = async (
const changed =
admission === "inventoried" &&
(primary instanceof NonRegularFileReadError ||
primary instanceof RegularFileChangedError ||
(primary instanceof Error &&
"code" in primary &&
["ENOENT", "ENOTDIR", "ELOOP", "EISDIR", "ENOTFILE"].includes(
String(primary.code),
)));
[
"ENOENT",
"ENOTDIR",
"ELOOP",
"EISDIR",
"ENOTFILE",
"ESTALE",
].includes(String(primary.code))));
// Normalize the primary failure before cleanup so failed closes keep both facts.
const failure =
signal?.aborted === true
+1 -1
View File
@@ -62,7 +62,7 @@ const largeUniversalTarget = async (
bytes.writeUInt32BE(cpu, entry);
bytes.writeUInt32BE(offset, entry + 8);
bytes.writeUInt32BE(size, entry + 12);
bytes.writeUInt32BE(14, entry + 16);
bytes.writeUInt32BE(12, entry + 16);
bytes.fill(0x11 * (index + 1), offset, offset + size);
thinMach(0xfeedfacf, cpu).copy(bytes, offset);
});
+14 -1
View File
@@ -496,7 +496,14 @@ it.each(["removed", "directory", "malformed"])(
},
);
it.each(["EISDIR", "ENOTFILE", "EACCES", "cancelled"])(
it.each([
"EISDIR",
"ENOTFILE",
"ESTALE",
"EACCES",
"cancelled",
...(process.platform === "win32" ? ["changed metadata"] : []),
])(
"preserves the %s admission meaning while reopening extraction",
async (code) => {
const root = await createTestTempDirectory("rea-ines-reopen-error-");
@@ -514,6 +521,12 @@ it.each(["EISDIR", "ENOTFILE", "EACCES", "cancelled"])(
const stat = vi
.spyOn(prototype, "stat")
.mockImplementationOnce(async function (this: FileHandle, ...args) {
if (code === "changed metadata") {
const metadata = await originalStat.call(this, ...args);
// Change the real file between descriptor stat and admission lstat.
await writeFile(path, "replacement cartridge");
return metadata;
}
if (code !== "cancelled")
throw Object.assign(new Error("injected admission failure"), {
code,