// v3.87.5:质量档位(quality)按「模型能力」开关 —— 默认自动,只有标记支持质量的模型才发送 // ① 已勾选支持的模型(gpt-image-2.5):浮层 6 档可选 → 选「最高」请求体带 quality=max // ② 未勾选的模型(gpt-image-2):非自动档位禁用 → 请求体**不含** quality 字段 // ③ 设置里手动勾上「质量」并保存 → 节点可选档位并发参数(默认不勾) // ④ 渠道 400:有界降级(max → xhigh),不会把整个模型拉黑 // 运行:npm run build && IWB_BASE_URL=http://127.0.0.1:8787 npx playwright test tests/iwb-quality-tier.spec.js 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 PIXEL = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8DwHwAFAAH/q842iQAAAABJRU5ErkJggg==', 'base64') const GEN_RESP = { created: 1, data: [{ url: 'https://cdn.example/out.png' }] } const CFG = { providers: [{ id: 'p-a', name: '服务商 A', baseUrl: 'https://a.example/v1', keys: [{ id: 'a-1', name: 'K1', value: 'sk-fake-for-e2e' }], // 两个模型:一个已手动勾选「质量」(gpt-image-2.5),一个没勾(gpt-image-2) models: [ { name: 'gpt-image-2.5', visible: true, source: 'custom', supportsQuality: true }, { name: 'gpt-image-2', visible: true, source: 'builtin' }, ], }], canvas: { snap: true }, } // 默认配置:两个模型都**没有**显式标记 → 质量勾选默认不勾、档位不可用(v3.87.5 起不做任何自动假定) const CFG_PLAIN = { providers: [{ id: 'p-a', name: '服务商 A', baseUrl: 'https://a.example/v1', keys: [{ id: 'a-1', name: 'K1', value: 'sk-fake-for-e2e' }], models: [ { name: 'gpt-image-2.5', visible: true, source: 'custom' }, { name: 'gpt-image-2', visible: true, source: 'builtin' }, ], }], canvas: { snap: true }, } const ws = (model) => ({ workspaces: [{ id: 'w1', name: 'W', nodes: [ { id: 'p1', type: 'prompt', x: 80, y: 60, data: { text: '测试质量档位' } }, { id: 'g1', type: 'gen', x: 420, y: 60, w: 480, data: { model, provider: 'p-a', keyGroup: 'a-1', size: '1024x1024', ratio: '1:1', res: '1K', quality: 'auto', align16: false, variants: 1, taskVariants: {} } }, ], edges: [{ id: 'e1', from: 'p1', to: 'g1' }], groups: [], }], activeId: 'w1', rev: 1, }) async function seed(page, model, cfg) { 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', d.ws.activeId) localStorage.setItem('iwb_ws_w1', JSON.stringify(d.ws.workspaces[0])) localStorage.setItem('iwb_web_outputs', JSON.stringify([])) }, { cfg: cfg || CFG, ws: ws(model) }) await page.goto('/', { waitUntil: 'domcontentloaded' }) await page.waitForTimeout(700) await page.locator('.iwb-home-card:not(.iwb-home-new)').first().dblclick() await expect(page.locator('.iwb-canvas:not(.iwb-canvas-hidden)')).toBeVisible() } // 打开该节点的「图像设置」浮层并返回 6 个质量 chip async function openQualityPanel(page) { await page.locator('[data-node-id="g1"] .iwb-gen-summary').click() const panel = page.locator('.iwb-image-settings') await expect(panel).toBeVisible() const group = panel.locator('.iwb-setgroup').first() const chips = group.locator('.iwb-chip') await expect(chips).toHaveCount(6) return { panel, chips } } async function runGen(page) { await page.locator('[data-node-id="g1"] .iwb-task button:has-text("生成")').first().click() } test('已勾选「质量」的模型(gpt-image-2.5):6 档可选,选「最高」→ quality=max', async ({ page }) => { const errors = [] page.on('pageerror', (e) => errors.push(String((e && e.message) || e))) const bodies = [] await page.route('**/images/generations', async (route) => { try { bodies.push(JSON.parse(route.request().postData() || '{}')) } catch (e) { bodies.push({ parseError: String(e) }) } await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(GEN_RESP) }) }) await page.route('https://cdn.example/**', (route) => route.fulfill({ status: 200, contentType: 'image/png', headers: { 'access-control-allow-origin': '*' }, body: PIXEL })) await seed(page, 'gpt-image-2.5') const { panel, chips } = await openQualityPanel(page) // 6 档全部可用(含 xhigh/max),且都在同一行内不溢出面板 for (const label of ['自动', '快速', '标准', '高清', '极高', '最高']) { const c = chips.filter({ hasText: label }).first() await expect(c).toBeEnabled() } const overflow = await panel.locator('.iwb-setgroup').first().evaluate((el) => el.scrollWidth - el.clientWidth) expect(overflow, '质量组不应横向溢出(放不下应换行)').toBeLessThanOrEqual(1) await chips.filter({ hasText: '最高' }).first().click() // 档位越高越慢:title 里要有说明 await expect(chips.filter({ hasText: '最高' }).first()).toHaveAttribute('title', /计费|越慢/) await page.keyboard.press('Escape') await runGen(page) await expect.poll(() => bodies.length).toBeGreaterThan(0) expect(bodies[0].quality, '种子命中的模型必须真的发送 quality').toBe('max') expect(errors).toEqual([]) }) test('未勾选「质量」的模型(gpt-image-2):档位禁用且请求体不含 quality', async ({ page }) => { const errors = [] page.on('pageerror', (e) => errors.push(String((e && e.message) || e))) const bodies = [] await page.route('**/images/generations', async (route) => { try { bodies.push(JSON.parse(route.request().postData() || '{}')) } catch (e) { bodies.push({ parseError: String(e) }) } await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(GEN_RESP) }) }) await page.route('https://cdn.example/**', (route) => route.fulfill({ status: 200, contentType: 'image/png', headers: { 'access-control-allow-origin': '*' }, body: PIXEL })) await seed(page, 'gpt-image-2') const { panel, chips } = await openQualityPanel(page) // 非自动档位全部禁用,只有「自动」可点 for (const label of ['快速', '标准', '高清', '极高', '最高']) { await expect(chips.filter({ hasText: label }).first()).toBeDisabled() } await expect(chips.filter({ hasText: '自动' }).first()).toBeEnabled() await expect(panel.getByText(/当前模型不支持质量档位/)).toBeVisible() // 汇总条如实显示「自动」 await page.keyboard.press('Escape') await expect(page.locator('[data-node-id="g1"] .iwb-gen-summary')).toContainText('自动') await runGen(page) await expect.poll(() => bodies.length).toBeGreaterThan(0) expect('quality' in bodies[0], '不支持的模型必须根本不发 quality').toBe(false) expect(errors).toEqual([]) }) test('设置里手动勾选「质量」并保存:节点即可选档位并发参数(默认一个都不勾)', async ({ page }) => { const errors = [] page.on('pageerror', (e) => errors.push(String((e && e.message) || e))) const bodies = [] await page.route('**/images/generations', async (route) => { try { bodies.push(JSON.parse(route.request().postData() || '{}')) } catch (e) { bodies.push({ parseError: String(e) }) } await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(GEN_RESP) }) }) await page.route('https://cdn.example/**', (route) => route.fulfill({ status: 200, contentType: 'image/png', headers: { 'access-control-allow-origin': '*' }, body: PIXEL })) await seed(page, 'gpt-image-2', CFG_PLAIN) // 打开设置 → 生图服务:默认**一个都没勾**(含 gpt-image-2.5),勾选完全手动 await page.locator('.iwb-top-nav-icon[title="服务与 Key 设置"]').click() const modal = page.locator('.iwb-settings-modal') await expect(modal).toBeVisible() await expect(modal.locator('.iwb-modelrow-q input[aria-label="支持质量 gpt-image-2.5"]')).not.toBeChecked() const q = modal.locator('.iwb-modelrow-q input[aria-label="支持质量 gpt-image-2"]') await expect(q).not.toBeChecked() await q.check() await expect(q).toBeChecked() // 设置面板是「草稿 → 保存配置」模型:必须保存后才会作用到画布(真实用户流程) await modal.locator('button:has-text("保存配置")').click() await expect(modal.getByText('已保存')).toBeVisible() const closeBtn = page.locator('.iwb-modal-head button[title="关闭"]') if (await closeBtn.count()) await closeBtn.click() // 节点侧:档位变为可用,选「高清」后请求体带 quality=high const { chips } = await openQualityPanel(page) await expect(chips.filter({ hasText: '高清' }).first()).toBeEnabled() await chips.filter({ hasText: '高清' }).first().click() await page.keyboard.press('Escape') await runGen(page) await expect.poll(() => bodies.length).toBeGreaterThan(0) expect(bodies[0].quality).toBe('high') expect(errors).toEqual([]) }) test('渠道 400:有界降级(max → xhigh),不会把整个模型拉黑', async ({ page }) => { const errors = [] page.on('pageerror', (e) => errors.push(String((e && e.message) || e))) const bodies = [] let n = 0 await page.route('**/images/generations', async (route) => { try { bodies.push(JSON.parse(route.request().postData() || '{}')) } catch (e) { bodies.push({ parseError: String(e) }) } n += 1 if (n === 1) return route.fulfill({ status: 400, contentType: 'application/json', body: JSON.stringify({ error: { message: 'quality max not supported' } }) }) return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(GEN_RESP) }) }) await page.route('https://cdn.example/**', (route) => route.fulfill({ status: 200, contentType: 'image/png', headers: { 'access-control-allow-origin': '*' }, body: PIXEL })) await seed(page, 'gpt-image-2.5') const { chips } = await openQualityPanel(page) await chips.filter({ hasText: '最高' }).first().click() await page.keyboard.press('Escape') await runGen(page) await expect.poll(() => bodies.length).toBeGreaterThanOrEqual(2) expect(bodies[0].quality, '第一次必须按用户选择发送').toBe('max') expect(bodies[1].quality, '被拒后只降一档重试,而不是直接放弃 quality').toBe('xhigh') expect(errors).toEqual([]) })