From 0ca2b1ae9e72a9b9cae88e18e526a5fb129c880f Mon Sep 17 00:00:00 2001 From: Luke Johnson <142949311+LukeTheoJohnson@users.noreply.github.com> Date: Mon, 9 Nov 2026 17:54:13 +0000 Subject: [PATCH] fix(cli): label SVG contact sheet thumbnails by file name on Windows (#6732) createSvgContactSheet built each path with path.join and then took the label with split("/"), so on Windows the label was the whole path and the 60-character cell limit cut the file name off. Use basename, as the scroll and snapshot sheets in the same file already do. --- packages/cli/src/capture/contactSheet.test.ts | 33 +++++++++++++++++-- packages/cli/src/capture/contactSheet.ts | 2 +- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/capture/contactSheet.test.ts b/packages/cli/src/capture/contactSheet.test.ts index 2a1db0cb6d..fd27ddc078 100644 --- a/packages/cli/src/capture/contactSheet.test.ts +++ b/packages/cli/src/capture/contactSheet.test.ts @@ -1,6 +1,7 @@ import { existsSync, lstatSync, + mkdirSync, mkdtempSync, readFileSync, rmSync, @@ -9,14 +10,15 @@ import { } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; -import sharp from "sharp"; -import { describe, expect, it } from "vitest"; +import sharp, { type Sharp } from "sharp"; +import { describe, expect, it, vi } from "vitest"; import { createContactSheet, createAssetContactSheet, createScrollContactSheet, createSvgContactSheet, } from "./contactSheet.js"; +import { loadSharp } from "../utils/optionalPackages.js"; function tempDir(): string { return mkdtempSync(join(tmpdir(), "hf-contact-sheet-test-")); @@ -310,4 +312,31 @@ describe("contact-sheet capture budget", () => { rmSync(dir, { recursive: true, force: true }); } }, 60_000); + + it("labels each SVG thumbnail with its file name", async () => { + const dir = tempDir(); + const runtimeSharp = await loadSharp("contact sheets"); + const sharpProto: Sharp = Object.getPrototypeOf( + runtimeSharp({ create: { width: 1, height: 1, channels: 3, background: "#000" } }), + ); + const composite = vi.spyOn(sharpProto, "composite"); + try { + const svgs = join(dir, "svgs"); + mkdirSync(svgs); + writeFileSync( + join(svgs, "logo-mark.svg"), + '', + ); + + await createSvgContactSheet(svgs, join(dir, "svg-contact-sheet.png")); + + const labelSvgs = composite.mock.calls + .flatMap(([overlays]) => overlays ?? []) + .map((overlay) => (Buffer.isBuffer(overlay.input) ? overlay.input.toString() : "")); + expect(labelSvgs.some((svg) => svg.includes(">1. logo-mark"))).toBe(true); + } finally { + composite.mockRestore(); + rmSync(dir, { recursive: true, force: true }); + } + }, 60_000); }); diff --git a/packages/cli/src/capture/contactSheet.ts b/packages/cli/src/capture/contactSheet.ts index f2f3cc1733..57e2a01279 100644 --- a/packages/cli/src/capture/contactSheet.ts +++ b/packages/cli/src/capture/contactSheet.ts @@ -304,7 +304,7 @@ export async function createSvgContactSheet( if (svgPaths.length === 0) return []; const sharp = await loadSharp("contact sheets"); - const svgFileNames = svgPaths.map((p) => p.split("/").pop()!); + const svgFileNames = svgPaths.map((p) => basename(p)); // Render ALL SVGs to PNG thumbnails first, then paginate the sheets const thumbSize = 200;