// 标注插件本地端到端(开发用,不进 CI)。 // // 为什么需要它:真站 e2e 要发布后才能跑;本探针直接把构建产物注入合成宿主, // 在真实 Chromium 里验证「选区 / 命令层 / 撤销 / 还原原图 / 输出预设 / 便利 UI」 // 以及 ESM 循环打包后是否真的能跑起来。网络完全本地,不依赖线上 KV 与 CSP。 // // 运行:node image-annotate/tools/harness.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)) const REPO = path.resolve(HERE, '../..') const HOST_REPO = '/Users/qiqi/open/github/image-workbench-web' const PLUGIN_ENTRY = path.resolve(HERE, '../src/index.js') 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') process.exit(2) } let failed = 0 const check = (name, ok, detail) => { if (!ok) failed++ console.log((ok ? '✓ ' : '✗ ') + name + (detail ? ' ' + detail : '')) } const poll = async (fn, timeout = 8000, step = 80) => { 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)) } } const browser = await chromium.launch() const page = await browser.newPage({ viewport: { width: 1440, height: 1000 }, acceptDownloads: true }) const errors = [] page.on('console', (m) => { if (m.type() === 'error') errors.push(m.text()) }) page.on('pageerror', (e) => errors.push('pageerror: ' + e.message)) page.on('dialog', (d) => { errors.push('unexpected dialog: ' + d.message()); d.dismiss().catch(() => {}) }) await page.setContent('
') 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.evaluate(() => { window.IWBPluginHost = { register(manifest, factory) { window.__manifest = manifest; window.__factory = factory }, snapshot() { return { initialized: true } }, list() { return [] } } window.__actions = {} window.__commands = {} window.__settings = {} window.__writes = [] }) await page.addScriptTag({ path: PLUGIN_ENTRY }) const boot = await page.evaluate((png) => { const ctx = { id: 'image-annotate', manifest: window.__manifest, apiVersion: 1, log() {}, settings: { get(k) { return window.__settings[k] }, set(k, v) { window.__settings[k] = v }, all() { return { ...window.__settings } } }, storage: { get() {}, set() {}, remove() {}, keys() { return [] } }, events: { on() { return () => {} }, emit() { return true } }, canvas: { getNodeImage() { return { dataUrl: png } }, getSelectedNode() { return { id: 'r1', type: 'ref', name: 'src.png' } }, setNodeImage(id, dataUrl) { window.__writes.push({ kind: 'replace', id, len: String(dataUrl).length }); return true }, createImageNode(o) { window.__writes.push({ kind: 'newNode', len: String(o.dataUrl).length }); return { id: 'r2' } } }, nodeActions: { register(r) { window.__actions[r.id] = r } }, commands: { register(r) { window.__commands[r.id] = r } } } window.__plugin = window.__factory(ctx) window.__commands['annotate-selected'].run().catch(() => {}) return { version: window.__manifest.version, settingsSchema: Object.keys(window.__manifest.settings || {}) } }, PNG) check('产物可执行(循环打包未炸)', boot.version === '1.1.2', 'version=' + boot.version) check('manifest 声明输出预设设置项', boot.settingsSchema.includes('exportPreset') && boot.settingsSchema.includes('panelsCollapsed'), boot.settingsSchema.join(',')) await page.locator('#iwb-editor-overlay').waitFor({ state: 'visible', timeout: 15000 }) const dbg = () => page.evaluate(() => window.__iwbEditor.__debug()) const pixel = (cx, cy) => page.evaluate(({ x, y }) => { const d = window.__iwbEditor.__debug() return { base: d.pixel('base', x, y), draw: d.pixel('draw', x, y), layers: d.layers.map(l => ({ id: l.id, a: d.pixel(l.id, x, y) })) } }, { x: cx, y: cy }) check('编辑器打开 + 便利 UI 五区齐全', await page.evaluate(() => { const q = (s) => Boolean(document.querySelector(s)) return q('.iwb-editor-optionbar') && q('.iwb-editor-statusbar') && q('.iwb-editor-sel-bar') && q('.iwb-editor-toast') && q('.iwb-editor-selection-overlay') && q('.iwb-editor-cursor-overlay') && q('[data-action="download"]') && q('[data-action="toggleMore"]') })) check('新增选区工具按钮', (await page.locator('.iwb-editor-tool[data-tool="marquee"]').count()) === 1 && (await page.locator('.iwb-editor-tool[data-tool="lasso"]').count()) === 1) check('modal 铺满视口、状态栏贴在 modal 底部(防多余 把状态栏挤成 overlay 的 flex 兄弟)', await page.evaluate(() => { const ov = document.querySelector('#iwb-editor-overlay') const modal = ov.querySelector('.iwb-editor-modal') const sb = ov.querySelector('.iwb-editor-statusbar') if (!ov || !modal || !sb) return false const vw = window.innerWidth const m = modal.getBoundingClientRect(), s = sb.getBoundingClientRect(), o = ov.getBoundingClientRect() const inside = (a, b) => a.left >= b.left - 1 && a.right <= b.right + 1 && a.top >= b.top - 1 && a.bottom <= b.bottom + 1 return Math.round(m.width) === vw && Math.round(o.width) === vw && Math.abs(s.bottom - m.bottom) < 3 && inside(m, o) && inside(s, m) })) const imgBox = await page.locator('.iwb-editor-layer-canvas').first().boundingBox() const drag = async (x1, y1, x2, y2) => { await page.mouse.move(x1, y1) await page.mouse.down() await page.mouse.move(x2, y2, { steps: 8 }) await page.mouse.up() await page.waitForTimeout(120) } // ---------- P1 选区 ---------- await page.locator('.iwb-editor-tool[data-tool="marquee"]').click() await drag(imgBox.x + imgBox.width * 0.25, imgBox.y + imgBox.height * 0.25, imgBox.x + imgBox.width * 0.7, imgBox.y + imgBox.height * 0.7) const sel = (await dbg()).selection check('拖出矩形选区 + 蚂蚁线启动', Boolean(sel && sel.w > 5 && sel.h > 5) && (await dbg()).ants, JSON.stringify(sel)) check('选区浮动操作条自动出现', await page.locator('.iwb-editor-sel-bar').isVisible()) const cx = Math.round(sel.x + sel.w / 2) const cy = Math.round(sel.y + sel.h / 2) const beforeFill = await pixel(cx, cy) await page.locator('.iwb-editor-sel-bar button[data-sel-cmd="sel.fill"]').click() const afterFill = await pixel(cx, cy) check('填充只写当前层(base 像素不变)', afterFill.draw && afterFill.draw[3] > 0 && JSON.stringify(afterFill.base) === JSON.stringify(beforeFill.base), 'draw=' + JSON.stringify(afterFill.draw) + ' base=' + JSON.stringify(afterFill.base)) const layersBeforeCopy = (await dbg()).layers.length await page.locator('.iwb-editor-sel-bar button[data-sel-cmd="sel.copy"]').click() const afterCopy = await dbg() check('复制为新层:像素落在选区原位、原层不变', afterCopy.layers.length === layersBeforeCopy + 1 && (await pixel(cx, cy)).draw[3] > 0, '层数 ' + layersBeforeCopy + ' → ' + afterCopy.layers.length) check('复制来源为当前层:新层有填充像素', afterCopy.layers.some(l => l.name === '选区副本') && (await pixel(cx, cy)).layers.some(v => v.id !== 'base' && v.id !== 'draw' && v.a && v.a[3] > 0)) await page.keyboard.press('Control+z') check('Ctrl+Z 撤销「复制为新层」(图层数可回退)', (await dbg()).layers.length === layersBeforeCopy, '层数=' + (await dbg()).layers.length) await page.locator('.iwb-editor-sel-bar button[data-sel-cmd="sel.delete"]').click() const afterDelete = await pixel(cx, cy) check('Delete 只清当前层:draw 挖空、base 与其它层原样', afterDelete.draw[3] === 0 && JSON.stringify(afterDelete.base) === JSON.stringify(beforeFill.base), 'draw=' + JSON.stringify(afterDelete.draw) + ' base=' + JSON.stringify(afterDelete.base)) await page.keyboard.press('Control+z') check('Ctrl+Z 恢复被清除的像素', (await pixel(cx, cy)).draw[3] > 0) // 三入口共用命令层 await page.keyboard.press('Control+j') const afterHotkey = await dbg() check('快捷键 Ctrl+J 与浮动条共用 execute()', afterHotkey.layers.length === layersBeforeCopy + 1 && afterHotkey.historyLabels.includes('复制为新层'), 'labels=' + JSON.stringify(afterHotkey.historyLabels.slice(-3))) await page.keyboard.press('Control+z') await page.mouse.click(imgBox.x + imgBox.width * 0.8, imgBox.y + imgBox.height * 0.2, { button: 'right' }) check('右键菜单复用同一条操作条', await page.locator('.iwb-editor-sel-bar.as-menu').count() === 1) // ---------- 还原原图(用户裁定:全部还原 + 可撤销) ---------- await page.keyboard.press('Control+a') // 重建选区(右键/工具切换不会改像素) await page.keyboard.press('Control+j') // 制造一个额外的选区副本层 const beforeReset = await dbg() await page.locator('[data-action="reset"]').click() const afterReset = await dbg() check('还原原图:只剩「原图 + 空画笔层」,无空白粘贴层', afterReset.layers.length === 2 && afterReset.layers.some(l => l.id === 'base') && afterReset.layers.some(l => l.id === 'draw'), JSON.stringify(afterReset.layers.map(l => l.name))) check('还原原图清空矢量/选区但保留 base 像素', !afterReset.selection && JSON.stringify((await pixel(cx, cy)).base) === JSON.stringify(beforeFill.base)) await page.keyboard.press('Control+z') const afterUndoReset = await dbg() check('Ctrl+Z 完整恢复还原前的图层结构(含被删的选区副本层)', beforeReset.layers.length === 3 && afterUndoReset.layers.length === beforeReset.layers.length, '还原前 ' + beforeReset.layers.length + ' → 还原后 ' + afterReset.layers.length + ' → 撤销后 ' + afterUndoReset.layers.length) // ---------- 单张输出预设(≤500KB) ---------- await page.locator('[data-action="toggleExportSettings"]').click() await page.locator('[data-export-key="preset"][data-export-value="ecom800"]').click() const opt = (await dbg()).exportOptions check('≤500KB 预设可切换并存 ctx.settings', opt.preset === 'ecom800' && opt.maxKB === 500 && (await page.evaluate(() => window.__settings.exportPreset)) === 'ecom800', JSON.stringify(opt)) await page.locator('[data-action="download"]').click() const exported = await poll(async () => (await dbg()).lastExport) check('下载只产一个结果:800×800 且 ≤500KB、编辑器不关闭', Boolean(exported && exported.width === 800 && exported.height === 800 && exported.bytes <= 500 * 1024 && await page.locator('#iwb-editor-overlay').isVisible()), JSON.stringify(exported)) // 输出面板的可见性/文案探针:面板收起时子元素 display 不在布局里, // 所以统一读 textContent 而不是 innerText(后者对隐藏元素返回空串)。 const summaryText = () => page.locator('.iwb-editor-export-summary').textContent() const noteText = () => page.locator('.iwb-editor-export-note').textContent() const ecomRowsVisible = () => page.evaluate(() => { const rows = Array.from(document.querySelectorAll('[data-export-when="ecom800"]')) return rows.length >= 2 && rows.every(r => !r.hidden) }) check('电商预设:摘要写明尺寸/格式/背景/体积上限', /800×800/.test(await summaryText()) && /≤500KB/.test(await summaryText()) && /透明/.test(await summaryText()), await summaryText()) await page.locator('[data-action="toggleExportSettings"]').click() // 上一步点「下载」会自动收起面板 check('电商预设:边长与体积控件可见', await ecomRowsVisible()) await page.locator('[data-export-key="format"][data-export-value="jpeg"]').click() const afterJpg = await dbg() check('选 JPG:背景自动收敛为白底并写回 settings(不再「显示透明、实际白底」)', afterJpg.exportOptions.bg === 'white' && (await page.evaluate(() => window.__settings.exportBg)) === 'white' && (await page.locator('[data-export-key="bg"][data-export-value="transparent"]').isDisabled()) === true, JSON.stringify(afterJpg.exportOptions)) check('JPG 摘要显示白底', /白底/.test(await summaryText()), await summaryText()) await page.locator('[data-action="download"]').click() const jpg = await poll(async () => { const d = await dbg(); return d.lastExport && d.lastExport.format === 'jpeg' ? d.lastExport : false }) check('格式/背景切换生效(JPG + 白底)', Boolean(jpg) && jpg.bg === 'white', JSON.stringify(jpg)) check('下载后摘要记录上次输出(尺寸 + 体积)', /上次输出 800×800/.test(await noteText()), await noteText()) // 边长 / 体积上限:原来只有计算没有控件,改完必须能真的改到并生效 await page.locator('[data-action="toggleExportSettings"]').click() await page.locator('[data-export-key="size"][data-export-value="1000"]').click() await page.locator('[data-export-key="maxKB"][data-export-value="300"]').click() const optSized = (await dbg()).exportOptions check('边长/体积控件可改并持久化到 ctx.settings', optSized.size === 1000 && optSized.maxKB === 300 && (await page.evaluate(() => window.__settings.exportSize)) === 1000 && (await page.evaluate(() => window.__settings.exportMaxKB)) === 300, JSON.stringify(optSized)) await page.locator('[data-action="download"]').click() const sized = await poll(async () => { const d = await dbg(); return d.lastExport && d.lastExport.width === 1000 ? d.lastExport : false }) check('边长生效:输出 1000×1000 且体积 ≤300KB', Boolean(sized) && sized.width === 1000 && sized.bytes <= 300 * 1024, JSON.stringify(sized)) await page.locator('[data-action="toggleExportSettings"]').click() await page.locator('[data-export-key="preset"][data-export-value="original"]').click() const optOriginal = (await dbg()).exportOptions check('切回原尺寸:maxKB 归零并写回 settings(重开不会让限制「复活」)', optOriginal.preset === 'original' && optOriginal.maxKB === 0 && (await page.evaluate(() => window.__settings.exportMaxKB)) === 0, JSON.stringify(optOriginal)) check('原尺寸下边长/体积控件隐藏', (await ecomRowsVisible()) === false) check('原尺寸摘要显示实际像素尺寸', /原尺寸 96×64/.test(await summaryText()), await summaryText()) await page.locator('[data-action="toggleExportSettings"]').click() // 收起,恢复后续用例的初始态 // ---------- 选区与裁剪互斥 ---------- await page.locator('.iwb-editor-tool[data-tool="crop"]').click() check('切到裁剪会清掉选区', !(await dbg()).selection) await page.locator('.iwb-editor-tool[data-tool="marquee"]').click() check('切回选区会取消裁剪框', await page.evaluate(() => { const bar = document.querySelector('.iwb-editor-crop-bar') return bar && getComputedStyle(bar).display === 'none' })) // ---------- 回归:矢量对象经撤销/重做后仍可渲染(快照不得把 DOM 画布序列化成 {}) ---------- await page.locator('.iwb-editor-tool[data-tool="rect"]').click() await drag(imgBox.x + imgBox.width * 0.2, imgBox.y + imgBox.height * 0.2, imgBox.x + imgBox.width * 0.45, imgBox.y + imgBox.height * 0.45) await page.keyboard.press('Control+z') await page.keyboard.press('Control+Shift+z') check('矢量对象撤销/重做后画布正常重建', await page.evaluate(() => document.querySelectorAll('.iwb-editor-vec-canvas').length >= 1)) await page.locator('.iwb-editor-tool[data-tool="brush"]').click() // ---------- 旧流程回归:粘贴一步落层 + 覆盖写回 ---------- const beforePaste = (await dbg()).layers.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) const pasted = await poll(async () => (await dbg()).layers.length === beforePaste + 1) check('粘贴图片一步落层(不再需要 Enter 确认)', Boolean(pasted), '层数 ' + beforePaste + ' → ' + (await dbg()).layers.length) await page.keyboard.press('Enter') check('粘贴后按 Enter 不会重复落层', (await dbg()).layers.length === beforePaste + 1) await page.locator('[data-action="replace"]').click() const wrote = await poll(async () => page.evaluate(() => window.__writes.some(w => w.kind === 'replace'))) check('覆盖仍回写宿主节点并关闭编辑器', Boolean(wrote) && (await page.locator('#iwb-editor-overlay').isVisible().catch(() => false)) === false, JSON.stringify(await page.evaluate(() => window.__writes))) // ---------- Round 2:P1 缺陷回归(新会话,逐条对应已确认缺陷) ---------- // 走 glue 的 openEditor:只有它能把「退出」与宿主 Promise 的结算连起来验证。 await page.evaluate(() => { window.__openState = null window.__commands['annotate-selected'].run().then( (mode) => { window.__openState = { mode: String(mode) } }, (err) => { window.__openState = { error: String((err && err.message) || err) } } ) }) await page.locator('#iwb-editor-overlay').waitFor({ state: 'visible', timeout: 15000 }) await page.waitForFunction(() => window.__iwbEditor.__debug().open === true) const box2 = await page.locator('.iwb-editor-layer-canvas').first().boundingBox() const drag2 = async (x1, y1, x2, y2) => { await page.mouse.move(x1, y1) await page.mouse.down() await page.mouse.move(x2, y2, { steps: 8 }) await page.mouse.up() await page.waitForTimeout(120) } // ---- Fix1:反选后 Delete / 复制必须作用整幅(与填充一致) ---- await page.keyboard.press('Control+a') await page.locator('.iwb-editor-sel-bar button[data-sel-cmd="sel.fill"]').click() const fullFill = await pixel(6, 6) check('Fix1 前置:全选填充整层', fullFill.draw[3] > 0) await page.locator('.iwb-editor-tool[data-tool="marquee"]').click() await drag2(box2.x + box2.width * 0.3, box2.y + box2.height * 0.3, box2.x + box2.width * 0.6, box2.y + box2.height * 0.6) const sel2 = (await dbg()).selection const cx2 = Math.round(sel2.x + sel2.w / 2) const cy2 = Math.round(sel2.y + sel2.h / 2) await page.keyboard.press('Control+Shift+i') const inv = (await dbg()).selection check('反选:标记 inverted 且蚂蚁线仍在', Boolean(inv && inv.inverted) && (await dbg()).ants, JSON.stringify(inv)) await page.keyboard.press('Delete') const invKeep = await pixel(cx2, cy2) const invGone = await pixel(6, 6) check('反选 + Delete:原选区内保留、原选区外挖空、base 不变', invGone.draw[3] === 0 && invKeep.draw[3] > 0 && JSON.stringify(invGone.base) === JSON.stringify(fullFill.base), 'inside=' + JSON.stringify(invKeep.draw) + ' outside=' + JSON.stringify(invGone.draw)) await page.keyboard.press('Control+z') check('反选 + Delete 可 Ctrl+Z 回退(掩膜 tile 边界未偏移)', (await pixel(6, 6)).draw[3] > 0) const layersBeforeInvCopy = (await dbg()).layers.length await page.keyboard.press('Control+j') const afterInvCopy = await dbg() const invCopyLayer = afterInvCopy.layers[afterInvCopy.layers.length - 1] const copyOutside = await pixel(6, 6) const copyInside = await pixel(cx2, cy2) const copyOutsidePx = copyOutside.layers.find(v => v.id === invCopyLayer.id).a const copyInsidePx = copyInside.layers.find(v => v.id === invCopyLayer.id).a check('反选 + Ctrl+J:新层只含原选区外像素,且与原层逐点对齐(不偏移)', afterInvCopy.layers.length === layersBeforeInvCopy + 1 && invCopyLayer.name === '选区副本' && copyOutsidePx[3] > 0 && copyOutsidePx.join(',') === copyOutside.draw.join(',') && copyInsidePx[3] === 0, 'outside=' + JSON.stringify(copyOutsidePx) + ' draw=' + JSON.stringify(copyOutside.draw) + ' inside=' + JSON.stringify(copyInsidePx)) await page.keyboard.press('Control+z') // 撤销复制新层 await page.keyboard.press('Control+d') // 取消选区 // feather>0:整幅 tile 不能把羽化边界变成硬切 await page.locator('.iwb-editor-tool[data-tool="marquee"]').click() await page.locator('.iwb-editor-optionbar-body [data-opt="feather"]').fill('6') await drag2(box2.x + box2.width * 0.3, box2.y + box2.height * 0.3, box2.x + box2.width * 0.6, box2.y + box2.height * 0.6) const selF = (await dbg()).selection await page.keyboard.press('Control+Shift+i') await page.keyboard.press('Delete') const edgeAlphas = [] for (let dx = -6; dx <= 6; dx++) { edgeAlphas.push((await pixel(Math.round(selF.x) + dx, Math.round(selF.y + selF.h / 2))).draw[3]) } check('反选 + 羽化 6px:边界仍是渐变(羽化未因整幅掩膜失效)', selF.feather === 6 && edgeAlphas.some(a => a > 0 && a < 255), JSON.stringify(edgeAlphas)) await page.keyboard.press('Control+z') await page.keyboard.press('Control+d') await page.locator('.iwb-editor-optionbar-body [data-opt="feather"]').fill('0') // ---- Fix3:选中形状时建立像素选区,Delete 语义必须切到「清像素」 ---- await page.locator('.iwb-editor-tool[data-tool="rect"]').click() await drag2(box2.x + box2.width * 0.35, box2.y + box2.height * 0.35, box2.x + box2.width * 0.65, box2.y + box2.height * 0.65) await page.locator('.iwb-editor-tool[data-tool="select"]').click() await page.mouse.click(box2.x + box2.width * 0.5, box2.y + box2.height * 0.5) const shapeSelected = await dbg() check('前置:形状已绘制并处于选中态', shapeSelected.shapes.length === 1 && shapeSelected.selectedShapeId === shapeSelected.shapes[0].id, JSON.stringify(shapeSelected.shapes)) await page.keyboard.press('Control+a') const selAllShape = (await dbg()).selection await page.keyboard.press('Delete') const afterShapeDelete = await dbg() const shapeDeletePixel = await pixel(cx2, cy2) check('选中形状 → Ctrl+A → Delete ⇒ 形状仍在、当前层像素被清(全选语义)', Boolean(selAllShape && selAllShape.w >= 96 && selAllShape.h >= 64) && afterShapeDelete.shapes.length === 1 && afterShapeDelete.selectedShapeId === null && shapeDeletePixel.draw[3] === 0, 'shapes=' + afterShapeDelete.shapes.length + ' draw=' + JSON.stringify(shapeDeletePixel.draw)) await page.keyboard.press('Control+z') await page.keyboard.press('Control+d') // ---- Fix2:裁剪与选区互斥(快捷键 / 更多菜单 / 右键菜单三入口) + confirmCrop 清残留 ---- await page.locator('.iwb-editor-tool[data-tool="crop"]').click() const cropStart = await dbg() check('切到裁剪:旧选区被清、蚂蚁线停止', cropStart.selection === null && cropStart.ants === false) await page.keyboard.press('Control+a') const cropAfterA = await dbg() check('裁剪中 Ctrl+A:不建选区、不启动蚂蚁线、浮动条不出现', cropAfterA.selection === null && cropAfterA.ants === false && (await page.locator('.iwb-editor-sel-bar').isVisible()) === false) await page.locator('[data-action="toggleMore"]').click() await page.locator('[data-more="sel.all"]').click() const cropAfterMenu = await dbg() check('裁剪中「更多 → 全选」同样被拦', cropAfterMenu.selection === null && cropAfterMenu.ants === false) await page.mouse.click(box2.x + box2.width * 0.5, box2.y + box2.height * 0.5, { button: 'right' }) const menuShown = await page.locator('.iwb-editor-sel-bar.as-menu').count() await page.locator('.iwb-editor-sel-bar button[data-sel-cmd="sel.all"]').click() const cropAfterCtx = await dbg() check('裁剪中右键菜单「全选」同样被拦', menuShown === 1 && cropAfterCtx.selection === null && cropAfterCtx.ants === false) await drag2(box2.x + box2.width * 0.1, box2.y + box2.height * 0.1, box2.x + box2.width * 0.7, box2.y + box2.height * 0.7) check('裁剪框可拉出(确认按钮可见)', await page.locator('[data-action="confirmCrop"]').isVisible()) await page.locator('[data-action="confirmCrop"]').click() const cropped = await dbg() check('确认裁剪:尺寸更新且无旧坐标系选区/蚂蚁线残留', cropped.doc.w < 96 && cropped.doc.h < 64 && cropped.selection === null && cropped.ants === false, JSON.stringify(cropped.doc)) await page.keyboard.press('Delete') const afterCropDelete = await dbg() check('裁剪后 Delete 不按旧 bbox 误擦(层数不变、底图仍有像素)', afterCropDelete.layers.length === cropped.layers.length && (await pixel(5, 5)).base[3] > 0 && afterCropDelete.selection === null) // ---- 还原原图的「尺寸复位」分支:必须走统一重绘,摘要/蚂蚁线才跟着走 ---- // (该分支会 setupCanvas + 清历史,此前只调 updateAllUI,摘要停留在裁剪后尺寸) const cropSummary = await summaryText() await page.locator('[data-action="reset"]').click() const restoredDoc = await dbg() const restoredSummary = await summaryText() check('还原原图复位尺寸后:输出摘要即时跟随(不停留在裁剪后尺寸)', restoredDoc.doc.w === 96 && restoredDoc.doc.h === 64 && /原尺寸 96×64/.test(restoredSummary) && cropSummary !== restoredSummary, cropSummary + ' → ' + restoredSummary) check('还原原图复位尺寸后蚂蚁线已停、选区已清', restoredDoc.ants === false && !restoredDoc.selection) // ---- Fix4:点「退出」必须结算宿主 Promise(glue.openEditor → onClose) ---- await page.locator('[data-action="cancel"]').click() const openState = await poll(async () => page.evaluate(() => window.__openState)) check('点「退出」:宿主 Promise 结算为 cancel 且编辑器关闭', Boolean(openState && openState.mode === 'cancel') && (await page.locator('#iwb-editor-overlay').isVisible().catch(() => false)) === false, JSON.stringify(openState)) check('无运行时错误 / 无弹窗', errors.length === 0, errors.slice(0, 3).join(' | ')) await browser.close() console.log('\n' + (failed ? '✗ 失败 ' + failed + ' 项' : '✓ 全部通过')) process.exit(failed ? 1 : 0)