diff --git a/tests/boundary/filesystem/safeOutputTree.test.ts b/tests/boundary/filesystem/safeOutputTree.test.ts index dbe06dcde4..88c68072f6 100644 --- a/tests/boundary/filesystem/safeOutputTree.test.ts +++ b/tests/boundary/filesystem/safeOutputTree.test.ts @@ -39,30 +39,24 @@ describe("safe artifact output cleanup", () => { expect(await readdir(output)).toEqual([]); await tree.closeHandles(); }); - it.skipIf(process.platform !== "linux")( - "closes the parent descriptor when the output disappears before commit", - async () => { - const parent = await createTestTempDirectory("rea-safe-output-"); - const output = join(parent, "published"); - const tree = await SafeOutputTree.create(output); - await rm(output, { recursive: true }); - await expect(tree.commit()).rejects.toThrow(); - const targets = await Promise.all( - (await readdir("/proc/self/fd")).map((fd) => - readlink(`/proc/self/fd/${fd}`).catch(() => undefined), - ), - ); - expect(targets.filter((target) => target === parent)).toEqual([]); - const failure = await tree.rollback().catch((cause: unknown) => cause); - expect(failure).toBeInstanceOf(ArtifactReaderFailure); - expect(failure).toMatchObject({ cleanup: { resources: [output] } }); - expect(tree.cleanup).toEqual({ - status: "incomplete", - residualPaths: ["published"], - }); - await rm(parent, { recursive: true, force: true }); - }, - ); + it("keeps cleanup incomplete when the owned root disappears before commit", async () => { + const parent = await createTestTempDirectory("rea-safe-output-"); + const output = join(parent, "published"); + const tree = await SafeOutputTree.create(output); + await rm(output, { recursive: true }); + + await expect(tree.commit()).rejects.toMatchObject({ code: "ENOENT" }); + await expect(tree.rollback()).rejects.toMatchObject({ + reason: "integrity", + integrityCheck: "output-lifecycle", + cause: { code: "ENOENT" }, + cleanup: { resources: [output] }, + }); + expect(tree.cleanup).toEqual({ + status: "incomplete", + residualPaths: ["published"], + }); + }); }); describe("safe artifact output file identity admission", () => { diff --git a/tests/boundary/filesystem/safeOutputTreeCloseFailures.test.ts b/tests/boundary/filesystem/safeOutputTreeCloseFailures.test.ts index 8f3bf359b7..12377545e2 100644 --- a/tests/boundary/filesystem/safeOutputTreeCloseFailures.test.ts +++ b/tests/boundary/filesystem/safeOutputTreeCloseFailures.test.ts @@ -19,8 +19,9 @@ const injectedFilesystemFailures = vi.hoisted(() => ({ | undefined, blockCloseRetries: false, chmodNext: false, - syncAbortAfter: undefined as AbortController | undefined, - syncCount: 0, + parentSync: undefined as + | { path: string; controller: AbortController; handle?: FileHandle } + | undefined, rootIdentityPath: undefined as string | undefined, })); @@ -56,13 +57,13 @@ vi.mock("node:fs/promises", async (importOriginal) => { await close(); }; } - if (injectedFilesystemFailures.syncAbortAfter !== undefined) { + const parentSync = injectedFilesystemFailures.parentSync; + if (parentSync !== undefined && args[0] === parentSync.path) { const sync = handle.sync.bind(handle); handle.sync = async () => { await sync(); - injectedFilesystemFailures.syncCount += 1; - if (injectedFilesystemFailures.syncCount === 2) - injectedFilesystemFailures.syncAbortAfter?.abort(); + parentSync.handle = handle; + parentSync.controller.abort(); }; } return handle; @@ -124,7 +125,7 @@ describe("safe artifact output close failures", () => { ); it.skipIf(process.platform === "win32")( - "keeps the tree unpublished when cancellation arrives during commit durability", + "closes the parent descriptor and keeps output unpublished after cancellation during durability", async () => { const parent = await createTestTempDirectory("rea-safe-output-cancel-"); const output = join(parent, "unpublished"); @@ -134,19 +135,23 @@ describe("safe artifact output close failures", () => { sha256: createHash("sha256").update(bytes).digest("hex"), bytes: bytes.byteLength, }); - const controller = new AbortController(); - injectedFilesystemFailures.syncCount = 0; - injectedFilesystemFailures.syncAbortAfter = controller; + const parentSync: NonNullable< + typeof injectedFilesystemFailures.parentSync + > = { path: parent, controller: new AbortController() }; + injectedFilesystemFailures.parentSync = parentSync; try { - await expect(tree.commit(controller.signal)).rejects.toMatchObject({ + await expect( + tree.commit(parentSync.controller.signal), + ).rejects.toMatchObject({ reason: "cancelled", }); + expect(parentSync.handle?.fd).toBe(-1); expect(tree.published).toBe(false); } finally { - injectedFilesystemFailures.syncAbortAfter = undefined; - injectedFilesystemFailures.syncCount = 0; + injectedFilesystemFailures.parentSync = undefined; + await tree.rollback(); } - expect(await tree.rollback()).toMatchObject({ status: "complete" }); + expect(tree.cleanup).toMatchObject({ status: "complete" }); await expect(access(output)).rejects.toMatchObject({ code: "ENOENT" }); }, );