fix: generate showcase thumbnails deterministically
Some checks failed
ci / test (macos-latest, 3.10) (push) Has been cancelled
ci / test (macos-latest, 3.12) (push) Has been cancelled
ci / test (ubuntu-latest, 3.10) (push) Has been cancelled
ci / test (ubuntu-latest, 3.12) (push) Has been cancelled
ci / test (windows-latest, 3.10) (push) Has been cancelled
ci / test (windows-latest, 3.12) (push) Has been cancelled
ci / browser-smoke (push) Has been cancelled

This commit is contained in:
2026-07-21 14:53:23 +08:00
parent e0cd974c6b
commit 8cc64f2e58
3 changed files with 26 additions and 3 deletions

View File

@@ -12,6 +12,7 @@ function arg(name, fallback = null) {
const url = arg("--url");
const out = arg("--out", "browser_smoke_report.json");
const shots = arg("--screenshots-dir", "browser_smoke");
const thumbnailOut = arg("--thumbnail-out");
if (!url) {
throw new Error("Usage: web_smoke_test.mjs --url http://127.0.0.1:8188 --out report.json");
}
@@ -24,6 +25,7 @@ try {
}
await fs.mkdir(shots, { recursive: true });
if (thumbnailOut) await fs.mkdir(path.dirname(thumbnailOut), { recursive: true });
const browser = await chromium.launch({ headless: true });
const consoleErrors = [];
const pageErrors = [];
@@ -56,6 +58,18 @@ async function inspect(viewport, name) {
await page.waitForTimeout(1500);
const after = await page.evaluate(() => window.__renders || 0);
checks.push({ name: `${name}:idle-render`, status: after === before ? "PASS" : "FAIL", detail: `${before}->${after}` });
if (name === "desktop" && thumbnailOut) {
// Export the renderer itself. Cropping a page screenshot retains UI panels
// and makes Agents guess at a dark-background crop; the canvas is already
// the canonical customer model view. Zoom out a fixed amount so the white
// model remains a compact subject on the dark exhibit background.
const canvas = page.locator("#scene");
await canvas.hover();
await page.mouse.wheel(0, 1800);
await page.waitForTimeout(500);
const dataUrl = await canvas.evaluate((element) => element.toDataURL("image/png"));
await fs.writeFile(thumbnailOut, Buffer.from(dataUrl.split(",", 2)[1], "base64"));
}
await page.screenshot({ path: path.join(shots, `${name}.png`), fullPage: true });
await page.close();
}