#!/usr/bin/env node /** * Gate for the beginner render lesson. * * node tools/web/check-render-basics.mjs * * Checks the capture report, the screenshots and finished frames it produced, * and the page itself. Two rules exist because a previous tutorial shipped with * them broken: adjacent screenshots must not be byte-identical, and a "render" * whose pixels are all transparent is not a picture. */ import assert from "node:assert/strict"; import fs from "node:fs"; import path from "node:path"; import {sha256File} from "./lib/image-stats.mjs"; const REPO = path.resolve(import.meta.dirname, "../.."); const GUIDE = path.join(REPO, "web/app/public/tutorial/render-basics"); const HTML = path.join(GUIDE, "index.html"); const CSS = path.join(GUIDE, "basics.css"); const REPORT = path.join(REPO, "tests/golden/RENDER-BASICS-001/capture-report.json"); const sha256 = (file) => crypto.createHash("sha256").update(fs.readFileSync(file)).digest("hex"); const failures = []; const check = (label, run) => { try { run(); } catch (error) { failures.push(`${label}: ${error.message}`); } }; const report = JSON.parse(fs.readFileSync(REPORT, "utf8")); const html = fs.readFileSync(HTML, "utf8"); const css = fs.readFileSync(CSS, "utf8"); // --- capture report ------------------------------------------------------- check("every step passed", () => { const failed = report.steps.filter((step) => step.status !== "PASS"); assert.equal(failed.length, 0, `failed steps: ${failed.map((step) => `${step.name} (${step.error ?? step.status})`).join("; ")}`); }); check("step files exist", () => { for (const step of report.steps) assert.ok(fs.existsSync(step.shot.path), `missing ${step.shot.path}`); }); check("no stale screenshots", () => { const listed = new Set(report.steps.map((step) => path.basename(step.shot.path))); const onDisk = fs.readdirSync(path.join(GUIDE, "steps")); assert.deepEqual(onDisk.filter((file) => !listed.has(file)), [], "screenshots left over from an earlier run"); }); check("step hashes match the report", () => { for (const step of report.steps) assert.equal(sha256File(step.shot.path), step.shot.sha256, `hash drifted: ${path.basename(step.shot.path)}`); }); check("adjacent screenshots differ", () => { assert.deepEqual(report.duplicateScreenshots, [], "consecutive steps captured the same frame"); }); check("server engines produced real pixels", () => { assert.equal(report.engines.length, 3, "expected Eevee, Workbench and Cycles"); for (const engine of report.engines) { assert.equal(engine.status, "PASS", `${engine.engine} ${engine.status}`); assert.ok(engine.artifact, `${engine.engine} has no artifact`); assert.ok(engine.pixels && engine.pixels.opaqueRatio > 0.5, `${engine.engine} wrote a transparent frame (opaqueRatio ${engine.pixels?.opaqueRatio})`); } }); check("PBR frame saved", () => { assert.ok(report.pbr?.artifact?.bytes > 0, "no PBR artifact"); assert.ok(fs.existsSync(report.pbr.artifact.path), `missing ${report.pbr.artifact.path}`); assert.equal(report.pbr.resolution, 512); }); check("render result editor showed that frame", () => { assert.deepEqual([report.renderResultView?.naturalWidth, report.renderResultView?.naturalHeight], [512, 512], "the editor did not display the 512 frame that was just rendered"); }); // A transparent frame is the defect this gate exists to name, not to hide: the // report must keep saying so until the embedded engine is fixed. check("embedded blank frame is recorded", () => { const engines = report.embeddedEngines ?? []; const workbench = engines.find((engine) => engine.engine === "BLENDER_WORKBENCH"); const eevee = engines.find((engine) => engine.engine === "BLENDER_EEVEE"); assert.ok(workbench, "embedded Workbench was not measured"); assert.ok(workbench.pixels?.opaqueRatio > 0.5, "embedded Workbench should produce a picture"); assert.ok(eevee, "embedded EEVEE was not measured"); assert.equal(eevee.pixels?.opaqueRatio, 0, "embedded EEVEE now renders pixels — update the lesson's known-gap note"); }); // --- page ----------------------------------------------------------------- check("no inline style or script", () => { assert.ok(!/]/i.test(html), "page contains