// Verify the SOFTWARE-RENDERING backdrop-filter fallback (upstream issue #95). // // Why this suite exists: `@supports not ((backdrop-filter: blur(1px)) or // (-webkit-backdrop-filter: blur(1px)))` is a SYNTAX check. In third-party // desktop shells that composite in software (enhanced / extended window modes) // the property parses fine but NEVER renders, so that CSS fallback stays // dormant, the glass surfaces claim a blur nobody draws, and the panels look // fully transparent ("过透"). The fix detects the condition at RUNTIME from the // WebGL renderer string and sets `body[data-we-glass-fallback]`; the CSS keyed // on that attribute disables backdrop-filter explicitly and re-applies the very // same near-opaque recipe the @supports fallbacks already carry (same --we-* // tokens, same color-mix declarations — no new mechanism, no new token). // // Static source assertions (cheap, robust) plus real runtime assertions against // the BUILT lib/client.js loaded in a node:vm sandbox with mocked globals, one // fresh sandbox per scenario (the detection caches its decision per module // instance, so a fresh instance is what makes scenario isolation honest). // // S1 the software-rasteriser regex carries every required pattern + /i. // S2 the manual override token + both renderer read paths are present. // A1 renderer containing SwiftShader → body[data-we-glass-fallback="1"]. // A2 a software context is released politely (WEBGL_lose_context once). // B1 normal renderer (NVIDIA GeForce RTX 4060) → hook absent. // B2 second normal renderer (Apple M1 Pro) → hook absent. // C1 getContext() → null (no WebGL at all) → hook set, and the // 'experimental-webgl' fallback is attempted in that order. // C2 the no-WebGL verdict is cached too (exactly 2 getContext calls for // 2 applies, never 4). // D1 ?we-glassfallback=off beats a SwiftShader detection → hook absent. // D2 ?we-glassfallback=on beats a normal renderer → hook set. // D3 ?we-glassfallback=1 / D4 =0 behave like on / off. // D5 an unknown value (?we-glassfallback=maybe) means auto → detection wins. // E1 the injected stylesheet really carries data-we-glass-fallback rules. // E2 REUSE proof: every near-opaque recipe the @supports fallbacks use also // appears in a data-we-glass-fallback rule (both texts, same string). // E3 those rules explicitly disable backdrop-filter (both prefixes) and the // content-surface plate reuses --we-content-surface-alpha / -color. // E4 the master switches are preserved (data-we-sidebar-glass / // data-we-glass-window still gate the fallback surfaces). // E5 GAP FIX (upstream #94): the composer card carries its blur on // [data-composer-card]::before, so the fallback block covers that carrier // too — a data-we-glass-fallback rule matching ::before with BOTH "none" // declarations AND a near-opaque recipe that the SIBLING fallback rules // also quote (same string, no new token / mechanism). // E6 daily-driver pairing (issue #398): every data-we-glass-fallback rule that // paints from --we-surface-tint-light has a dark twin — same selector once // [data-ds-dark-theme] is stripped, painting from --we-surface-tint-dark. // Without it the dark theme paints a 92% white plate. E6b is the negative // control: deleting the composer twin must be reported. // F1 disposing the plugin (fiber cleanup) removes the hook. // G1 the detection is cached: 3 applies → exactly 1 WebGL context created. // H1 no WEBGL_debug_renderer_info → gl.getParameter(gl.RENDERER) is read and // matched (llvmpipe → hook set). // H2 the same fallback path with a normal RENDERER → hook absent. // P1 the exact string the LOCAL supreium-headless-gl software rasteriser // reports (RENDERER "ANGLE" + VENDOR "stack-gl", no debug-renderer-info) // is detected — the reason the vendor string joins the match. // I1 with no URLSearchParams the regex fallback reads and decodes the override // (%6Fff → off) on a software renderer, and I2 does the same through // `new URLSearchParams(search)`; I3 is the positive control (same renderer, // no override → hook set), so the pair proves the guard actually runs // instead of the hook being absent for every input. // // Usage: node test/verify-softrender.mjs import { readFileSync } from 'node:fs'; import { createRequire } from 'node:module'; import vm from 'node:vm'; const results = []; function check(name, ok, detail) { results.push({ name, ok: !!ok }); console.log((ok ? 'PASS' : 'FAIL') + ' | ' + name + (detail ? ' | ' + detail : '')); } const CODE = readFileSync(new URL('../lib/client.js', import.meta.url), 'utf8'); // ADR-0016 第三刀:detectSoftwareRender 与 data-we-glass-fallback 的挂载随玻璃层出户到 // packages/glass ⇒ S1/S2 的静态提取与本沙箱的**行为**路径都改读/加载玻璃包产物。 const GLASS_CODE = readFileSync(new URL('../packages/glass/lib/client.glass.js', import.meta.url), 'utf8'); // ── Sandbox harness ────────────────────────────────────────────────────────── // Mirrors the loader style of verify-client.mjs / verify-resource-lifecycle.mjs: // the built bundle is a window.__ModuleLoader__.load({ id, factory }) envelope, // so we capture the handoff and call factory(require) ourselves. function makeEl(tag) { return { tagName: String(tag).toUpperCase(), children: [], attributes: Object.create(null), dataset: {}, textContent: '', className: '', style: { _props: {}, setProperty(k, v) { this._props[k] = v; }, removeProperty(k) { delete this._props[k]; }, }, appendChild(child) { this.children.push(child); child._parent = this; return child; }, remove() { if (this._parent) { const i = this._parent.children.indexOf(this); if (i >= 0) this._parent.children.splice(i, 1); } }, setAttribute(k, v) { this.attributes[k] = String(v); }, removeAttribute(k) { delete this.attributes[k]; }, getAttribute(k) { return Object.prototype.hasOwnProperty.call(this.attributes, k) ? this.attributes[k] : null; }, querySelector() { return null; }, querySelectorAll() { return []; }, addEventListener() {}, removeEventListener() {}, getBoundingClientRect() { return { width: 0, height: 0, left: 0, top: 0, right: 0, bottom: 0 }; }, classList: { add() {}, remove() {}, toggle() {}, contains() { return false; } }, isConnected: false, }; } const React = { Fragment: 'Fragment', useState: (init) => [typeof init === 'function' ? init() : init, () => {}], useEffect: () => {}, useLayoutEffect: () => {}, useMemo: (fn) => fn(), useCallback: (fn) => fn, useRef: (v) => ({ current: v }), createElement: (type, props, ...children) => typeof type === 'function' ? type(props || {}) : ({ type, props: props || null, children }), }; /** * Load lib/client.js into a fresh vm context and apply the plugin once per call * to the returned apply(). * `renderer` is the WEBGL_debug_renderer_info UNMASKED_RENDERER_WEBGL string; * `publicRenderer` is what gl.getParameter(gl.RENDERER) reports (used when the * debug extension is missing, i.e. unmasked:false). */ function loadClient({ search = '', renderer = 'NVIDIA GeForce RTX 4060', publicRenderer = 'NVIDIA GeForce RTX 4060', publicVendor = 'Google Inc. (Mock)', unmasked = true, webgl = true, loseContext = true, provideURLSearchParams = true, } = {}) { const stats = { getContext: 0, kinds: [], loseContext: 0, contextCreations: 0 }; const DBG = { UNMASKED_RENDERER_WEBGL: 0x9246, UNMASKED_VENDOR_WEBGL: 0x9245 }; const glMock = { RENDERER: 0x1f01, VENDOR: 0x1f00, getExtension(name) { if (name === 'WEBGL_debug_renderer_info' && unmasked) return DBG; if (name === 'WEBGL_lose_context' && loseContext) { return { loseContext() { stats.loseContext++; } }; } return null; }, getParameter(p) { if (p === DBG.UNMASKED_RENDERER_WEBGL) return renderer; if (p === DBG.UNMASKED_VENDOR_WEBGL) return 'Google Inc. (Mock)'; if (p === 0x1f01) return publicRenderer; if (p === 0x1f00) return publicVendor; return null; }, }; const bodyEl = makeEl('body'); const headEl = makeEl('head'); const makeCanvas = () => { const el = makeEl('canvas'); el.getContext = (kind) => { stats.getContext++; stats.kinds.push(String(kind)); if (!webgl) return null; if (kind !== 'webgl' && kind !== 'experimental-webgl') return null; stats.contextCreations++; return glMock; }; return el; }; const document = { createElement: (tag) => (String(tag).toLowerCase() === 'canvas' ? makeCanvas() : makeEl(tag)), getElementById: () => null, querySelector: () => null, querySelectorAll: () => [], addEventListener: () => {}, removeEventListener: () => {}, head: headEl, body: bodyEl, }; const localStorage = { _store: {}, getItem(k) { return Object.prototype.hasOwnProperty.call(this._store, k) ? this._store[k] : null; }, setItem(k, v) { this._store[k] = String(v); }, removeItem(k) { delete this._store[k]; }, }; const cap = { handoff: null, handoffs: [] }; const timers = []; const sandbox = { window: { __ModuleLoader__: { load: (h) => { cap.handoff = h; cap.handoffs.push(h); } }, addEventListener: () => {}, removeEventListener: () => {}, matchMedia: () => ({ matches: false, addEventListener: () => {}, removeEventListener: () => {} }), setTimeout: (fn, ms) => { const t = { fn, ms, cleared: false }; timers.push(t); return t; }, clearTimeout: (t) => { if (t) t.cleared = true; }, // ADR-0016:玻璃客户端入口的行状态轮询(每 3s 探测 glass-row-state)在求值期挂 interval // ⇒ 沙箱必须供给收集型桩,否则求值即 ReferenceError(不执行 fn ⇒ 探测不跑,行为判据不受影响)。 setInterval: (fn, ms) => { const t = { fn, ms, cleared: false, interval: true }; timers.push(t); return t; }, clearInterval: (t) => { if (t) t.cleared = true; }, innerWidth: 1280, innerHeight: 800, outerWidth: 1280, outerHeight: 800, }, document, localStorage, // Never resolves: the boot chain (loadPersisted → loadInventory) must not // race the synchronous assertions below with a late applyEffects(). fetch: () => new Promise(() => {}), React, navigator: { userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/120 mock' }, }; // Every scenario models a page, so `location` is always present (it used to be // gated behind a `provideLocation` switch that no scenario could meaningfully // turn off: the manual-override branch below is unreachable without it). sandbox.location = { search, href: 'http://127.0.0.1:43120/' + search, pathname: '/' }; if (provideURLSearchParams) sandbox.URLSearchParams = URLSearchParams; // ADR-0016:玻璃客户端入口在求值期裸调 setInterval(行状态轮询)——浏览器里裸全局就是 // window 上的 ⇒ 沙箱顶层必须同样供给(收集型桩,不执行 fn,行为判据不受影响)。 sandbox.setInterval = (fn, ms) => { const t = { fn, ms, cleared: false, interval: true }; timers.push(t); return t; }; sandbox.clearInterval = (t) => { if (t) t.cleared = true; }; vm.createContext(sandbox); new vm.Script(CODE, { filename: 'client.js' }).runInContext(sandbox); if (!cap.handoff || typeof cap.handoff.factory !== 'function') { throw new Error('lib/client.js did not register a module-loader factory'); } const requireMock = (spec) => { if (spec === 'react') return React; if (spec === 'react-dom') return { createPortal: (node) => node }; // no createRoot → rope effect skipped throw new Error('unexpected require: ' + spec); }; const exportsObj = cap.handoff.factory(requireMock); // ADR-0016 第三刀:与真实 loader 同形,把玻璃子包产物也在**同一个 vm 上下文**求值掉 // (它的 factory 经 require('dsh-plugin-wallpaper-engine') 取主 bundle 键集,登记 // registerLayerHooks('glass') + registerGlassStatus)。不求值它 ⇒ apply() 挂载期玻璃层 // 不在注册表里,sync 永不跑,A1/A2/G1 等行为判据全部以"钩子为 null"假红。 new vm.Script(GLASS_CODE, { filename: 'client.glass.js' }).runInContext(sandbox); const glassHandoff = cap.handoffs ? cap.handoffs[cap.handoffs.length - 1] : null; const subRequire = (spec) => (spec === 'dsh-plugin-wallpaper-engine' ? exportsObj : requireMock(spec)); if (glassHandoff && typeof glassHandoff.factory === 'function') glassHandoff.factory(subRequire); const disposers = []; const ctx = { slots: { inject: (key, cb) => cb(), register: () => {} }, effect(fn) { const d = fn(); if (typeof d === 'function') disposers.push(d); return d; }, }; return { stats, bodyEl, headEl, ctx, disposers, timers, apply() { exportsObj.apply(ctx); }, hook() { return Object.prototype.hasOwnProperty.call(bodyEl.attributes, 'data-we-glass-fallback') ? bodyEl.attributes['data-we-glass-fallback'] : null; }, styleCss() { // ADR-0016 第四刀:样式表拆成主包 sheet + 玻璃包 sheet 两个