Files

59 lines
3.6 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// v3.87.26 契约:
// ① 2K/4K 时 size 必须照常发出(自动=不发,但显式档位不能丢)
// ② 画布顶部栏「内存 / 规模」实时信息存在,且点击直接打开 设置→诊断
const { test, expect } = require('./_pw-coverage')
const baseURL = process.env.IWB_BASE_URL || 'http://127.0.0.1:8787'
test.use({ baseURL, viewport: { width: 1600, height: 1000 } })
const CFG = { providers: [{ id: 'p-a', name: 'A', baseUrl: 'https://a.example/v1', keys: [{ id: 'a-1', name: 'K', value: 'sk' }], models: [{ name: 'gpt-image-2.5', visible: true }] }], canvas: { snap: true } }
const mkWs = (res) => ({ schemaVersion: 1, rev: 1, activeId: 'w1', workspaces: [{ id: 'w1', name: 'W', nodes: [
{ id: 'p1', type: 'prompt', x: 80, y: 80, w: 320, data: { text: 'a cat' } },
{ id: 'g1', type: 'gen', x: 480, y: 80, w: 420, data: { model: 'gpt-image-2.5', provider: 'p-a', keyGroup: 'a-1', ratio: '9:16', res, size: '1440x2560', custom: false, customSize: '', quality: 'auto' } },
], edges: [{ id: 'e1', from: 'p1', to: 'g1' }], groups: [] }] })
async function boot(page, res) {
const bodies = []
await page.route('**/images/generations', async (route) => {
try { bodies.push(JSON.parse(route.request().postData() || '{}')) } catch (e) { bodies.push({ parseError: true }) }
await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ data: [{ url: 'https://example.com/a.png', width: 1440, height: 2560 }] }) })
})
await page.addInitScript((d) => {
localStorage.clear()
localStorage.setItem('iwb_web_cfg', JSON.stringify(d.cfg))
localStorage.setItem('iwb_web_workspaces', JSON.stringify(d.ws))
localStorage.setItem('iwb_ws_active', 'w1')
localStorage.setItem('iwb_ws_w1', JSON.stringify(d.ws.workspaces[0]))
}, { cfg: CFG, ws: mkWs(res) })
await page.goto('/', { waitUntil: 'domcontentloaded' })
await page.waitForTimeout(800)
await page.locator('.iwb-home-card:not(.iwb-home-new)').first().dblclick()
await expect(page.locator('.iwb-canvas:not(.iwb-canvas-hidden)')).toBeVisible()
await page.waitForTimeout(400)
return bodies
}
test('显式 2K 档位必须照常发送 size(回归守卫)', async ({ page }) => {
const bodies = await boot(page, '2K')
await page.locator('[data-node-id="g1"] button', { hasText: '生成' }).first().click()
expect(bodies.length).toBeGreaterThanOrEqual(1)
expect(String(bodies[0].size || ''), '9:16 的 2K 应为 1440x2560').toBe('1440x2560')
})
test('顶部栏「内存/规模」实时信息存在,点击直接打开诊断', async ({ page }) => {
const errors = []
page.on('pageerror', (e) => errors.push(String((e && e.message) || e)))
await boot(page, 'auto')
const chip = page.locator('.iwb-status-mem')
await expect(chip).toBeVisible()
const text = (await chip.textContent()) || ''
expect(text, '格式简洁:内存 X/YMB Z%(v3.1.0 已去节点/板/图尾巴)').toMatch(/^内存\s*\d+\/\d+MB\s*\d+%$/)
// 规模信息独立成状态项,仍是实时值(种子画板 2 节点 / 1 连线)
const meta = (await page.locator('.iwb-canvas-meta').textContent()) || ''
expect(meta, '节点/连线应为真实值(种子画板 2 节点 / 1 连线)').toMatch(/2\s*节点\s*\/\s*1\s*连线/)
expect(meta, '不得出现全 0 的规模信息').not.toMatch(/0\s*节点\s*\/\s*0\s*连线/)
// 点击 → 设置面板落在「诊断」页
await chip.click()
await expect(page.getByText('运行诊断').first()).toBeVisible({ timeout: 5000 })
await expect(page.getByText('崩溃 / 错误记录', { exact: false }).first()).toBeVisible({ timeout: 5000 })
expect(errors).toEqual([])
})