fix(artifacts): retain ASAR resources through cleanup failures

Give snapshot capture, header admission, packed members, and container streams one file-handle owner. Serialize adoption with reader shutdown, retain failed closes for retry, and remove snapshots only after descriptor cleanup succeeds.

Cover unread members, pending opens, zero-byte members, and paired format/cleanup failures. Keep intentionally unrecoverable test fixtures hygienic and strengthen managed identity and process cleanup-authority expectations.

Validation: full npm run check; 99 targeted tests and temporary-directory hygiene; exact discovery of 877 test files. No real vendor-provider verification was performed.
This commit is contained in:
morluto
2026-10-12 05:05:21 +08:00
parent 290d301ec7
commit eb97da3388
7 changed files with 670 additions and 222 deletions
@@ -182,15 +182,13 @@ describe("ASAR snapshot operation ownership", () => {
const removalStartedPromise = new Promise<void>((resolve) => {
removalStarted = resolve;
});
const reader = new AsarArtifactReader(
fixture.archive,
undefined,
async (path) => {
const reader = new AsarArtifactReader(fixture.archive, {
removeSnapshot: async (path) => {
removalStarted?.();
await removalGate;
await rm(path, { recursive: true, force: true });
},
);
});
let prepared = false;
const preparing = reader.prepareContainer().then(() => {
prepared = true;
@@ -302,15 +300,13 @@ describe("ASAR captured-byte identity", () => {
it("retains a completed inventory and snapshot ownership when cleanup fails", async () => {
const fixture = await archiveFixture();
const attempts: string[] = [];
const reader = new AsarArtifactReader(
fixture.archive,
undefined,
async (path) => {
const reader = new AsarArtifactReader(fixture.archive, {
removeSnapshot: async (path) => {
attempts.push(path);
if (attempts.length === 1) throw new Error("snapshot removal denied");
await rm(path, { recursive: true, force: true });
},
);
});
const resourceScope = new ArtifactResourceScope();
onTestFinished(() => resourceScope.close());
try {