Skip to content

Commit 34e488c

Browse files
DeRaowlclaude
andcommitted
fix(percy): clone all widths/devices/browsers, not just first comparison
Download every comparison screenshot per snapshot — each width, device, and browser combo gets its own file named {snapshot}_{browser}_{width}px. Previously only downloaded the first comparison per snapshot. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent bfa9163 commit 34e488c

1 file changed

Lines changed: 42 additions & 28 deletions

File tree

src/tools/percy-mcp/v2/clone-build.ts

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -467,35 +467,42 @@ async function uploadScreenshots(
467467
// Step 1: Create temp directory for screenshots
468468
const tmpDir = await mkdtemp(join(tmpdir(), "percy-clone-"));
469469
let downloaded = 0;
470+
let totalComps = 0;
470471

471-
// Step 2: Download screenshots — use first comparison per snapshot (primary width)
472+
// Step 2: Download ALL screenshots — every width/device/browser per snapshot
472473
for (const snap of snapshots) {
473-
const comp = snap.comparisons.find((c) => c.imageUrl);
474-
if (!comp?.imageUrl) continue;
475-
476-
try {
477-
const imgResponse = await fetch(comp.imageUrl);
478-
if (!imgResponse.ok) continue;
479-
480-
const imgBuffer = Buffer.from(await imgResponse.arrayBuffer());
481-
482-
// Name file after snapshot — sanitize for filesystem
483-
const safeName = snap.name
484-
.replace(/[/\\?%*:|"<>]/g, "-")
485-
.replace(/\s+/g, "_")
486-
.slice(0, 200);
487-
const ext =
488-
comp.imageUrl.includes(".jpg") || comp.imageUrl.includes("jpeg")
489-
? ".jpg"
490-
: ".png";
491-
await writeFile(join(tmpDir, `${safeName}${ext}`), imgBuffer);
492-
downloaded++;
493-
} catch {
494-
output += `- Failed to download: ${snap.name}\n`;
474+
const compsWithImages = snap.comparisons.filter((c) => c.imageUrl);
475+
if (compsWithImages.length === 0) continue;
476+
totalComps += compsWithImages.length;
477+
478+
for (const comp of compsWithImages) {
479+
try {
480+
const imgResponse = await fetch(comp.imageUrl!);
481+
if (!imgResponse.ok) continue;
482+
483+
const imgBuffer = Buffer.from(await imgResponse.arrayBuffer());
484+
485+
// Name: {snapshot}_{browser}_{width}px — preserves all width/device combos
486+
const safeName = snap.name
487+
.replace(/[/\\?%*:|"<>]/g, "-")
488+
.replace(/\s+/g, "_")
489+
.slice(0, 150);
490+
const devicePart = comp.browserName || comp.tagName || "default";
491+
const safeDevice = devicePart.replace(/[/\\?%*:|"<>]/g, "-");
492+
const fileName = `${safeName}_${safeDevice}_${comp.width}px`;
493+
const ext =
494+
comp.imageUrl!.includes(".jpg") || comp.imageUrl!.includes("jpeg")
495+
? ".jpg"
496+
: ".png";
497+
await writeFile(join(tmpDir, `${fileName}${ext}`), imgBuffer);
498+
downloaded++;
499+
} catch {
500+
output += `- Failed to download: ${snap.name} (${comp.browserName} ${comp.width}px)\n`;
501+
}
495502
}
496503
}
497504

498-
output += `Downloaded **${downloaded}/${snapshots.length}** screenshots.\n\n`;
505+
output += `Downloaded **${downloaded}/${totalComps}** screenshots across ${snapshots.length} snapshots.\n\n`;
499506

500507
if (downloaded === 0) {
501508
output += `No screenshots to upload.\n`;
@@ -573,11 +580,18 @@ async function uploadScreenshots(
573580
output += `\n**Percy output:**\n\`\`\`\n${percyLines.join("\n")}\n\`\`\`\n`;
574581
}
575582

576-
// List cloned snapshots
577-
output += `\n**Snapshots:**\n`;
583+
// List cloned snapshots with all their width/device combos
584+
output += `\n**Snapshots cloned:**\n`;
578585
for (const snap of snapshots) {
579-
const hasImage = snap.comparisons.some((c) => c.imageUrl);
580-
output += `- ${hasImage ? "+" : "-"} ${snap.name}\n`;
586+
const comps = snap.comparisons.filter((c) => c.imageUrl);
587+
if (comps.length === 0) {
588+
output += `- ${snap.name} — no screenshots\n`;
589+
} else {
590+
const details = comps
591+
.map((c) => `${c.browserName || c.tagName} ${c.width}px`)
592+
.join(", ");
593+
output += `- **${snap.name}** — ${comps.length} variant${comps.length !== 1 ? "s" : ""} (${details})\n`;
594+
}
581595
}
582596

583597
return { content: [{ type: "text", text: output }] };

0 commit comments

Comments
 (0)