From 8cc64f2e58ae1173751b319a16e6a593349815ec Mon Sep 17 00:00:00 2001 From: zhengwr Date: Tue, 21 Jul 2026 14:53:23 +0800 Subject: [PATCH] fix: generate showcase thumbnails deterministically --- SKILL.md | 1 + scripts/cad_showcase.py | 14 +++++++++++--- scripts/web_smoke_test.mjs | 14 ++++++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/SKILL.md b/SKILL.md index c5ae064..9669155 100644 --- a/SKILL.md +++ b/SKILL.md @@ -74,6 +74,7 @@ Read only the branches needed for the current task: - Require `verify_showcase.py --strict` and `verify_delivery.py` to pass. - Inspect at least one iso/front/side/plan render personally. - For served Web output, use `cad_showcase.py run --web`; it Draco-compresses Trimesh GLBs, starts a temporary local server, runs `web_smoke_test.mjs` at real 1440×900 and 390×844 viewports, and feeds the report to final verification automatically. + - Use the `thumbnail.png` emitted by the Web smoke. It is exported directly from the WebGL canvas with the canonical camera; do not manually crop the browser screenshot or iterate on UI-free framing. - For `--offline`, the pipeline embeds the retained uncompressed `standard.raw.glb`, opens `viewer.html` through a real `file://` Chromium page, and records `offline_browser_smoke_report.json`. Never embed a Draco GLB in the r147 offline viewer unless a matching offline decoder is bundled and tested. - Confirm idle `window.__renders` does not grow, GLBs decode, variants exist, controls work, and console errors are zero. diff --git a/scripts/cad_showcase.py b/scripts/cad_showcase.py index 15c6d54..0ef3b4f 100644 --- a/scripts/cad_showcase.py +++ b/scripts/cad_showcase.py @@ -373,7 +373,7 @@ def ensure_node_runtime(pipeline: Pipeline, *, browser: bool) -> None: ) -def run_browser_smoke(pipeline: Pipeline, web_dir: Path, report: Path, screenshots: Path) -> None: +def run_browser_smoke(pipeline: Pipeline, web_dir: Path, report: Path, screenshots: Path, thumbnail: Path) -> None: """Serve the formal Web bundle and mechanically prove desktop/mobile loading.""" report.parent.mkdir(parents=True, exist_ok=True) port = available_port() @@ -405,8 +405,10 @@ def run_browser_smoke(pipeline: Pipeline, web_dir: Path, report: Path, screensho str(report), "--screenshots-dir", str(screenshots), + "--thumbnail-out", + str(thumbnail), ), - [report, screenshots], + [report, screenshots, thumbnail], ) finally: server.terminate() @@ -695,7 +697,13 @@ def run_pipeline(args: argparse.Namespace) -> int: browser_report = ( Path(args.browser_report).resolve() if args.browser_report else out_dir / "browser_smoke_report.json" ) - run_browser_smoke(pipeline, web_dir, browser_report, out_dir / "browser_smoke") + run_browser_smoke( + pipeline, + web_dir, + browser_report, + out_dir / "browser_smoke", + out_dir / "thumbnail.png", + ) standard = bundle / "variants" / "standard" / "standard.glb" offline = out_dir / "viewer.html" diff --git a/scripts/web_smoke_test.mjs b/scripts/web_smoke_test.mjs index e056de7..7845d81 100644 --- a/scripts/web_smoke_test.mjs +++ b/scripts/web_smoke_test.mjs @@ -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(); }