diff --git a/src/agents/apply-patch.test.ts b/src/agents/apply-patch.test.ts index 0eb63d8fdb4..363c20aa3f2 100644 --- a/src/agents/apply-patch.test.ts +++ b/src/agents/apply-patch.test.ts @@ -84,7 +84,17 @@ async function expectOutsideWriteRejected(params: { }) { const patch = buildAddFilePatch(params.patchTargetPath); await expect(applyPatch(patch, { cwd: params.dir })).rejects.toThrow(/Path escapes sandbox root/); - await expect(fs.readFile(params.outsidePath, "utf8")).rejects.toMatchObject({ code: "ENOENT" }); + await expectMissingPath(fs.readFile(params.outsidePath, "utf8")); +} + +async function expectMissingPath(operation: Promise) { + let error: NodeJS.ErrnoException | undefined; + try { + await operation; + } catch (caught) { + error = caught as NodeJS.ErrnoException; + } + expect(error?.code).toBe("ENOENT"); } describe("applyPatch", () => { @@ -232,7 +242,7 @@ describe("applyPatch", () => { await expect(applyPatch(patch, { cwd: dir })).rejects.toThrow( /Symlink escapes sandbox root/, ); - await expect(fs.readFile(outsideFile, "utf8")).rejects.toMatchObject({ code: "ENOENT" }); + await expectMissingPath(fs.readFile(outsideFile, "utf8")); } finally { await fs.rm(outsideDir, { recursive: true, force: true }); } @@ -376,7 +386,7 @@ describe("applyPatch", () => { const result = await applyPatch(patch, { cwd: dir }); expect(result.summary.deleted).toEqual(["link"]); - await expect(fs.lstat(linkDir)).rejects.toMatchObject({ code: "ENOENT" }); + await expectMissingPath(fs.lstat(linkDir)); const outsideContents = await fs.readFile(outsideTarget, "utf8"); expect(outsideContents).toBe("keep\n"); } finally { @@ -456,9 +466,7 @@ describe("applyPatch", () => { ); }, }); - await expect(fs.stat(path.join(outside, "nested"))).rejects.toMatchObject({ - code: "ENOENT", - }); + await expectMissingPath(fs.stat(path.join(outside, "nested"))); } finally { await fs.rm(outside, { recursive: true, force: true }); }