Compare commits

...
5 changed files with 344 additions and 8 deletions

No files matched your search

+22 -3
View File
@@ -25,7 +25,7 @@
- **点击**:不传坐标(`createNode('prompt', null, null, …)`),交给宿主 `findSpot()` —— 从**视口中心**向外螺旋扫空位、跳过已有节点、并**避开压在画布上的浮层**(资源中心 / 插件面板 / 左右侧栏)。插件只有节点的 `x/y`,拿不到 pan/zoom 和实测高度,自己排必然插到看不见的地方或压在别的节点上(旧版就是「选中节点右侧固定 380,无避让」)。
- **按住拖到画布上松手**:节点落在**松手点**(`screenToWorld` 换算,节点左上角对齐光标)。落点由宿主算:pan/zoom 只有它知道。拖动中光标下跟一张幽灵卡片,进入画布会提示「松手放这里」;松手点不在画布上(还在面板里)⇒ 取消。位移不足 6px 视作点击,两条路径并存、互不干扰。落点**压住已有节点或被浮层遮住**时,宿主会就近吸附到旁边的空位(`snapToFreeSpot`,20px 间隙、优先留在视口内);落在空处则**完全按松手点**,不偏移。
## 样式节点(v1.3.0)
## 样式节点(v1.3.1)
详情页底部有三颗按钮:**样式节点**(新)· 插入参考图 · 插入提示词。三颗都支持「点一下自动找位」和「按住拖到画布松手」,原两颗的行为一个字没改。
@@ -48,6 +48,13 @@
}
```
### v1.3.1(2026-11-14)CSS 改为激活时注入
`ensureStyle()` 原本只在 `mount()`(面板)里调用 ⇒ **没打开过「风格库」面板**时,节点体是无样式的裸 DOM,
`<img class="iwb-ssn-thumb">` 按原图尺寸铺满整个节点(真机表现:图片"跑出来了")。
现在 setup 注册变体前注入一次,`renderStyleNode()` 里再兜一次(幂等)。
回归用例:`tools/e2e-test-site.mjs` 第 9 段(不开面板直接进存档画布,断言缩略图宽高 ≈56px)。
### 五条硬约束(改之前先读)
1. **节点上没有生成按钮。** 注册变体时不传 `run`,宿主就不会渲染那颗按钮。出图一律交给下游生图节点(它已经处理了四家渠道差异、尺寸收敛、并发与恢复)。
@@ -160,16 +167,28 @@
数据与图片都是公网 `https://`,宿主 `_headers` 的 `img-src … https:` / `connect-src … https:` 已经放行。对比 `ai-chat`(连本机 `http://127.0.0.1:3425`)必须单独加端口。
## 测试(三层,从快到慢)
| 层 | 命令 | 覆盖什么 | 依赖 |
|---|---|---|---|
| 合成宿主 | `node tools/harness.mjs`(88 项) | 面板交互、详情页按钮顺序与同色、节点体结构、变量写入/防抖/不失焦、收起变量、截图 | 无(自带 mock 宿主) |
| 线上真网 | `node tools/e2e-real.mjs`(10 项) | 线上 `styles.json` 真拉的到、真 CSP、卡片渲染、样式节点入口 | 网络 |
| 测试站端到端 | `node tools/e2e-test-site.mjs`(15 项) | **宿主新接口到底接上没有**:双击进画布 → 开资源库 → 点「样式节点」→ 节点体由插件渲染、示例图默认勾选、变量输入不失焦、多变量不裁切、收起生效 | 宿主已发测试站(`SITE=` 换地址,`HEADED=1` 看着跑) |
前两支只验插件自己;**第三支才验宿主**,发布宿主改动后必跑。
## 发布
`src/index.js` 是手写单文件 IIFE,不构建,直接发布:
`src/index.js` 是手写单文件 IIFE,不构建。走宿主仓带守卫的发布脚本(会拒发「宿主工作区脏」和「HEAD 不在 origin/main」):
```bash
cp src/index.js /tmp/plugin-style-source.js
cd ../image-workbench-web
node scripts/plugins-publish.mjs /tmp/plugin-<其余插件>.js /tmp/plugin-style-source.js --upload --version style-source=1.0.5
scripts/plugins-publish.sh style-source /tmp/plugin-style-source.js 1.3.0
```
脚本会算 SRI、生成内容寻址名 `plugin-style-source.<hash12>.js`、**合并**进 KV 清单,并把宿主仓本地的 `plugins/index.json` 一起改掉(**记得提交那一处改动**)。它顺手打的 tag `style-source@1.3.0` **不会自动推**:`git push origin style-source@1.3.0`。
图标:宿主 `app.js` 的 `PLUGIN_ICONS` 可加 `'style-source': 'palette'`(不加则用面板 manifest 自带的 `palette`,效果一致)。
## 数据结构(上游 styles.json)
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@iwb-plugin/style-source",
"private": true,
"version": "1.3.0",
"version": "1.3.1",
"description": "风格库:资源库面板里浏览 310 个 AI 绘画风格(12 分类 / 搜索 / 变量替换),一键把预览图插入画布 ref 节点、把提示词插入 prompt 节点",
"ibwPlugin": {
"id": "style-source",
+10 -1
View File
@@ -614,6 +614,9 @@
// 变量输入框一旦被重建,每敲一个字就会失焦。
// 所以这里做「建一次骨架 + 之后只同步值」。
function renderStyleNode(node, props, host) {
// 兜底:万一节点体先于 setup 渲染(宿主注册表现在支持「注册后立刻重画」),
// 这一句保证样式一定在 —— 少一次注入就是「缩略图铺满节点」那种事故。
ensureStyle()
let st = host.__ssn
if (!st) {
host.textContent = ''
@@ -1365,7 +1368,7 @@
global.IWBPluginHost.register({
id: 'style-source',
name: '风格库',
version: '1.3.0',
version: '1.3.1',
apiVersion: 1,
capabilities: ['panels', 'canvas', 'canvasWrite', 'nodeTypes'],
settings: {
@@ -1397,6 +1400,12 @@
// 样式节点变体(v1.3.0)。注意能力名是 nodeTypes、但挂在 ctx 上的 key 是 `nodes`
// (plugin-host.js 的 CAPABILITY_API_KEYS:nodeTypes → 'nodes'),写成 ctx.nodeTypes 会静默失效。
// 不传 run ⇒ 节点上不会出现「运行」按钮(用户明确要求:出图交给下游生图节点)。
//
// v1.3.1(2026-11-14,用户报障「图片都跑出来了」):CSS 原先进在 `mount()` 里 ——
// 只有打开过「风格库」面板才会注入。但从存档打开画布时,节点体先渲染、面板根本不 mount ⇒
// 节点里的 `<img class="iwb-ssn-thumb">` 拿不到 56px 约束,按原图尺寸铺满整个节点。
// 现在在注册变体前就把样式注入(mount 里那次是幂等兜底)。
ensureStyle()
if (ctx.nodes && typeof ctx.nodes.register === 'function') {
ctx.nodes.register({
id: 'style',
+28 -3
View File
@@ -64,7 +64,7 @@ async function main() {
await page.goto(`http://127.0.0.1:${port}/`)
await page.evaluate(() => {
window.__calls = { panels: [], images: [], nodes: [] }
window.__calls = { panels: [], images: [], nodes: [], variants: [] }
window.__nodes = [{ id: 'n1', type: 'prompt', x: 100, y: 100, data: { text: 'x' } }]
window.__sel = { id: 'n1', type: 'prompt', name: 'x' }
window.IWBPluginHost = { register(m, s) { window.__m = m; window.__s = s } }
@@ -77,6 +77,8 @@ async function main() {
settings: { get: (k) => (window.__m.settings[k] || {}).default },
storage: null,
ui: { registerPanel: (p) => window.__calls.panels.push(p) },
// v1.3.0:样式节点变体(宿主能力名 nodeTypes → ctx.nodes)
nodes: { register: (v) => { window.__calls.variants.push(v); return true } },
canvas: {
getNodes: () => window.__nodes,
getSelectedNode: () => window.__sel,
@@ -99,7 +101,8 @@ async function main() {
check('真实网络拉到数据并渲染卡片', Boolean(gotData), 'cards=' + gotData)
const status = await page.locator('#h .iwb-ss-status').innerText().catch(() => '')
check('总数显示 310', /310/.test(status), status.replace(/\n/g, ' '))
// 数量随上游数据增长会变(310 → 367);这里只要求「显示的是三位数总量」
check('总数显示三位数风格条数', /\b[1-9]\d{2}\b/.test(status), status.replace(/\n/g, ' '))
// 真实缩略图必须真的解码出来
const decoded = await poll(async () => {
@@ -114,12 +117,34 @@ async function main() {
// 真实 webp → dataURL
await page.locator('#h .iwb-ss-card').first().click()
await page.waitForTimeout(300)
await page.locator('#h .iwb-ss-dfoot .iwb-ss-btn').first().click()
await page.locator('#h .iwb-ss-dfoot .iwb-ss-btn').filter({ hasText: '插入参考图' }).click()
const img = await poll(() => page.evaluate(() => window.__calls.images[0] || null), 30000)
check('真实图插入画布(createImageNode 被调用)', Boolean(img))
check('dataURL 是真实内容而非空图', Boolean(img) && String(img.dataUrl).length > 5000,
img ? 'len=' + String(img.dataUrl).length + ' head=' + String(img.dataUrl).slice(0, 22) : '')
// v1.3.0:样式节点(真实数据 + 真实模板)
const styleCall = await page.evaluate(async () => {
const v = window.__calls.variants[0]
const btn = [...document.querySelectorAll('#h .iwb-ss-dfoot .iwb-ss-btn')].find((b) => b.textContent === '样式节点')
if (!btn) return { noBtn: true }
window.__calls.nodes.length = 0
btn.click()
await new Promise((r) => setTimeout(r, 60))
return { hasRender: typeof v.render === 'function', ports: v.ports, call: window.__calls.nodes[0] || null }
})
check('详情页有「样式节点」按钮,且变体已注册(render + 只出不入)',
!styleCall.noBtn && styleCall.hasRender === true && styleCall.ports.in === false && styleCall.ports.out === true,
JSON.stringify({ noBtn: styleCall.noBtn, hasRender: styleCall.hasRender, ports: styleCall.ports }))
check('样式节点落的是 plugin:style-source:style,数据带 outKind/promptTpl/varMeta',
Boolean(styleCall.call) && styleCall.call.t === 'plugin:style-source:style' &&
styleCall.call.d.outKind === 'prompt' && typeof styleCall.call.d.promptTpl === 'string' &&
Array.isArray(styleCall.call.d.varMeta),
styleCall.call ? 't=' + styleCall.call.t + ' varMeta=' + (styleCall.call.d.varMeta || []).length : '未调用')
check('未填变量时 text 原样保留 {占位符}(不是被替换成空串)',
Boolean(styleCall.call) && (styleCall.call.d.varMeta.length === 0 || /\{[^{}\n]{1,40}\}/.test(String(styleCall.call.d.text))),
styleCall.call ? 'text=' + String(styleCall.call.d.text).slice(0, 48) : '未调用')
check('无 GitHub 资源请求失败', netFail.length === 0, netFail.slice(0, 2).join(' | '))
check('无页面 JS 异常', errors.length === 0, errors.slice(0, 2).join(' | '))
+283
View File
@@ -0,0 +1,283 @@
// 真机验收:**测试站上「宿主新接口 + 本插件」端到端**跑通(harness / e2e-real 都覆盖不到的那一层)。
//
// 为什么单独一支:
// - `tools/harness.mjs` 跑在合成宿主里,验不了「宿主的 PluginDomBody / 声明式参考图」是否真的接上;
// - `tools/e2e-real.mjs` 验的是「线上真网 + 插件面板」,不去点画布、不落节点。
// 这支脚本在**真的 test 站**里:双击进工作台 → 开资源库 → 点风格 → 点「样式节点」→ 检查节点体与输入体验。
//
// 用法:
// node tools/e2e-test-site.mjs # 默认 https://test.image-workbench-web.pages.dev/
// SITE=https://xxx.pages.dev/ node tools/e2e-test-site.mjs
// HEADED=1 node tools/e2e-test-site.mjs # 看着它跑
//
// 前置:宿主已部署含「插件节点体 + 声明式参考图」的版本,且 style-source 已在 KV 清单里。
// 全程只读:不动线上数据,浏览器用一次性 profile(跑完即弃)。
import { createRequire } from 'node:module'
import path from 'node:path'
import fs from 'node:fs'
const HERE = path.dirname(new URL(import.meta.url).pathname)
let chromium = null
for (const base of [path.resolve(HERE, '../..'), path.resolve(HERE, '../../../image-workbench-web'), process.cwd()]) {
const pkg = path.join(base, 'package.json')
if (!fs.existsSync(pkg)) continue
try { chromium = createRequire(pkg)('playwright').chromium; break } catch { /* 换下一个 */ }
}
if (!chromium) {
console.error('找不到 playwright:请在插件仓根目录或宿主仓(image-workbench-web)里跑')
process.exit(2)
}
const SITE = process.env.SITE || 'https://test.image-workbench-web.pages.dev/'
let failed = 0
const check = (name, ok, detail) => {
if (!ok) failed++
console.log((ok ? '✓ ' : '✗ ') + name + (detail ? ' ' + detail : ''))
}
const shot = (name) => page.screenshot({ path: path.join(HERE, 'shot-testsite-' + name + '.png') }).catch(() => {})
const proxy = process.env.HTTPS_PROXY || process.env.https_proxy || process.env.HTTP_PROXY || process.env.http_proxy
const browser = await chromium.launch({
headless: process.env.HEADED !== '1',
...(proxy ? { proxy: { server: proxy } } : {}),
})
const page = await browser.newPage({ viewport: { width: 1440, height: 900 } })
const errors = []
page.on('pageerror', (e) => errors.push(String(e)))
await page.goto(SITE, { waitUntil: 'domcontentloaded' })
await page.waitForTimeout(1200)
// 启停状态只落 localStorage['iwb_plugins'](真机同款键)
await page.evaluate(() => {
localStorage.setItem('iwb_plugins', JSON.stringify({ 'style-source': { enabled: true, settings: {}, data: {} } }))
})
await page.reload({ waitUntil: 'domcontentloaded' })
await page.waitForTimeout(4000)
// ── 1. 宿主版本:三处新接口的特征串(压缩后函数名会变,只能查字符串) ──────────
const host = await page.evaluate(async () => {
const src = await (await fetch('/app.js', { cache: 'no-store' })).text()
const ver = await (await fetch('/version.json', { cache: 'no-store' })).json().catch(() => ({}))
return {
pluginBody: src.includes('iwb-plugin-node-body'),
selfRef: src.includes('style-ref.png'),
combineTag: src.includes('iwb-combine-src-tag'),
version: ver.version || '',
len: src.length,
}
})
check('测试站 app.js 含插件节点体 + 声明式参考图 + 组合来源标签', host.pluginBody && host.selfRef && host.combineTag,
JSON.stringify({ version: host.version, len: host.len }))
// ── 2. 插件已启用并激活 ───────────────────────────────────────────────────
const list = await page.evaluate(() => {
const h = window.IWBPluginHost
if (!h) return { noHost: true }
const l = typeof h.list === 'function' ? h.list() : []
return { list: l.map((p) => ({ id: p.id, version: p.version, enabled: p.enabled, active: p.active, error: p.error })) }
})
const me = (list.list || []).find((p) => p.id === 'style-source')
check('style-source 已启用并激活', Boolean(me && me.active), JSON.stringify(me))
// ── 3. 进工作台(首页卡片是「双击打开」,单击只是选中) ──────────────────────
await page.locator('.iwb-home-card').first().dblclick({ timeout: 8000 })
await page.waitForTimeout(3000)
const entered = await page.evaluate(() => ({ cards: document.querySelectorAll('.iwb-home-card').length }))
check('双击首页卡片进入画布', entered.cards === 0, JSON.stringify(entered))
// ── 4. 资源库 → 风格库 tab(N 是宿主「开关资源库」的快捷键) ──────────────────
await page.evaluate(() => { const a = document.activeElement; if (a && a.blur) a.blur() })
await page.keyboard.press('n')
await page.waitForTimeout(1200)
const tabs = await page.evaluate(() => [...document.querySelectorAll('.iwb-res-tab')].map((b) => (b.textContent || '').trim()))
await page.evaluate(() => {
const hit = [...document.querySelectorAll('.iwb-res-tab')].find((b) => /风格库/.test(b.textContent || ''))
if (hit) hit.click()
})
check('资源库里有「风格库」tab', tabs.includes('风格库'), JSON.stringify(tabs))
// 风格数据是直连 GitHub Pages 拉的,首次没缓存时快时慢 ⇒ 轮询,别写死等待
await page.waitForFunction(() => document.querySelectorAll('.iwb-ss-card').length > 0, null, { timeout: 30000 }).catch(() => {})
await page.waitForTimeout(300)
const cards = await page.locator('.iwb-ss-card').count()
check('风格库渲染出卡片', cards > 0, String(cards))
// ── 5. 详情页底部三颗按钮:同行、均分、「样式节点」在最左(不是替换掉原来两颗) ──
await page.locator('.iwb-ss-card').first().click()
await page.waitForTimeout(900)
const footInfo = await page.evaluate(() => {
const btns = [...document.querySelectorAll('.iwb-ss-dfoot .iwb-ss-btn')]
return { labels: btns.map((b) => (b.textContent || '').trim()), tops: btns.map((b) => Math.round(b.getBoundingClientRect().top)) }
})
check('详情页底部三颗按钮同行,「样式节点」在最左',
footInfo.labels.length === 3 && footInfo.labels[0] === '样式节点' && new Set(footInfo.tops).size <= 1,
JSON.stringify(footInfo))
// ── 6. 点「样式节点」→ 节点落地,节点体由插件渲染 ─────────────────────────────
await page.locator('.iwb-ss-dfoot .iwb-ss-btn').filter({ hasText: '样式节点' }).first().click()
await page.waitForTimeout(1600)
await page.keyboard.press('Escape')
await page.waitForTimeout(400)
await page.keyboard.press('f')
await page.waitForTimeout(700)
await shot('node')
const node1 = await page.evaluate(() => {
const b = document.querySelector('.iwb-plugin-node-body')
if (!b) return { bodies: 0 }
const rows = [...b.querySelectorAll('.iwb-ssn-row')]
return {
bodies: document.querySelectorAll('.iwb-plugin-node-body').length,
hasRoot: Boolean(b.querySelector('.iwb-ssn')),
name: (b.querySelector('.iwb-ssn-name') || {}).textContent || '',
code: (b.querySelector('.iwb-ssn-code') || {}).textContent || '',
rows: rows.length,
refChecked: b.querySelector('.iwb-ssn-ref input') ? b.querySelector('.iwb-ssn-ref input').checked : null,
hasRunBtn: [...b.querySelectorAll('button')].some((x) => /运行|生成/.test(x.textContent)),
foot: (b.querySelector('.iwb-ssn-foot') || {}).textContent || '',
}
})
check('样式节点落地且节点体由插件渲染(.iwb-ssn 存在)', node1.hasRoot === true, JSON.stringify(node1).slice(0, 300))
check('节点体有名称/编号/变量行,示例图默认勾选,且没有生成按钮',
Boolean(node1.name) && Boolean(node1.code) && node1.refChecked === true && node1.hasRunBtn === false,
JSON.stringify(node1).slice(0, 300))
// ── 7. 变量输入不失焦、值不被重渲染覆盖(PluginDomBody 固定容器生效) ─────────
const typing = await page.evaluate(async () => {
const b = document.querySelector('.iwb-plugin-node-body .iwb-ssn')
const input = b && b.querySelector('.iwb-ssn-row input')
if (!input) return { noBody: true }
input.focus()
input.value = '真机测试值'
input.dispatchEvent(new Event('input', { bubbles: true }))
await new Promise((r) => setTimeout(r, 700))
const b2 = document.querySelector('.iwb-plugin-node-body .iwb-ssn')
const input2 = b2.querySelector('.iwb-ssn-row input')
return { sameInput: input === input2, kept: input2.value, focusKept: document.activeElement === input2 }
})
check('变量输入不失焦、值不被重渲染覆盖',
typing.sameInput === true && typing.kept === '真机测试值' && typing.focusKept === true, JSON.stringify(typing))
// ── 8. 变量多的样式:全部露出、不裁切、单行 28px、收起/展开生效 ──────────────
// 上一步把焦点留在了变量输入框里;宿主的快捷键在 INPUT 上直接 return ⇒ 先 blur,否则按 n 只会打出一个字母
await page.evaluate(() => { const a = document.activeElement; if (a && a.blur) a.blur() })
await page.keyboard.press('n')
await page.waitForTimeout(1200)
await page.evaluate(() => {
const hit = [...document.querySelectorAll('.iwb-res-tab')].find((b) => /风格库/.test(b.textContent || ''))
if (hit) hit.click()
})
await page.waitForFunction(() => document.querySelectorAll('.iwb-ss-card').length > 0, null, { timeout: 30000 }).catch(() => {})
let picked = null
const total = await page.locator('.iwb-ss-card').count()
for (let i = 0; i < Math.min(total, 30); i++) {
await page.locator('.iwb-ss-card').nth(i).click()
await page.waitForTimeout(380)
const info = await page.evaluate(() => ({
n: document.querySelectorAll('.iwb-ss-dbody .iwb-ss-var').length,
title: (document.querySelector('.iwb-ss-dtitle') || {}).textContent || '',
}))
if (info.n >= 3) { picked = { idx: i, ...info }; break }
}
check('能找到一个变量 ≥3 的样式(用于压力验证)', Boolean(picked), JSON.stringify(picked))
if (picked) {
await page.locator('.iwb-ss-dfoot .iwb-ss-btn').filter({ hasText: '样式节点' }).first().click()
await page.waitForTimeout(1600)
await page.keyboard.press('Escape')
await page.waitForTimeout(400)
await page.keyboard.press('f')
await page.waitForTimeout(700)
await shot('multivar')
const multi = await page.evaluate(() => {
const all = [...document.querySelectorAll('.iwb-plugin-node-body')]
const b = all[all.length - 1]
if (!b) return { noBody: true }
const rows = [...b.querySelectorAll('.iwb-ssn-row')]
return {
bodies: all.length,
rows: rows.length,
labels: rows.map((x) => ((x.querySelector('label') || {}).textContent || '')).filter(Boolean),
rowH: rows.length ? Math.round(rows[0].getBoundingClientRect().height) : 0,
hiddenRows: rows.filter((x) => x.getBoundingClientRect().height < 8).length,
scrollH: b.scrollHeight,
clientH: b.clientHeight,
}
})
check('变量多的样式:所有变量行都露出、无零高行', multi.rows >= 3 && multi.hiddenRows === 0, JSON.stringify(multi).slice(0, 320))
check('节点体没有裁切(scrollHeight ≈ clientHeight)', Math.abs(multi.scrollH - multi.clientH) <= 2,
JSON.stringify({ s: multi.scrollH, c: multi.clientH }))
check('变量单行高度 28px 量级', multi.rowH >= 24 && multi.rowH <= 32, String(multi.rowH))
const collapsed = await page.evaluate(async () => {
const all = [...document.querySelectorAll('.iwb-plugin-node-body')]
const b = all[all.length - 1]
const btn = b && b.querySelector('.iwb-ssn-toggle')
if (!btn) return { noBtn: true }
const before = Math.round(b.querySelector('.iwb-ssn-vars').getBoundingClientRect().height)
btn.click()
await new Promise((r) => setTimeout(r, 500))
const box = b.querySelector('.iwb-ssn-vars')
return { before, after: Math.round(box.getBoundingClientRect().height), hidden: box.classList.contains('is-hidden'), tip: btn.title }
})
check('「收起变量」生效(变量区收起,按钮变成「展开变量」)',
collapsed.hidden === true && collapsed.after === 0 && collapsed.tip === '展开变量', JSON.stringify(collapsed))
await shot('collapsed')
}
// ── 9. 冷启动:**一次都没打开过「风格库」面板**,节点体也必须是有样式的 ──────────────
// v1.3.1 修的事故:CSS 原先进在 mount() 里,从存档打开画布时面板不 mount ⇒ `<img class="iwb-ssn-thumb">`
// 拿不到 56px 约束,按原图尺寸铺满整个节点(用户原话「图片都跑出来了」)。
{
const COLD_NODE = {
id: 'cold1', type: 'plugin:style-source:style', x: 260, y: 200, w: 300, h: 380,
data: {
variant: 'style', styleId: 'cold-style', name: '冷启动样式', code: 'ST9999', outKind: 'prompt',
promptTpl: '一张{主体}的图', varMeta: [{ key: '主体', label: '主体' }], vars: { 主体: '手表' },
text: '一张手表的图', preview: 'https://example.invalid/cold.png', refName: 'ST9999.png',
refOn: true, refUrl: 'https://example.invalid/cold.png', collapsed: false,
},
}
const ws = { workspaces: [{ id: 'w1', name: '冷启动', nodes: [COLD_NODE], edges: [], groups: [] }], activeId: 'w1', rev: 1 }
const ctx2 = await browser.newContext({ viewport: { width: 1400, height: 900 } })
const p2 = await ctx2.newPage()
await p2.addInitScript(({ ws, board }) => {
localStorage.clear()
localStorage.setItem('iwb_plugins', JSON.stringify({ 'style-source': { enabled: true, settings: {}, data: {} } }))
localStorage.setItem('iwb_web_workspaces', JSON.stringify(ws))
localStorage.setItem('iwb_ws_active', 'w1')
localStorage.setItem('iwb_ws_w1', JSON.stringify(board))
}, { ws, board: ws.workspaces[0] })
await p2.goto(SITE, { waitUntil: 'domcontentloaded' })
await p2.waitForTimeout(1500)
await p2.locator('.iwb-home-card:not(.iwb-home-new)').first().dblclick().catch(() => {})
await p2.waitForFunction(() => Boolean(document.querySelector('.iwb-plugin-node-body')), null, { timeout: 20000 }).catch(() => {})
const cold = await p2.evaluate(() => {
const th = document.querySelector('.iwb-ssn-thumb')
const body = document.querySelector('.iwb-plugin-node-body')
const node = document.querySelector('.iwb-node')
return {
hasBody: Boolean(body),
hasStyle: Boolean(document.getElementById('iwb-ss-style')),
thumbW: th ? Math.round(th.getBoundingClientRect().width) : 0,
thumbH: th ? Math.round(th.getBoundingClientRect().height) : 0,
nodeW: node ? Math.round(node.getBoundingClientRect().width) : 0,
}
})
check('冷启动(没开过风格库):节点体成立 + 样式已注入', cold.hasBody && cold.hasStyle, JSON.stringify(cold))
check('冷启动:缩略图被 CSS 约束在 56px(不是按原图铺满节点)',
cold.thumbW >= 40 && cold.thumbW <= 62 && cold.thumbH >= 40 && cold.thumbH <= 62,
JSON.stringify({ w: cold.thumbW, h: cold.thumbH, nodeW: cold.nodeW }))
await p2.screenshot({ path: path.join(HERE, 'shot-testsite-coldstart.png') }).catch(() => {})
await ctx2.close()
}
check('全程无页面 JS 异常', errors.length === 0, errors.slice(0, 3).join(' | '))
await browser.close()
console.log('')
console.log(failed === 0 ? '全部通过' : failed + ' 项失败')
process.exit(failed === 0 ? 0 : 1)