74 lines
4.6 KiB
JavaScript
74 lines
4.6 KiB
JavaScript
// v3.87.28 契约:按「厂商分类」下发请求体
|
||
// ① 豆包(seedream)比例=具体值 → 像素 size(比例+档位都精确)+ watermark:false
|
||
// ② 豆包 比例=自动 → K 档字符串 size(比例交给上游)
|
||
// ③ 豆包每模型上限:seedream-5-0 选 4K → 实发 3K
|
||
// ④ 未知模型(无规则命中)→ 回落 openai(像素 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: 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: 'doubao-seedream-4-5-251128', visible: true }, { name: 'doubao-seedream-5-0-260128', visible: true }, { name: 'mystery-model-1', visible: true }] }], canvas: { snap: true } }
|
||
const mkWs = (model, ratio, 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, provider: 'p-a', keyGroup: 'a-1', ratio, res, size: '1440x2560', custom: false, customSize: '', quality: 'auto' } },
|
||
], edges: [{ id: 'e1', from: 'p1', to: 'g1' }], groups: [] }] })
|
||
|
||
async function boot(page, model, ratio, res) {
|
||
const bodies = []
|
||
await page.route('**/images/generations', async (route) => {
|
||
try { bodies.push(JSON.parse(route.request().postData() || '{}')) } catch (e) { bodies.push({}) }
|
||
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(model, ratio, 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)
|
||
await page.locator('[data-node-id="g1"] button', { hasText: '生成' }).first().click()
|
||
await page.waitForTimeout(1200)
|
||
return bodies
|
||
}
|
||
|
||
test('豆包:比例=具体值 → 像素 size(比例+档位)+ watermark:false', async ({ page }) => {
|
||
const bodies = await boot(page, 'doubao-seedream-4-5-251128', '9:16', '2K')
|
||
expect(bodies.length).toBeGreaterThanOrEqual(1)
|
||
expect(bodies[0].size, '豆包像素模式应发像素尺寸').toBe('1440x2560')
|
||
expect(bodies[0].watermark, '应显式关闭水印').toBe(false)
|
||
})
|
||
|
||
test('豆包:比例=自动 → K 档字符串', async ({ page }) => {
|
||
const bodies = await boot(page, 'doubao-seedream-4-5-251128', 'auto', '2K')
|
||
expect(bodies.length).toBeGreaterThanOrEqual(1)
|
||
expect(bodies[0].size, '比例自动时改发 K 档').toBe('2K')
|
||
})
|
||
|
||
test('豆包每模型上限:seedream-5-0 选 4K → 实发 3K', async ({ page }) => {
|
||
const bodies = await boot(page, 'doubao-seedream-5-0-260128', 'auto', '4K')
|
||
expect(bodies.length).toBeGreaterThanOrEqual(1)
|
||
expect(bodies[0].size, '5-0 档位上限为 3K').toBe('3K')
|
||
})
|
||
|
||
test('未知模型 → 回落 openai(像素 size,不带 K 档)', async ({ page }) => {
|
||
const bodies = await boot(page, 'mystery-model-1', '9:16', '2K')
|
||
expect(bodies.length).toBeGreaterThanOrEqual(1)
|
||
expect(bodies[0].size).toBe('1440x2560')
|
||
expect(bodies[0].watermark).toBeUndefined()
|
||
})
|
||
|
||
// 2026-10-29(方向 C 批 3):把原先只靠「源码正则」守的两条请求策略,改成**真实浏览器**断言:
|
||
// ① 生图必须强制上游返回 URL(response_format=url),不接受 Base64
|
||
// ② 每次生成只请求一次(不再按地址列表 fallback 重试)
|
||
// 原先这两条由 tests/iwb-v32-web-test.js 的 58-2c / 58-2d 正则钉死实现细节,现已删除并由此处接管。
|
||
test('请求策略:response_format=url 且有且仅有一次请求(无地址 fallback 重试)', async ({ page }) => {
|
||
const bodies = await boot(page, 'doubao-seedream-4-5-251128', '9:16', '2K')
|
||
expect(bodies.length, '应命中 /images/generations(路径固定为 generations)').toBeGreaterThanOrEqual(1)
|
||
expect(bodies[0].response_format, '生图必须要求上游返回 URL,不接受 Base64').toBe('url')
|
||
expect(bodies.length, '每次生成只应请求一次(不得按地址列表 fallback 重试)').toBe(1)
|
||
})
|