// iwb-dev-probe: 设计 token 视觉基线(M0/T0.2),不入常规门禁(下划线前缀 + 此标记 = 被 scripts/list-e2e-specs.js 排除) // // 为什么不做成门禁 spec: // ① 截图像素受**字体渲染**(系统是否装同版本中文字体)、**DPR**、**GPU 合成**影响, // 跨机器必然漂移 → 挂门禁就是把机器差异变成 CI 红灯; // ② 它的用途是「我改完这一批,和上一批比 0 diff」,属于本地验收工具,不是代码正确性断言。 // // 用法: // npm run build && node scripts/serve-test.js & # 端口 8787 // npx playwright test _visual-tokens --update-snapshots # 首次生成/确认变更 // npx playwright test _visual-tokens # 比对(0 diff 才算过) // // 8 个场景 × 亮/暗 = 16 张,覆盖「壳层 / 画布 / 浮层 / 抽屉 / 插件面板 / 右键菜单 / // 插件管理 / 插件市场」八类界面。⑦⑧ 是 M6 重做插件面板时补的:那一整段样式此前**没有基线**, // 六次叠加的改动全靠人眼看,等于最乱的地方最没保护。 // 稳定化:固定 1280×800 + deviceScaleFactor 1、animations disabled、caret hide、等字体与两帧。 const { test, expect } = require('./_pw-coverage') const baseURL = process.env.IWB_BASE_URL || 'http://127.0.0.1:8787' test.use({ baseURL, viewport: { width: 1280, height: 800 }, deviceScaleFactor: 1 }) // 预置一张「有东西可看」且**在视口内**的画布:提示词 → 文本 / 组合,组合 → 配置。 // 不放 out 节点:它的节点体是一张大卡片,会把画布基线变成「一张图 vs 一堆节点」的对比。 const WS = { workspaces: [{ id: 'ws_visual', name: '视觉基线', groups: [], nodes: [ { id: 'p1', type: 'prompt', x: 240, y: 180, data: { text: '一只橘猫坐在窗台上,午后阳光,胶片质感' } }, { id: 't1', type: 'textout', x: 600, y: 180, data: {} }, { id: 'c1', type: 'combine', x: 240, y: 400, data: {} }, { id: 'g1', type: 'gen', x: 600, y: 400, data: { size: '1024x1024', n: 1 } }, ], edges: [ { id: 'e1', from: 'p1', to: 't1' }, { id: 'e2', from: 'p1', to: 'c1' }, { id: 'e3', from: 'c1', to: 'g1' }, ], }], activeId: 'ws_visual', rev: 1, schemaVersion: 1, } const CFG = { providers: [], canvas: {} } // 停靠栏状态:左栏停在「节点组」(默认「浏览器」面板在网页环境下只有一句客户端提示, // 「风格库」首帧是异步加载态,两者都不适合做像素基线);右栏默认关,④⑤ 用例自己点开。 const DOCK = { left: { open: true, w: 318, list: ['groups', 'browser', 'styles'], removed: [], active: 'groups' }, right: { open: false, w: 330, list: ['prompts', 'gallery'], removed: [], active: 'gallery' }, } // 主题走 iwb_theme(app.js initTheme 的读取键);清掉外观覆盖,保证基线是「出厂派生色」 async function seed(page, theme) { await page.addInitScript(({ cfg, ws, dock, theme }) => { localStorage.clear() localStorage.setItem('iwb_web_cfg', JSON.stringify(cfg)) localStorage.setItem('iwb_web_workspaces', JSON.stringify(ws)) localStorage.setItem('iwb_ws_active', ws.activeId) localStorage.setItem('iwb_theme', theme) localStorage.setItem('iwb.dock.v1', JSON.stringify(dock)) }, { cfg: CFG, ws: WS, dock: DOCK, theme }) } // 等「真的画完了」:字体就绪 + 连续两帧 + 没有正在跑的动画帧(rAF 计数稳定) async function settle(page) { await page.evaluate(() => document.fonts && document.fonts.ready) await page.evaluate(() => new Promise((resolve) => { let left = 3 const step = () => { left -= 1; if (left <= 0) resolve(); else requestAnimationFrame(step) } requestAnimationFrame(step) })) await page.waitForTimeout(250) // 少量固定等待:等 CSS 过渡(120ms)收尾;本文件不进门禁,不影响固定等待棘轮 } async function shot(page, name) { await settle(page) await expect(page).toHaveScreenshot(name + '.png', { animations: 'disabled', caret: 'hide', maxDiffPixels: 0, // threshold 默认 0.2(每像素 YCbCr 距离),`maxDiffPixels: 0` 只是「超阈值的像素数为 0」—— // 两者叠加并不等于逐像素精确。B5 踩到:端口描边色改了约 19 级,全被 0.2 吃掉, // 基线没更新、比对还显示 12/12 通过(假绿灯)。这里显式压到 0,让「0 diff」名副其实。 threshold: 0, }) } async function bootHome(page, theme) { await seed(page, theme) await page.goto('/', { waitUntil: 'domcontentloaded' }) await page.waitForSelector('.iwb-home-card:not(.iwb-home-new)', { timeout: 20000 }) await settle(page) } async function bootCanvas(page, theme) { await bootHome(page, theme) await page.locator('.iwb-home-card:not(.iwb-home-new)').first().dblclick() await page.waitForSelector('.iwb-canvas:not(.iwb-canvas-hidden)', { timeout: 20000 }) await expect(page.locator('.iwb-node')).toHaveCount(4, { timeout: 15000 }) // 画布基线关掉左栏:保持基线口径一致(停靠栏本身由 ④⑤ 两张右栏截图覆盖)。 // 注:v3.26.108 起 doFit 已扣除停靠栏占位,开左栏也不会再把节点压住;此步仅为基线稳定保留。 const toggle = page.locator('.iwb-top-nav-icon[title="显示 / 隐藏左栏"]').first() await toggle.click() await expect(page.locator('.iwb-dock[data-side="left"]')).toHaveCount(0) await page.waitForTimeout(300) } // 右栏默认是关的(dock 状态 right.open=false),必须点顶栏开关;开完等面板挂载 async function openRightDock(page) { await page.locator('.iwb-top-nav-icon[title="显示 / 隐藏右栏"]').first().click() await expect(page.locator('.iwb-dock[data-side="right"]')).toBeVisible({ timeout: 15000 }) await page.waitForTimeout(400) // 插件面板挂载是异步的(pluginMount effect) } // ── ⑦⑧ 组件夹具 ──────────────────────────────────────────────────────── // 为什么不用整页截图:插件管理/市场这一屏由 DesktopPluginsTab 渲染,而它在 // `isDesk()` 为 false 时(网页 e2e 环境)走的是另一条分支(.iwb-plugin-row 清单), // 这条最乱的样式反而截不到。夹具用同一套类名 + 真实 dist/style.css 渲染, // 覆盖「设置行 / 列表行 / 开关 / 工具条 / 筛选胶囊 / 卡片」六种形态。 const PANEL_HTML = `
插件
插件市场
浏览并安装由官方 / 社区制作的插件
插件安装情况
你目前已经安装了 8 个插件,其中 2 个可更新
开发者模式
加载 plugins/local/<id>/plugin.js(未签名,仅本地调试)
已安装插件
✎
标注 / 修图 v1.20.7 官方 已加载
在图片上画箭头、文字、马赛克,支持批量导出
◈
位图转矢量 v0.6.1 官方 未加载
把位图描成 SVG,可调颜色数量与平滑度
⇩
批量导出 v1.2.1 官方 可更新
按预设尺寸批量导出,支持透明 PNG 与白底 JPG 双版本
` const MARKET_HTML = `
插件市场
共 4 个插件 · 资料目录/plugins/
✎
标注 / 修图已安装
官方 · v1.20.7 · 442 KB
在图片上画箭头、文字、马赛克,支持批量导出
标注修图
◈
位图转矢量
官方 · v0.6.1 · 143 KB
把位图描成 SVG,可调颜色数量与平滑度
矢量
⇩
批量导出
官方 · v1.2.1 · 44 KB
按预设尺寸批量导出,支持透明 PNG 与白底 JPG 双版本
导出批处理
◐
风格来源
社区 · v1.3.3 · 69 KB
从参考图提取配色与风格关键词
风格
` async function bootPanel(page, theme, html) { await page.goto('about:blank') await page.setContent(html, { waitUntil: 'domcontentloaded' }) await page.addStyleTag({ path: require('node:path').join(__dirname, '..', 'dist', 'style.css') }) // 夹具里所有过渡必须彻底关掉:开关的 .15s 背景过渡在截图时可能停在最后一帧, // 两次截图差 1~3 级灰度、只有几个像素,却会让 threshold:0 的基线变成随机红灯。 await page.addStyleTag({ content: '*,*::before,*::after{transition:none!important;animation:none!important}' }) await page.evaluate((t) => { document.documentElement.classList.toggle('theme-dark', t === 'dark') }, theme) } for (const theme of ['light', 'dark']) { test.describe('视觉基线 · ' + theme, () => { test('① 首页', async ({ page }) => { await bootHome(page, theme) await shot(page, '01-home-' + theme) }) test('② 画布(节点 + 连线)', async ({ page }) => { await bootCanvas(page, theme) await shot(page, '02-canvas-' + theme) }) test('③ 设置弹窗', async ({ page }) => { await bootCanvas(page, theme) await page.locator('button[title="设置"]').first().click() await expect(page.locator('.iwb-settings-modal')).toBeVisible() await shot(page, '03-settings-' + theme) }) test('④ 库面板(右抽屉 · 图库)', async ({ page }) => { await bootCanvas(page, theme) await openRightDock(page) await shot(page, '04-drawer-gallery-' + theme) }) test('⑤ 插件面板(右抽屉 · 提示词库)', async ({ page }) => { await bootCanvas(page, theme) await openRightDock(page) await page.locator('.iwb-dock-btn[data-panel="prompts"]').first().click() await expect(page.locator('.iwb-dock[data-side="right"] .iwb-dock-body')).toBeVisible() await shot(page, '05-panel-promptlib-' + theme) }) test('⑥ 右键菜单', async ({ page }) => { await bootCanvas(page, theme) // 用合成 contextmenu 而不是 mouse.click(button:'right'):后者在 Chromium/macOS 上 // 会被节点/顶栏的命中判定吃掉,坐标依赖视口高度 → 基线不可复现。 await page.locator('.iwb-canvas').first().dispatchEvent('contextmenu', { clientX: 320, clientY: 520 }) await expect(page.locator('.iwb-ctxmenu').first()).toBeVisible() await shot(page, '06-ctxmenu-' + theme) }) test('⑦ 插件管理(设置行 + 列表 + 开关)', async ({ page }) => { await bootPanel(page, theme, PANEL_HTML) await shot(page, '07-plugins-manage-' + theme) }) test('⑧ 插件市场(工具条 + 筛选 + 卡片墙)', async ({ page }) => { await bootPanel(page, theme, MARKET_HTML) await shot(page, '08-plugins-market-' + theme) }) }) } // ── ⑨⑩ 提示词库弹窗夹具 ─────────────────────────────────────────────── // 真实对话框由插件 JS 生成、依赖 Tauri 宿主,网页环境点不出来;这里用同一套类名 + // 真实 dist/style.css + plugins/promptlib/styles.css 渲染,做「编辑 / 详情」两屏基线。 // 只覆盖静态外观:不测交互逻辑(交互由 tests/plugin-promptlib-render-test.js 守)。 const PLP_EDIT_HTML = `
编辑提示词
名称
分组
标签
收藏×
在光标处插入 {变量},并自动聚焦变量名
参考图片内容,保持图片内容一致性,{写实摄影} 风格,符合{女生} 喜好
变量与正文双向同步 · 点 i 写说明
` const PLP_DETAIL_HTML = `
提示词详情
女生喜欢的小红书封面
分组:
小红书
标签:
#收藏
字数:
119 字
提示词内容
参考图片内容,保持图片内容一致性,商品图片保持包装一致,修改图片的风格为小红书封面风格,{写实摄影} 风格,书写标题字,手绘辅助装饰及辅助文案,符合{女生} 喜好的配色,突出{价格与利益点},画面简洁,不需要给产品配名称,符合品牌的调性。
` async function bootPromptlib (page, theme, html) { await bootPanel(page, theme, html) await page.addStyleTag({ path: require('node:path').join(__dirname, '..', 'dist', 'plugins', 'promptlib', 'styles.css') }) await page.waitForTimeout(50) } for (const theme of ['light', 'dark']) { test.describe('视觉基线 · promptlib · ' + theme, () => { test('⑨ 提示词编辑弹窗', async ({ page }) => { await bootPromptlib(page, theme, PLP_EDIT_HTML) await shot(page, '09-promptlib-edit-' + theme) }) test('⑩ 提示词详情弹窗', async ({ page }) => { await bootPromptlib(page, theme, PLP_DETAIL_HTML) await shot(page, '10-promptlib-detail-' + theme) }) }) } // ── ⑪ 生图服务设置(多服务商 · 单栏切换) ───────────────────────────── // 设置页入口在网页环境是左下角导航齿轮(.iwb-nav-item[title="设置"]); // 这里预置两个服务商,验证 chips + 单份详情的视觉基线。 const SETTINGS_CFG = { providers: [ { id: 'p-visual-a', name: 'TuZi', baseUrl: 'https://apicdn.tu-zi.com/v1', fallbacks: ['https://apius.tu-zi.com/v1'], genPath: '/images/generations', editPath: '/images/edits', keys: [{ id: 'k1', name: 'Key', value: '', masked: 'sk-••••tCZT' }], models: [{ name: 'gpt-image-2-1k', visible: true }, { name: 'gpt-image-2', visible: true }], layerModels: [], }, { id: 'p-visual-b', name: '即梦 Dreamina', baseUrl: 'https://x.example/v1', fallbacks: [], keys: [], models: [] }, ], canvas: {}, } async function bootSettings (page, theme) { await page.addInitScript(({ cfg, theme }) => { localStorage.clear() localStorage.setItem('iwb_web_cfg', JSON.stringify(cfg)) localStorage.setItem('iwb_theme', theme) }, { cfg: SETTINGS_CFG, theme }) await page.goto('/', { waitUntil: 'domcontentloaded' }) await page.evaluate(() => { const el = document.querySelector('.iwb-nav-item[title="设置"]'); if (el) el.click() }) // 2026-11-25:设置默认落「通用」标签,本基线要的是生图服务页 → 显式切过去 await page.locator('.iwb-settings-modal .iwb-set-nav-item', { hasText: '生图服务' }).first().click() await expect(page.locator('.iwb-prov-chip').first()).toBeVisible({ timeout: 15000 }) await expect(page.locator('.iwb-provider-card')).toHaveCount(1) await settle(page) } for (const theme of ['light', 'dark']) { test.describe('视觉基线 · 设置 · ' + theme, () => { test('⑪ 生图服务(多服务商)', async ({ page }) => { await bootSettings(page, theme) await shot(page, '11-provider-settings-' + theme) }) }) } // ── ⑫ 通用设置(卡片化重排) ───────────────────────────────────────── for (const theme of ['light', 'dark']) { test.describe('视觉基线 · 通用设置 · ' + theme, () => { test('⑫ 通用(数据/图片/生成/版本)', async ({ page }) => { await bootSettings(page, theme) await page.locator('.iwb-tab', { hasText: '通用' }).first().click() await expect(page.locator('.iwb-gset-group-body').first()).toBeVisible({ timeout: 15000 }) await shot(page, '12-general-settings-' + theme) }) }) }