From 6fd31fc0b08ff1b0d074093b57b5ef62d865d0cf Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 21 Feb 2026 19:39:41 +0000 Subject: [PATCH] test(browser): dedupe invalid-path assertions and cover blank path rejection --- src/browser/paths.test.ts | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/src/browser/paths.test.ts b/src/browser/paths.test.ts index 6719961d6..03f88a8a1 100644 --- a/src/browser/paths.test.ts +++ b/src/browser/paths.test.ts @@ -23,6 +23,16 @@ async function withFixtureRoot( } describe("resolveExistingPathsWithinRoot", () => { + function expectInvalidResult( + result: Awaited>, + expectedSnippet: string, + ) { + expect(result.ok).toBe(false); + if (!result.ok) { + expect(result.error).toContain(expectedSnippet); + } + } + it("accepts existing files under the upload root", async () => { await withFixtureRoot(async ({ uploadsDir }) => { const nestedDir = path.join(uploadsDir, "nested"); @@ -54,10 +64,19 @@ describe("resolveExistingPathsWithinRoot", () => { scopeLabel: "uploads directory", }); - expect(result.ok).toBe(false); - if (!result.ok) { - expect(result.error).toContain("must stay within uploads directory"); - } + expectInvalidResult(result, "must stay within uploads directory"); + }); + }); + + it("rejects blank paths", async () => { + await withFixtureRoot(async ({ uploadsDir }) => { + const result = await resolveExistingPathsWithinRoot({ + rootDir: uploadsDir, + requestedPaths: [" "], + scopeLabel: "uploads directory", + }); + + expectInvalidResult(result, "path is required"); }); }); @@ -87,10 +106,7 @@ describe("resolveExistingPathsWithinRoot", () => { scopeLabel: "uploads directory", }); - expect(result.ok).toBe(false); - if (!result.ok) { - expect(result.error).toContain("regular non-symlink file"); - } + expectInvalidResult(result, "regular non-symlink file"); }); }); @@ -109,10 +125,7 @@ describe("resolveExistingPathsWithinRoot", () => { scopeLabel: "uploads directory", }); - expect(result.ok).toBe(false); - if (!result.ok) { - expect(result.error).toContain("regular non-symlink file"); - } + expectInvalidResult(result, "regular non-symlink file"); }); }, );