Files
image-workbench-desktop/tests/iwb-size-auto.spec.js
T

41 lines
3.0 KiB
JavaScript
Raw 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.25 契约:分辨率选「自动」时,请求里的 size 不能被子虚乌有地降成 1K。
// 旧 bug:策略模块 normalizeResolution 对 'auto' 回落到 '1K',而 standardSizeOf() 正是实际发出的尺寸 →
// 选「自动」会主动发 1K(表现为"某些模型只能出 1K")。本用例断言:发的是节点里保存的尺寸。
const { test, expect } = require('./_pw-coverage')
const baseURL = process.env.IWB_BASE_URL || 'http://127.0.0.1:8787'
test.use({ baseURL, viewport: { width: 1440, 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: 'gemini-3.1-flash-image-preview', visible: true }] }], canvas: { snap: true } }
// 9:16 的 2K 是 1440x2560;res 故意设为「自动」,size 保存为 2K
const ws = { 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: 'gemini-3.1-flash-image-preview', provider: 'p-a', keyGroup: 'a-1', ratio: '9:16', res: '2K', size: '1440x2560', custom: false, customSize: '', quality: 'auto' } },
], edges: [{ id: 'e1', from: 'p1', to: 'g1' }], groups: [] }] }
test('gemini 族:size=比例(9x16)、quality=K 档(2k),不发像素尺寸', async ({ page }) => {
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 })
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)
// 点该 gen 节点任务条上的「生成」
const btn = page.locator('[data-node-id="g1"] button', { hasText: '生成' }).first()
await btn.click()
expect(bodies.length, '应发出一次生图请求').toBeGreaterThanOrEqual(1)
// v3.87.28:gemini 族按渠道文档 —— size 表示比例、quality 表示分辨率档
expect(bodies[0].size, 'gemini 族 size 应为比例 9x16').toBe('9x16')
expect(bodies[0].quality, 'gemini 族 quality 应为 K 档 2k').toBe('2k')
expect(String(bodies[0].size), '不得发像素尺寸').not.toBe('1440x2560')
expect(bodies[0].model, '模型应照常发送').toBe('gemini-3.1-flash-image-preview')
})