/* Bounded Chromium probe for the workbench-shading batch: * A. `.sl` studio-light presets reach the shader * B. MATCAP mode swaps the material and restores Studio * C. cavity + curvature change the frame, and reverting changes it back * D. `?offscreen=1` sculpt ring + stroke samples work through the worker * * Runs against the dev server on 5184 with the installed Chromium. Evidence only: * a PASS here is a probe result, not acceptance. */ import { createRequire } from 'node:module'; const WEB = '/home/mes123456/workinf_Blender_Wasm/web'; const { chromium } = createRequire(WEB + '/package.json')('playwright'); const BASE = 'http://127.0.0.1:5184'; const args = ['--no-sandbox', '--use-gl=angle', '--use-angle=gl', '--ignore-gpu-blocklist', '--enable-gpu-rasterization', '--enable-zero-copy']; const res = []; const rec = (m, o, s, d) => { res.push({ m, o, s, d }); console.log(`[${s}] ${m} :: ${o} :: ${d ?? ''}`); }; /* React reads `.value` off its own tracker, so a plain assignment is swallowed. * Go through the prototype setter and dispatch the event React listens for. */ const SET_SELECT = `(label, value) => { const el = document.querySelector('[aria-label="' + label + '"]'); if (!el) return 'missing'; const proto = Object.getPrototypeOf(el); const setter = Object.getOwnPropertyDescriptor(proto, 'value').set; setter.call(el, value); el.dispatchEvent(new Event('change', { bubbles: true })); return el.value; }`; const SET_CHECK = `(label, checked) => { const el = document.querySelector('[aria-label="' + label + '"]'); if (!el) return 'missing'; const setter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'checked').set; setter.call(el, checked); el.dispatchEvent(new Event('click', { bubbles: true })); el.dispatchEvent(new Event('change', { bubbles: true })); return el.checked; }`; /* Mean + spread of luminance across a horizontal scanline through the object. * Cavity darkens creases, so it moves both statistics; a preset swap moves the * distribution without touching the silhouette. */ const SAMPLE = `(y) => { const c = document.querySelector('canvas.viewport-canvas'); if (!c) return null; const gl = c.getContext('webgl2', { preserveDrawingBuffer: true }); if (!gl) return null; const w = gl.drawingBufferWidth, h = gl.drawingBufferHeight; const px = new Uint8Array(w * 4); gl.readPixels(0, Math.round(h * (y ?? 0.5)), w, 1, gl.RGBA, gl.UNSIGNED_BYTE, px); const lum = []; for (let i = 0; i < w; i++) { const a = 0.2126 * px[i * 4] + 0.7152 * px[i * 4 + 1] + 0.0722 * px[i * 4 + 2]; if (a > 3) lum.push(a); /* skip the flat background */ } if (lum.length < 8) return { n: lum.length, mean: 0, sd: 0, min: 0, max: 0 }; const mean = lum.reduce((s, v) => s + v, 0) / lum.length; const sd = Math.sqrt(lum.reduce((s, v) => s + (v - mean) ** 2, 0) / lum.length); return { n: lum.length, mean: Math.round(mean * 100) / 100, sd: Math.round(sd * 100) / 100, min: Math.round(Math.min(...lum)), max: Math.round(Math.max(...lum)), }; }`; const browser = await chromium.launch({ headless: false, args, executablePath: '/usr/bin/google-chrome' }); const page = await browser.newPage({ viewport: { width: 1500, height: 950 } }); const errs = []; page.on('pageerror', (e) => errs.push(String(e).slice(0, 240))); await page.goto(BASE + '/?ui=web', { waitUntil: 'domcontentloaded' }); await page.waitForTimeout(22000); rec('boot', 'app mounted', await page.locator('main.blender-app').count() ? 'PASS' : 'FAIL', ''); const canvas = page.locator('canvas.viewport-canvas').first(); await canvas.click({ position: { x: 420, y: 320 } }).catch(() => {}); await page.waitForTimeout(800); /* Get to SOLID however the app started: the button cycles WIREFRAME→SOLID→…, * so poll the dataset rather than assuming a start mode. */ const shading = () => page.evaluate(() => { const c = document.querySelector('canvas.viewport-canvas'); return c ? { shading: c.dataset.shadingMode ?? null, studio: c.dataset.studioLighting ?? null } : null; }); for (let i = 0; i < 5; i++) { const st = await shading(); if (st?.shading === 'solid') break; await page.locator('[aria-label="着色模式"]').click().catch(() => {}); await page.waitForTimeout(900); } rec('setup', 'SOLID reached', (await shading())?.shading === 'solid' ? 'PASS' : 'FAIL', JSON.stringify(await shading())); const sample = (y) => page.evaluate(`(${SAMPLE})(${y})`); /* ---------- A. `.sl` presets ---------- */ const presetNames = await page.evaluate(() => { const el = document.querySelector('[aria-label="工作室光照预设"]'); return el ? [...el.options].map((o) => o.value) : null; }); rec('A-sl', 'preset list populated', Array.isArray(presetNames) && presetNames.length === 6 ? 'PASS' : 'FAIL', JSON.stringify(presetNames)); const applyPreset = async (name) => { const got = await page.evaluate(`(${SET_SELECT})('工作室光照预设', ${JSON.stringify(name)})`); await page.waitForTimeout(1500); return got; }; const studioDefault = await sample(0.5); await applyPreset('basic.sl'); const studioBasic = await sample(0.5); await applyPreset('outdoor.sl'); const studioOutdoor = await sample(0.5); await applyPreset('studio.sl'); const studioStudio = await sample(0.5); rec('A-sl', 'basic.sl differs from Default', studioBasic && studioBasic.mean !== studioDefault?.mean ? 'PASS' : 'FAIL', `default=${JSON.stringify(studioDefault)} basic=${JSON.stringify(studioBasic)}`); rec('A-sl', 'outdoor.sl differs from basic.sl', studioOutdoor && studioOutdoor.sd !== studioBasic?.sd ? 'PASS' : 'FAIL', `basic=${JSON.stringify(studioBasic)} outdoor=${JSON.stringify(studioOutdoor)}`); rec('A-sl', 'studio.sl differs from outdoor.sl', studioStudio && studioStudio.mean !== studioOutdoor?.mean ? 'PASS' : 'FAIL', `outdoor=${JSON.stringify(studioOutdoor)} studio=${JSON.stringify(studioStudio)}`); /* ---------- B. MATCAP ---------- */ await applyPreset('Default'); const beforeMatcap = await sample(0.5); await page.evaluate(`(${SET_SELECT})('光照模式', 'MATCAP')`); await page.waitForTimeout(1600); const matcapList = await page.evaluate(() => { const el = document.querySelector('[aria-label="Matcap"]'); return el ? [...el.options].length : null; }); rec('B-matcap', 'matcap picker appears', matcapList === 27 ? 'PASS' : 'FAIL', `options=${matcapList}`); await page.evaluate(`(${SET_SELECT})('Matcap', 'clay_studio')`); await page.waitForTimeout(2200); const matcapClay = await sample(0.5); await page.evaluate(`(${SET_SELECT})('Matcap', 'fullmetal')`); await page.waitForTimeout(2200); const matcapMetal = await sample(0.5); rec('B-matcap', 'clay_studio renders shaded', matcapClay && matcapClay.sd > 3 ? 'PASS' : 'FAIL', JSON.stringify(matcapClay)); rec('B-matcap', 'fullmetal differs from clay_studio', matcapMetal && matcapClay && matcapMetal.mean !== matcapClay.mean ? 'PASS' : 'FAIL', `clay=${JSON.stringify(matcapClay)} metal=${JSON.stringify(matcapMetal)}`); await page.evaluate(`(${SET_SELECT})('光照模式', 'STUDIO')`); await page.waitForTimeout(1800); const backToStudio = await sample(0.5); rec('B-matcap', 'studio restores after matcap', backToStudio && beforeMatcap && backToStudio.mean === beforeMatcap.mean ? 'PASS' : 'INFO', `before=${JSON.stringify(beforeMatcap)} after=${JSON.stringify(backToStudio)}`); /* ---------- C. cavity + curvature ---------- */ const beforeCavity = await sample(0.5); const setCheck = (label, on) => page.evaluate(`(${SET_CHECK})(${JSON.stringify(label)}, ${on})`); await setCheck('空腔', true); await page.waitForTimeout(2000); const cavityOn = await sample(0.5); rec('C-post', 'cavity changes the frame', cavityOn && beforeCavity && (cavityOn.mean !== beforeCavity.mean || cavityOn.sd !== beforeCavity.sd) ? 'PASS' : 'FAIL', `off=${JSON.stringify(beforeCavity)} on=${JSON.stringify(cavityOn)}`); await setCheck('曲率', true); await page.waitForTimeout(2000); const curvatureOn = await sample(0.5); rec('C-post', 'curvature adds on top of cavity', curvatureOn && cavityOn && curvatureOn.sd !== cavityOn.sd ? 'PASS' : 'FAIL', `cavity=${JSON.stringify(cavityOn)} +curv=${JSON.stringify(curvatureOn)}`); await setCheck('曲率', false); await setCheck('空腔', false); await page.waitForTimeout(2000); const reverted = await sample(0.5); rec('C-post', 'toggling off reverts the frame', reverted && beforeCavity && Math.abs(reverted.mean - beforeCavity.mean) < 0.6 ? 'PASS' : 'FAIL', `before=${JSON.stringify(beforeCavity)} after=${JSON.stringify(reverted)}`); /* ---------- D. offscreen sculpt ---------- */ const off = await browser.newPage({ viewport: { width: 1200, height: 800 } }); const offErrs = []; off.on('pageerror', (e) => offErrs.push(String(e).slice(0, 240))); await off.goto(BASE + '/?ui=web&offscreen=1', { waitUntil: 'domcontentloaded' }); await off.waitForTimeout(22000); const offCanvas = off.locator('canvas.viewport-canvas').first(); await offCanvas.click({ position: { x: 320, y: 260 } }).catch(() => {}); await off.waitForTimeout(1500); rec('D-offscreen', 'worker backend attached', await off.evaluate(() => document.querySelector('canvas.viewport-canvas')?.dataset.rendererBackend) === 'offscreen-worker' ? 'PASS' : 'FAIL', ''); await off.evaluate(() => { const b = [...document.querySelectorAll('button')].find((e) => (e.textContent || '').trim() === 'Sculpting'); b?.click(); }); await off.waitForTimeout(6000); const ringSize = () => off.evaluate(() => { const el = document.querySelector('[data-testid="sculpt-brush-cursor"]'); if (!el) return null; const r = el.getBoundingClientRect(); return { w: Math.round(r.width), left: Math.round(r.left), top: Math.round(r.top) }; }); const box = await offCanvas.boundingBox(); const cx = box.x + box.width * 0.5, cy = box.y + box.height * 0.5; /* The ring answers from a cache the previous pointermove filled, so move twice: * the first move seeds the worker round-trip, the second reads it back. */ for (let i = 0; i < 3; i++) { await off.mouse.move(cx + i, cy); await off.waitForTimeout(500); } const ringSmall = await ringSize(); rec('D-offscreen', 'ring appears over the mesh', ringSmall ? 'PASS' : 'FAIL', JSON.stringify(ringSmall)); await off.keyboard.press('t'); await off.waitForTimeout(1000); await off.evaluate(() => { const input = document.querySelector('[aria-label="工具架 笔刷半径"]'); if (!input) return; const setter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value').set; setter.call(input, '0.9'); input.dispatchEvent(new Event('input', { bubbles: true })); }); await off.waitForTimeout(900); for (let i = 0; i < 3; i++) { await off.mouse.move(cx + 2 + i, cy + 2); await off.waitForTimeout(500); } const ringBig = await ringSize(); rec('D-offscreen', 'ring grows with brush radius', ringSmall && ringBig && ringBig.w > ringSmall.w ? 'PASS' : 'FAIL', `small=${ringSmall?.w} big=${ringBig?.w}`); /* Stroke samples: the sculpt editor button prints the current sample count. */ const samples = () => off.evaluate(() => { const b = [...document.querySelectorAll('button')].find((e) => (e.textContent || '').startsWith('Apply Sculpt Stroke')); const m = b && (b.textContent || '').match(/(\d+)\s*samples/); return m ? Number(m[1]) : null; }); const before = await samples(); await off.mouse.move(cx, cy); await off.mouse.down(); for (let i = 1; i <= 6; i++) { await off.mouse.move(cx + i * 8, cy + i * 3); await off.waitForTimeout(220); } await off.mouse.up(); await off.waitForTimeout(1500); const after = await samples(); rec('D-offscreen', 'drag produces stroke samples', before !== null && after !== null && after > before ? 'PASS' : 'FAIL', `before=${before} after=${after}`); console.log('\n=== SUMMARY ==='); const pass = res.filter((r) => r.s === 'PASS').length; const fail = res.filter((r) => r.s === 'FAIL'); console.log(`${pass}/${res.length} PASS, ${fail.length} FAIL`); fail.forEach((r) => console.log(` FAIL ${r.m} :: ${r.o} :: ${r.d}`)); console.log('pageerrors:', errs.slice(0, 6)); console.log('offscreen pageerrors:', offErrs.slice(0, 6)); await browser.close();