// 真实站点端到端(开发用,不进 CI)。 // // 为什么需要它:mock 页没有 CSP,`connect-src` 一类问题(例如 `fetch(dataURL)` 被 // `connect-src 'self' https: …` 拦掉)在 mock 下永远绿,只有带 CSP 的真站能抓出来。 // 它不 mock /plugins/*:走真实 KV + 浏览器 SRI 校验 + 真实画布桥。 // // 运行: // node image-annotate/tools/e2e-site.mjs // IWB_BASE_URL=https://iwb.maqiart.eu.org node image-annotate/tools/e2e-site.mjs // 依赖:playwright(本仓/宿主仓 node_modules 均可;或用 IWB_PLAYWRIGHT_ROOT 指定)。 import { createRequire } from 'node:module' import { readFileSync } from 'node:fs' import path from 'node:path' import { fileURLToPath } from 'node:url' const HERE = path.dirname(fileURLToPath(import.meta.url)) // /image-annotate/tools const REPO = path.resolve(HERE, '../..') // const HOST_REPO = '/Users/qiqi/open/github/image-workbench-web' let chromium = null for (const base of [process.env.IWB_PLAYWRIGHT_ROOT, REPO, HOST_REPO, process.cwd()].filter(Boolean)) { try { chromium = createRequire(path.join(base, 'package.json'))('playwright').chromium; break } catch { /* 试下一个 */ } } if (!chromium) { console.error('✗ 找不到 playwright。请在含 node_modules 的目录执行,或指定 IWB_PLAYWRIGHT_ROOT:') console.error(' npm i -D playwright # 本仓或宿主仓皆可') console.error(' IWB_PLAYWRIGHT_ROOT=/path/to/repo node image-annotate/tools/e2e-site.mjs') process.exit(2) } const BASE = process.env.IWB_BASE_URL || 'https://test.image-workbench-web.pages.dev' const WANT_VERSION = JSON.parse(readFileSync(path.join(REPO, 'image-annotate/package.json'), 'utf8')).version const CFG = { providers: [], canvas: {} } const WS = { workspaces: [{ id: 'w1', name: 'W', nodes: [], edges: [], groups: [] }], activeId: 'w1', rev: 1 } let failed = 0 const check = (name, ok, detail) => { if (!ok) failed++ console.log((ok ? '✓ ' : '✗ ') + name + (detail ? ' ' + detail : '')) } const poll = async (fn, timeout = 25000, step = 250) => { const end = Date.now() + timeout for (;;) { let v try { v = await fn() } catch { v = false } if (v) return v if (Date.now() > end) return false await new Promise((r) => setTimeout(r, step)) } } console.log('目标站点:' + BASE + '(期望插件版本 ' + WANT_VERSION + ')') const browser = await chromium.launch() const page = await browser.newPage({ viewport: { width: 1440, height: 1000 } }) const consoleErrors = [] page.on('console', (m) => { if (m.type() === 'error') consoleErrors.push(m.text()) }) page.on('pageerror', (e) => consoleErrors.push('pageerror: ' + e.message + ' @ ' + String(e.stack || '').split('\n').slice(1, 4).join(' | '))) page.on('dialog', (d) => { consoleErrors.push('unexpected dialog: ' + d.message()); d.dismiss().catch(() => {}) }) // 造一张真实的 96x64 PNG 作为节点图片 await page.goto('about:blank') const PNG = await page.evaluate(() => { const c = document.createElement('canvas') c.width = 96; c.height = 64 const x = c.getContext('2d') x.fillStyle = '#2f6fed'; x.fillRect(0, 0, 96, 64) x.fillStyle = '#ffffff'; x.fillRect(20, 12, 56, 40) return c.toDataURL('image/png') }) await page.addInitScript((d) => { localStorage.clear() localStorage.setItem('iwb_web_cfg', JSON.stringify(d.cfg)) const ws = JSON.parse(JSON.stringify(d.ws)) ws.workspaces[0].nodes = [{ id: 'r1', type: 'ref', x: 140, y: 140, data: { url: '', data: d.png, name: 'src.png', localName: null } }] localStorage.setItem('iwb_web_workspaces', JSON.stringify(ws)) localStorage.setItem('iwb_ws_active', ws.activeId) localStorage.setItem('iwb_ws_w1', JSON.stringify(ws.workspaces[0])) localStorage.setItem('iwb_web_outputs', JSON.stringify([])) localStorage.setItem('iwb_plugins', JSON.stringify({ 'image-annotate': { enabled: true, settings: {}, data: {} } })) }, { cfg: CFG, ws: WS, png: PNG }) const resp = await page.goto(BASE + '/', { waitUntil: 'domcontentloaded' }) check('站点可达', Boolean(resp && resp.ok()), resp && String(resp.status())) await page.waitForFunction(() => Boolean(window.IWBPluginHost) && window.IWBPluginHost.snapshot().initialized === true, null, { timeout: 30000 }) // ---------- 1) 真实 KV 加载 + SRI + 启用 ---------- const active = await poll(async () => page.evaluate(() => { const p = window.IWBPluginHost.list().find((x) => x.id === 'image-annotate') return p && p.active ? { version: p.version, enabled: p.enabled, capabilities: p.capabilities, error: p.error } : false })) check('从真实 KV 加载并启用(SRI 通过)', Boolean(active), JSON.stringify(active)) check('线上版本 = package.json(' + WANT_VERSION + ')', Boolean(active && active.version === WANT_VERSION), active && active.version) const scripts = await page.evaluate(() => Array.from(document.querySelectorAll('script[src*="/plugins/"]')).map((s) => ({ src: s.getAttribute('src'), integrity: s.getAttribute('integrity') || '' }))) // 文件名两种都合法:plugins-publish.mjs 产内容寻址名(..js,可 immutable 缓存), // plugins-publish.sh(带主干守卫的合规通道)产固定名(plugin-image-annotate.js,走 no-cache+ETag)。 // 断言的关键是「必须带 integrity」,与命名策略无关。 check('插件脚本用 SRI(sha256) 加载', scripts.some((s) => /^\/plugins\/plugin-image-annotate(\.[a-f0-9]{12})?\.js$/.test(s.src) && /^sha256-/.test(s.integrity)), JSON.stringify(scripts)) // ---------- 2) 打开工作区 + 节点存在 ---------- await page.locator('.iwb-home-card:not(.iwb-home-new)').first().dblclick() await page.locator('.iwb-canvas:not(.iwb-canvas-hidden)').waitFor({ state: 'visible', timeout: 30000 }) check('工作区打开、种子节点在画布', (await page.locator('.iwb-node[data-node-id="r1"]').count()) === 1) // ---------- 3) 入口:节点漂浮菜单(回落右键插件命令)---------- const openEditor = async () => { await page.locator('.iwb-node[data-node-id="r1"]').click() const btn = page.locator('.iwb-node-floatbar button[title="标注 / 修图"]') if (await btn.count()) { await btn.click(); return '漂浮菜单' } await page.locator('.iwb-canvas').click({ button: 'right', position: { x: 900, y: 620 } }) await page.locator('.iwb-ctxmenu .iwb-ctx-item').filter({ hasText: '标注 / 修图:选中节点' }).click() return '右键命令' } const entry = await openEditor() check('节点入口可触发(漂浮菜单或右键命令)', true, entry) // ---------- 4) 编辑器打开(真实 CSP 下注入样式)---------- await page.locator('#iwb-editor-overlay').waitFor({ state: 'visible', timeout: 30000 }) const opened = await page.evaluate(() => { const el = document.querySelector('#iwb-editor-overlay') const style = document.getElementById('iwb-annotate-style') return { display: getComputedStyle(el).display, position: getComputedStyle(el).position, zIndex: getComputedStyle(el).zIndex, bg: getComputedStyle(el).backgroundColor, styleInjected: Boolean(style && style.textContent.includes('.iwb-editor-')), } }) check('编辑器浮层可见', opened.display === 'flex' && opened.position === 'fixed') check('样式注入生效(CSP unsafe-inline)', opened.styleInjected) check('浮层压住宿主 UI', Number(opened.zIndex) >= 999998, 'z=' + opened.zIndex + ' bg=' + opened.bg) // ---------- 4.5) 剪贴板粘贴:⌘V 把剪贴板图片贴为新图层 ---------- // 合成 ClipboardEvent(带 image/png File),粘贴应进入「图片放置」模式;回车确认后图层面板 +1 项。 // SKIP_PASTE=1 可跳过(隔离「粘贴」与「覆盖写回」两条链路的排查用)。 const SKIP_PASTE = process.env.SKIP_PASTE === '1' if (!SKIP_PASTE) { // 先画一个矢量矩形,制造「截图 + 图形」共存场景 —— 这是 z 撞车 / 排序按钮失效的复现前提 const imgBox = await page.locator('.iwb-editor-layer-canvas').first().boundingBox() await page.locator('.iwb-editor-tool[data-tool="rect"]').click() await page.mouse.move(imgBox.x + imgBox.width * 0.25, imgBox.y + imgBox.height * 0.25) await page.mouse.down() await page.mouse.move(imgBox.x + imgBox.width * 0.75, imgBox.y + imgBox.height * 0.75, { steps: 8 }) await page.mouse.up() await page.waitForTimeout(200) const layersBefore = await page.evaluate(() => document.querySelectorAll('.iwb-editor-layer-list > *').length) await page.evaluate((png) => { const bin = atob(png.split(',')[1]) const bytes = new Uint8Array(bin.length) for (let i = 0; i < bin.length; i++) bytes[i] = bin.charCodeAt(i) const dt = new DataTransfer() dt.items.add(new File([bytes], 'paste.png', { type: 'image/png' })) document.dispatchEvent(new ClipboardEvent('paste', { clipboardData: dt, bubbles: true, cancelable: true })) }, PNG) await page.waitForTimeout(800) // FileReader → loadImage → 进入放置模式 await page.keyboard.press('Enter') // 确认放置 → 落层 const pasted = await poll(async () => page.evaluate((n) => document.querySelectorAll('.iwb-editor-layer-list > *').length > n, layersBefore)) check('⌘V 粘贴剪贴板图片 → 确认后图层面板 +1', Boolean(pasted), '图层项 ' + layersBefore + ' → ' + await page.evaluate(() => document.querySelectorAll('.iwb-editor-layer-list > *').length)) // ---------- 4.6) 图层顺序回归(2026-11-04 修):z 唯一 / 选中唯一 / 四个排序按钮 ---------- const panelSeq = () => page.evaluate(() => Array.from(document.querySelectorAll('.iwb-editor-layer-list .iwb-layer-item')) .map((n) => n.querySelector('.iwb-layer-name')?.textContent).join(' > ')) const activeCount = () => page.evaluate(() => document.querySelectorAll('.iwb-editor-layer-list .iwb-layer-item.active').length) check('图层面板只有一个选中项(画笔目标改用 ✎ 标记)', (await activeCount()) === 1, 'active=' + await activeCount() + ' / ' + await panelSeq()) await page.locator('.iwb-editor-tool[data-tool="select"]').click() await page.mouse.click(imgBox.x + imgBox.width * 0.5, imgBox.y + imgBox.height * 0.5) await page.waitForTimeout(150) const activeItem = await page.evaluate(() => { const n = document.querySelector('.iwb-editor-layer-list .iwb-layer-item.active') return n && { type: n.dataset.layerType, name: n.querySelector('.iwb-layer-name')?.textContent } }) check('点击「截图+图形」重叠区选中最上层截图(不被下方图形抢走)', Boolean(activeItem && activeItem.type === 'bitmap' && /图层/.test(activeItem.name)), JSON.stringify(activeItem)) // v1.13 起顶栏四个层级按钮已删除(改为图层拖动 + Ctrl+]/[ 快捷键), // 这里改为断言「按钮确实没了」+ 用快捷键验证排序仍然可用。 check('顶栏不再有层级排序按钮(改用图层拖动 + Ctrl+]/[)', (await page.locator('.iwb-editor-layer-btn').count()) === 0 && (await page.locator('.iwb-editor-header .iwb-editor-commands').count()) === 0, 'layerBtn=' + await page.locator('.iwb-editor-layer-btn').count()) // v1.18(用户 2026-11-10):撤销 / 重做 / 还原 从顶栏搬到工具条最右, // 「适应窗口 / 收起侧栏」退到它前面两位。这里断言「末尾是撤销组、视图按钮在其前」 // —— 光看版本号挡不住产物没重建。 const toolsOrder = await page.evaluate(() => { const kids = Array.from(document.querySelectorAll('.iwb-editor-tools > *')) const acts = kids.filter((n) => n.dataset && n.dataset.action).map((n) => n.dataset.action) const hist = kids[kids.length - 1] return { tail: acts.slice(-2), lastIsHistory: Boolean(hist && hist.classList.contains('iwb-editor-history')), histActs: [...(hist ? hist.querySelectorAll('[data-action]') : [])].map((b) => b.dataset.action), headerHasHistory: Boolean(document.querySelector('.iwb-editor-header .iwb-editor-history')), } }) check('工具栏最右是「撤销/重做/还原」组(视图按钮在其前)', JSON.stringify(toolsOrder.tail) === JSON.stringify(['zoomFit', 'togglePanels']) && toolsOrder.lastIsHistory && toolsOrder.histActs.join(',') === 'undo,redo,reset' && !toolsOrder.headerHasHistory, JSON.stringify(toolsOrder)) const before = await panelSeq() const activeName = await page.evaluate(() => document.querySelector('.iwb-editor-layer-list .iwb-layer-item.active .iwb-layer-name')?.textContent) await page.keyboard.press('Control+[') // 下移一层 const afterDown = await panelSeq() check('Ctrl+[ 下移一层改变图层顺序', before !== afterDown, before + ' → ' + afterDown) await page.keyboard.press('Control+]') // 上移一层 check('Ctrl+] 上移一层恢复原顺序', (await panelSeq()) === before, await panelSeq()) await page.keyboard.press('Control+Shift+[') // 置底 const afterBottom = await panelSeq() check('Ctrl+Shift+[ 置底生效(元素不会消失)', afterBottom !== before && afterBottom.endsWith(String(activeName)), afterBottom) check('置底后原图不再被钉在最底 —— 图层可以压到原图下面(v1.13 解封)', !afterBottom.endsWith('原图'), afterBottom) await page.keyboard.press('Control+Shift+]') // 置顶 check('Ctrl+Shift+] 置顶生效', (await panelSeq()) !== afterBottom, await panelSeq()) check('排序后仍只有一个选中项', (await activeCount()) === 1, 'active=' + await activeCount()) // v1.15 图片调节:真站确认面板存在、11 项按参数表生成(DOM 由 adjust.js 生成, // 构建时漏带就会是 0 行 —— 这类「打包产物缺模块」只有真站能发现) const adjRowCount = await page.locator('.iwb-editor-adj-row').count() const adjNames = await page.locator('.iwb-editor-adj-name').allTextContents() check('右侧栏「图片调节」11 项齐全', adjRowCount === 11 && adjNames.join('/') === '曝光/明度/对比度/阴影/高光/色相/饱和度/温度/色调/锐度/清晰度', 'rows=' + adjRowCount + ' ' + adjNames.join('/')) check('调节面板认到了作用层(不是「无图层」)', (await page.locator('.iwb-editor-adj-target').textContent()) !== '无图层', await page.locator('.iwb-editor-adj-target').textContent()) // v1.19:右栏常驻调色面板已删(用户 2026-11-10),颜色只剩工具栏弹层一处。 // 真站里 DOM 与 CSS 分别打包,这里同时验「右栏干净」和「弹层头部一行 / 16 色 8 列」—— // 样式漏打包时,头部会退回竖排或色块掉成 6 列,这条会直接露出来。 const sideColor = await page.evaluate(() => ({ hasSide: Boolean(document.querySelector('.iwb-editor-left [data-color-surface]')), firstSection: (document.querySelector('.iwb-editor-left > section') || {}).className || '', })) check('右栏调色模块已删(第一个模块是图片调节)', sideColor.hasSide === false && /iwb-editor-adj/.test(sideColor.firstSection), JSON.stringify(sideColor)) await page.locator('.iwb-editor-tools [data-action="toggleColorPop"][data-color-slot="stroke"]').click() await page.waitForTimeout(240) const popShape = await page.evaluate(() => { const pop = document.querySelector('.iwb-editor-color-pop') if (!pop) return null const r = (el) => el.getBoundingClientRect() const head = r(pop.querySelector('.iwb-color-pop-head')) const items = [pop.querySelector('[data-action="palettePick"]'), pop.querySelector('.iwb-editor-color-hex-input'), pop.querySelector('[data-action="pinColorPop"]')].map((el) => { const b = r(el) return { c: b.top + b.height / 2, l: b.left, r: b.right } }) const sw = [...pop.querySelectorAll('.iwb-editor-color-swatches [data-panel-color]')] const grid = pop.querySelector('.iwb-editor-color-swatches') return { w: Math.round(r(pop).width), sameRow: items.every((it) => Math.abs(it.c - (head.top + head.height / 2)) < 3 && it.l >= head.left - 1 && it.r <= head.right + 1), common: sw.length, cols: new Set(sw.map((b) => Math.round(r(b).left))).size, swatch: sw.length ? Math.round(r(sw[0]).width) : 0, // v1.20:去色占常用色第一格(20px 同尺寸、第一排最左) noneFirst: grid.children[0] === pop.querySelector('[data-color-none]'), cells: grid.children.length, } }) check('色板弹层:头部一行(吸管 / 色值 / 图钉同排)+ 去色占常用色第一格 + 15 色 8 列', Boolean(popShape) && popShape.sameRow && popShape.noneFirst && popShape.cells === 16 && popShape.common === 15 && popShape.cols === 8 && popShape.swatch === 20 && popShape.w === 440, JSON.stringify(popShape)) await page.keyboard.press('Escape') await page.waitForTimeout(140) const sideBefore = await page.evaluate(() => Math.round(document.querySelector('.iwb-editor-left').getBoundingClientRect().width)) const sideGrip = await page.locator('.iwb-editor-side-resizer').boundingBox() if (sideGrip) { await page.mouse.move(sideGrip.x + 3, sideGrip.y + 120) await page.mouse.down() await page.mouse.move(sideGrip.x + 3 - 70, sideGrip.y + 120, { steps: 6 }) await page.mouse.up() await page.waitForTimeout(180) } const sideAfter = await page.evaluate(() => Math.round(document.querySelector('.iwb-editor-left').getBoundingClientRect().width)) check('右栏可以拖宽(不再固定 220)', sideAfter >= sideBefore + 60, sideBefore + ' → ' + sideAfter) await page.locator('.iwb-editor-side-resizer').dblclick() await page.waitForTimeout(150) // v1.17:描边可以是「无色」。真站要验的是按钮真的出现在描边槽、点完对象上真的关了, // 而不只是 CSS 里多了个类 —— 形状消失与否只有跑起来才知道。 await page.locator('.iwb-editor-tool[data-tool="rect"]').click() await page.mouse.move(imgBox.x + imgBox.width * 0.12, imgBox.y + imgBox.height * 0.12) await page.mouse.down() await page.mouse.move(imgBox.x + imgBox.width * 0.30, imgBox.y + imgBox.height * 0.30, { steps: 6 }) await page.mouse.up() await page.waitForTimeout(250) await page.locator('.iwb-editor-tool[data-tool="select"]').click() await page.mouse.click(imgBox.x + imgBox.width * 0.21, imgBox.y + imgBox.height * 0.21) await page.waitForTimeout(200) await page.locator('.iwb-editor-tools [data-action="toggleColorPop"][data-color-slot="stroke"]').click() await page.waitForTimeout(250) const noneOnStroke = await page.evaluate(() => { const n = document.querySelector('.iwb-editor-color-pop [data-color-none]') // v1.20:去色不再 hidden,改用 disabled 表达「这个上下文不能去色」 return Boolean(n) && Boolean(n.offsetParent) && !n.disabled }) await page.evaluate(() => document.querySelector('.iwb-editor-color-pop [data-color-none]').click()) await page.waitForTimeout(300) const noStrokeState = await page.evaluate(() => { const d = window.__iwbEditor.__debug() const s = d.shapes.find((x) => x.id === d.selectedShapeId) return s ? { strokeOn: s.strokeOn, fill: s.fill } : null }) check('真站:描边能置「无」(去掉描边顺手切实心,对象不会消失)', noneOnStroke && Boolean(noStrokeState) && noStrokeState.strokeOn === false && noStrokeState.fill === true, JSON.stringify({ noneOnStroke, noStrokeState })) await page.keyboard.press('Escape') await page.waitForTimeout(120) // v1.14 字体选择:真站是带 CSP 的环境,这里确认下拉可用、字体切换真的落到了对象上。 // 系统字体不受 CSP 约束(CSP 管的是网络字体),所以只要 canvas 能画就没问题。 const famDbg = () => page.evaluate(() => window.__iwbEditor.__debug()) const FAM_SEL = '.iwb-editor-optionbar-body select[data-opt-text="fontFamily"]' await page.locator('.iwb-editor-tool[data-tool="text"]').click() const famBox = await page.locator('.iwb-editor-layer-canvas').first().boundingBox() await page.mouse.click(famBox.x + 60, famBox.y + 60) await page.waitForTimeout(300) await page.evaluate(() => { const el = document.querySelector('.iwb-editor-text-input') if (!el) return el.focus() el.value = '字体测试' el.dispatchEvent(new Event('input', { bubbles: true })) }) await page.keyboard.press('Enter') await page.waitForTimeout(400) const famOpts = await page.locator(FAM_SEL + ' option').allTextContents() check('真站选项栏出现字体下拉,四档:黑体 / 宋体 / 楷体 / 圆体', famOpts.length === 4, JSON.stringify(famOpts)) const wSans = ((await famDbg()).texts.find((t) => t.text === '字体测试') || {}).box await page.selectOption(FAM_SEL, 'serif') await page.waitForTimeout(320) const tSerif = (await famDbg()).texts.find((t) => t.text === '字体测试') check('真站切换宋体生效,且中文宽度不变(全角等宽,版面不跳动)', Boolean(tSerif && tSerif.fontFamily === 'serif' && wSans && Math.abs(tSerif.box.w - wSans.w) <= 1), (wSans ? wSans.w : '?') + ' → ' + (tSerif ? tSerif.box.w : '?')) await page.keyboard.press('Delete') await page.waitForTimeout(200) // 复原成画笔工具,避免影响后面「覆盖」链路的画笔取样 await page.locator('.iwb-editor-tool[data-tool="brush"]').click() } // ---------- 4.7) v1.1:选区 / 单层 Delete / 还原原图 / ≤500KB 预设 ---------- const dbg = () => page.evaluate(() => window.__iwbEditor.__debug()) const v11Box = await page.locator('.iwb-editor-layer-canvas').first().boundingBox() await page.locator('.iwb-editor-tool[data-tool="marquee"]').click() await page.mouse.move(v11Box.x + v11Box.width * 0.25, v11Box.y + v11Box.height * 0.25) await page.mouse.down() await page.mouse.move(v11Box.x + v11Box.width * 0.7, v11Box.y + v11Box.height * 0.7, { steps: 8 }) await page.mouse.up() await page.waitForTimeout(150) const v11sel = (await dbg()).selection check('v1.1 框选 + 浮动操作条出现', Boolean(v11sel && v11sel.w > 5 && v11sel.h > 5) && await page.locator('.iwb-editor-sel-bar').isVisible(), JSON.stringify(v11sel)) const v11px = (x, y) => page.evaluate(({ px, py }) => { const d = window.__iwbEditor.__debug() // 1.2.1 起默认没有 id='draw' 的预建层:填充落进「当前活动层」, // 所以这里读活动层像素而不是写死 'draw' return { base: d.pixel('base', px, py), draw: d.pixel(d.activeLayerId, px, py), activeId: d.activeLayerId } }, { px: x, py: y }) const vcX = Math.round(v11sel.x + v11sel.w / 2) const vcY = Math.round(v11sel.y + v11sel.h / 2) const v11before = await v11px(vcX, vcY) await page.locator('.iwb-editor-sel-bar button[data-sel-cmd="sel.fill"]').click() await page.locator('.iwb-editor-sel-bar button[data-sel-cmd="sel.delete"]').click() const v11after = await v11px(vcX, vcY) check('v1.1 Delete 只清当前层(base 像素原样)', v11after.draw[3] === 0 && JSON.stringify(v11after.base) === JSON.stringify(v11before.base), 'draw=' + JSON.stringify(v11after.draw) + ' base=' + JSON.stringify(v11after.base)) await page.keyboard.press('Control+z') const v11layersBeforeReset = (await dbg()).layers.length await page.locator('[data-action="reset"]').click() check('v1.1 还原原图=只剩原图单层(1.2.1 起不预建画笔层)', (await dbg()).layers.length === 1, JSON.stringify((await dbg()).layers)) await page.keyboard.press('Control+z') check('v1.1 还原原图可 Ctrl+Z 撤销', (await dbg()).layers.length === v11layersBeforeReset, '层数 ' + v11layersBeforeReset + ' → 2 → ' + (await dbg()).layers.length) await page.locator('[data-action="toggleExportSettings"]').click() await page.locator('[data-export-key="preset"][data-export-value="ecom800"]').click() check('v1.1 ≤500KB 输出预设可切换', (await dbg()).exportOptions.maxKB === 500, JSON.stringify((await dbg()).exportOptions)) await page.locator('[data-export-key="preset"][data-export-value="original"]').click() await page.locator('.iwb-editor-tool[data-tool="brush"]').click() // ---------- 5) 覆盖:回写真机画布 ---------- await page.mouse.move(400, 300) await page.mouse.down() await page.mouse.move(760, 520, { steps: 8 }) await page.mouse.up() await page.locator('[data-action="replace"]').click() const replaced = await poll(async () => page.evaluate((orig) => { const ws = JSON.parse(localStorage.getItem('iwb_ws_w1') || '{}') const n = (ws.nodes || []).find((x) => x.id === 'r1') if (!n) return false const v = n.data && (typeof n.data.data === 'string' ? n.data.data : (n.data.data && (n.data.data.__blob || JSON.stringify(n.data.data)))) return (ws.nodes.length === 1 && v && v !== orig) ? { nodes: ws.nodes.length, changed: true } : false }, PNG)) check('「覆盖」写回原节点(节点数不变、内容已变)', Boolean(replaced), JSON.stringify(replaced)) check('编辑器导出后关闭', (await page.locator('#iwb-editor-overlay').isVisible().catch(() => false)) === false) // ---------- 6) 新建:真机画布新增节点 ---------- await openEditor() await page.locator('#iwb-editor-overlay').waitFor({ state: 'visible', timeout: 30000 }) await page.locator('[data-action="newNode"]').click() const created = await poll(async () => page.evaluate(() => { const ws = JSON.parse(localStorage.getItem('iwb_ws_w1') || '{}') return (ws.nodes || []).length === 2 ? { nodes: 2 } : false })) check('「新建」在真机画布新增节点', Boolean(created), JSON.stringify(created)) await page.locator('.iwb-canvas').waitFor({ state: 'visible' }) check('画布渲染出 2 个节点', (await page.locator('.iwb-node').count()) === 2) // ---------- 7) 无 CSP / 运行时错误 ---------- const bad = consoleErrors.filter((t) => /Content Security Policy|integrity|Refused to (execute|load|connect)/i.test(t)) check('无 CSP / SRI 拦截报错', bad.length === 0, bad.slice(0, 2).join(' | ')) check('无页面级运行时错误', consoleErrors.length === 0, consoleErrors.slice(0, 3).join(' | ')) await browser.close() console.log('\n' + (failed ? '✗ 失败 ' + failed + ' 项' : '✓ 全部通过')) process.exit(failed ? 1 : 0)