根因(trace 定位,6 条同一原因): 首页视图里启动 fit 早于停靠栏挂载(--iwb-dock-l 首帧为空)⇒ 算出 ins=0 的坏视口 (实测 translate(-92,-84));这份坏值被 useViewportPersistence 落盘,打开画布时又被当作 「用户保存的视口」恢复 ⇒ 节点停在 x=29(压在 318px 左栏下),dblclick 命中浏览器面板的 .iwb-cwv-url / .iwb-cwv-empty,Playwright 重试到 30s 超时。 修法:flushViewport 增加 insetsReady 门槛(--iwb-dock-l 为空串时跳过落盘); 画布打开后 loadWsInto 走 doFit,此时占位就绪,落盘的是正确视口。 4 条用例按现 UI 修正: - tooltip-labels ②:单选气泡现为 改名/复制/删除/添加到提示词库…(收藏只在多选气泡) - image-original:收藏入口已收进「选中操作 ▸」子菜单(且需先选中节点) - resume-scope:运行入口已收进「该节点 ▸」子菜单 - download-cors:同源代理 /api/img 已随网页版删除,桌面走原生 HTTP 另存为 ⇒ 该条标 fixme(需 Tauri 环境) 验证: - 组 A(typing-perf / storage-incremental / close-flush / history-sweep)6/6 绿 - 组 B(image-original / resize-perf / tooltip-labels / resume-scope / download-cors)12/12 绿 - verify:ci 全绿(facts 数字已 sync) - 已知红基线 17 → 7 条(只剩 clipboard-audit 3 + image-memory-parity 4,均为环境限制)
83 lines
5.6 KiB
JavaScript
83 lines
5.6 KiB
JavaScript
// v3.87.34 契约:CORS 受限图床(豆包/火山 TOS)也能下载 —— 走图片代理兜底并真的触发下载
|
||
const { test, expect } = require('./_pw-coverage')
|
||
const W = require('./_helpers/wait')
|
||
const baseURL = process.env.IWB_BASE_URL || 'http://127.0.0.1:8787'
|
||
test.use({ baseURL, viewport: { width: 1440, height: 1000 }, acceptDownloads: true })
|
||
const PNG = Buffer.from('89504e470d0a1a0a0000000d49484452000000010000000108060000001f15c4890000000a49444154789c6360000002000100ffff03000006000557bfabd40000000049454e44ae426082', 'hex')
|
||
// 2026-11-27:同源代理 /api/img 已随网页版一起删除(见 app.js downloadUrl 的注释),
|
||
// 桌面端改走「原生 HTTP 取图 → 系统另存为」,web e2e(无 Tauri)只能落到「新标签打开」,不会触发 download 事件。
|
||
// 该能力需在 Tauri 环境验收,web 侧暂挂。
|
||
test.fixme('直连失败的图床(403/无 CORS):经图片代理下载成功(需桌面环境)', async ({ page }) => {
|
||
let proxyHits = 0
|
||
await page.route('**/cdn.example.com/**', async (route) => {
|
||
// 确定性失败(等价于火山 TOS 的 403/无 CORS 头):直连必然拿不到图
|
||
await route.fulfill({ status: 403, contentType: 'text/plain', body: 'blocked' })
|
||
})
|
||
// 本站同源代理(生产由 functions/api/img.js 实现;e2e 里直接拦截该路径)
|
||
await page.route('**/api/img?**', async (route) => {
|
||
proxyHits++
|
||
await route.fulfill({ status: 200, contentType: 'image/png', headers: { 'Access-Control-Allow-Origin': '*' }, body: PNG })
|
||
})
|
||
await page.addInitScript(() => { localStorage.clear() })
|
||
await page.goto('/', { waitUntil: 'domcontentloaded' })
|
||
await page.waitForTimeout(700)
|
||
// 直接调用应用的下载函数(与预览/图库/自动保存共用同一实现)
|
||
const dl = page.waitForEvent('download', { timeout: 15000 })
|
||
await page.evaluate(() => window.__IWB_E2E_DOWNLOAD__('https://cdn.example.com/tos-blocked.png', 'doubao.png'))
|
||
const d = await dl
|
||
expect(d.suggestedFilename()).toBe('doubao.png')
|
||
expect(proxyHits, 'CORS 失败后应走本站同源代理(/api/img)').toBeGreaterThanOrEqual(1)
|
||
})
|
||
|
||
// v3.24.64(用户 2026-11-11 实测):上游已会返回 .svg,而下载入口一律传 'image.png' 这类硬编码名。
|
||
// 契约:下载名后缀必须跟着**真实格式**走,不得把矢量内容存成 .png。
|
||
test('SVG 结果:下载名后缀跟着真实格式(不再写死 .png)', async ({ page }) => {
|
||
const SVG = Buffer.from('<?xml version="1.0" encoding="UTF-8"?><svg xmlns="http://www.w3.org/2000/svg" width="64" height="32"><rect width="64" height="32" fill="#0af"/></svg>', 'utf8')
|
||
await page.route('**/cdn.example.com/**', async (route) => {
|
||
await route.fulfill({ status: 200, contentType: 'image/svg+xml', headers: { 'Access-Control-Allow-Origin': '*' }, body: SVG })
|
||
})
|
||
await page.addInitScript(() => { localStorage.clear() })
|
||
await page.goto('/', { waitUntil: 'domcontentloaded' })
|
||
await page.waitForFunction(() => typeof window.__IWB_E2E_DOWNLOAD__ === 'function')
|
||
const dl = page.waitForEvent('download', { timeout: 15000 })
|
||
await page.evaluate(() => window.__IWB_E2E_DOWNLOAD__('https://cdn.example.com/gen-1.svg', 'image.png'))
|
||
const d = await dl
|
||
expect(d.suggestedFilename()).toBe('image.svg')
|
||
})
|
||
|
||
// v3.24.65(用户 2026-11-11 实测):图库 / 大图预览 / 输出缩略图传进下载入口的是**本站自建的
|
||
// objectURL**(`blob:...`,字符串里只有 uuid,没有任何格式线索)⇒ 此前一律退回硬编码的 .png。
|
||
// 契约:blob: 地址必须从 Blob 注册表取回 type 再定后缀;且预览下载要拿**原图**而不是占位缩略图。
|
||
test('图库原图是 SVG:大图预览下载名 = image.svg(blob: 也按真实格式命名)', async ({ page }) => {
|
||
const svgText = '<svg xmlns="http://www.w3.org/2000/svg" width="64" height="32"><rect width="64" height="32" fill="#0af"/></svg>'
|
||
const svgDataUrl = 'data:image/svg+xml;base64,' + Buffer.from(svgText, 'utf8').toString('base64')
|
||
await page.addInitScript(() => {
|
||
localStorage.clear()
|
||
localStorage.setItem('iwb_web_workspaces', JSON.stringify({
|
||
workspaces: [{ id: 'ws_svgdl', name: 'SVG下载板', nodes: [], edges: [], groups: [] }],
|
||
activeId: 'ws_svgdl', rev: 1, schemaVersion: 1,
|
||
}))
|
||
// 索引条目形态照抄线上(storeOutputThumb):缩略图 jpeg/png 存 out_,原图存 out_orig_
|
||
localStorage.setItem('iwb_web_outputs', JSON.stringify([
|
||
{ name: 'svg_out.png', url: 'https://cdn.example.com/svg_out.svg', size: 300, mtime: Date.now(), w: 64, h: 32, idb: 'out_svg_out.png', origIdb: 'out_orig_svg_out.png' },
|
||
]))
|
||
})
|
||
await page.goto('/', { waitUntil: 'domcontentloaded' })
|
||
await page.waitForSelector('.iwb-home-card', { timeout: 25000 })
|
||
await page.locator('.iwb-home-card', { hasText: 'SVG下载板' }).first().dblclick()
|
||
await page.waitForSelector('.iwb-canvas-topbar', { timeout: 25000 })
|
||
await page.evaluate(async (dataUrl) => {
|
||
const c = document.createElement('canvas'); c.width = 64; c.height = 32
|
||
const g = c.getContext('2d'); g.fillStyle = '#2b7'; g.fillRect(0, 0, 64, 32)
|
||
const store = window.IWBStorageIndexedDB.create({})
|
||
await store.put('out_svg_out.png', c.toDataURL('image/png'))
|
||
await store.put('out_orig_svg_out.png', dataUrl)
|
||
}, svgDataUrl)
|
||
await W.openGallery(page, { waitItems: 15000 })
|
||
await page.locator('.iwb-history-item img').first().dblclick()
|
||
await page.waitForSelector('.iwb-imgpreview img', { timeout: 20000 })
|
||
const dl = page.waitForEvent('download', { timeout: 20000 })
|
||
await page.locator('.iwb-prev-bar button').filter({ hasText: '下载' }).click()
|
||
expect((await dl).suggestedFilename()).toBe('image.svg')
|
||
})
|