From 555a4d896c909cb8f42cc64fb323f2cdbbfa9d40 Mon Sep 17 00:00:00 2001 From: Shakker Date: Mon, 30 Mar 2026 16:43:11 +0100 Subject: [PATCH] test: stabilize media attachment cache path assertions --- .../media-understanding-misc.test.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/media-understanding/media-understanding-misc.test.ts b/src/media-understanding/media-understanding-misc.test.ts index 4b02099b546..5dc06b17420 100644 --- a/src/media-understanding/media-understanding-misc.test.ts +++ b/src/media-understanding/media-understanding-misc.test.ts @@ -125,6 +125,7 @@ describe("media understanding attachments SSRF", () => { const attachmentPath = path.join(allowedRoot, "voice-note.m4a"); await fs.mkdir(allowedRoot, { recursive: true }); await fs.writeFile(attachmentPath, "ok"); + const canonicalAttachmentPath = await fs.realpath(attachmentPath).catch(() => attachmentPath); const cache = new MediaAttachmentCache([{ index: 0, path: attachmentPath }], { localPathRoots: [allowedRoot], @@ -134,7 +135,9 @@ describe("media understanding attachments SSRF", () => { openSpy.mockImplementation(async (filePath, flags) => { const handle = await originalOpen(filePath, flags); - if (filePath !== attachmentPath) { + const candidatePath = + (await fs.realpath(String(filePath)).catch(() => String(filePath))) ?? String(filePath); + if (candidatePath !== canonicalAttachmentPath) { return handle; } const mockedHandle = handle as typeof handle & { @@ -159,6 +162,7 @@ describe("media understanding attachments SSRF", () => { const attachmentPath = path.join(allowedRoot, "voice-note.m4a"); await fs.mkdir(allowedRoot, { recursive: true }); await fs.writeFile(attachmentPath, "ok"); + const canonicalAttachmentPath = await fs.realpath(attachmentPath).catch(() => attachmentPath); const cache = new MediaAttachmentCache([{ index: 0, path: attachmentPath }], { localPathRoots: [allowedRoot], @@ -167,10 +171,12 @@ describe("media understanding attachments SSRF", () => { await cache.getBuffer({ attachmentIndex: 0, maxBytes: 1024, timeoutMs: 1000 }); - expect(openSpy).toHaveBeenCalledWith( - attachmentPath, - fsConstants.O_RDONLY | fsConstants.O_NOFOLLOW, + expect(openSpy).toHaveBeenCalled(); + const [openedPath, openedFlags] = openSpy.mock.calls[0] ?? []; + expect(await fs.realpath(String(openedPath)).catch(() => String(openedPath))).toBe( + canonicalAttachmentPath, ); + expect(openedFlags).toBe(fsConstants.O_RDONLY | fsConstants.O_NOFOLLOW); }); }); });