// v3.87.29 契约:设置 → 生图服务 里的「厂商分类」UI // ① 每个服务商都有「厂商类型」下拉,默认 openai // ② 选「自定义」→ 出现请求体模板输入框;填合法 JSON 即生效(配置里写入 requestShape.body) // ③ 模型行有「厂商分类」覆盖下拉 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: 1100 } }) 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 } } test('设置里可配厂商类型 / 自定义模板 / 模型级覆盖', async ({ page }) => { const errors = [] page.on('pageerror', (e) => errors.push(String((e && e.message) || e))) await page.addInitScript((d) => { localStorage.clear(); localStorage.setItem('iwb_web_cfg', JSON.stringify(d.cfg)) }, { cfg: CFG }) await page.goto('/', { waitUntil: 'domcontentloaded' }) await page.waitForTimeout(600) // 打开设置(入口因视图而异 → 依次尝试,任一命中即可) const nav = page.locator('.iwb-nav-item[title="设置"]') if (await nav.count() > 0) { await nav.first().click() } else { const cands = [ page.locator('.iwb-home-side-item', { hasText: '设置' }), page.locator('.iwb-home-menu-item', { hasText: '设置' }), page.locator('[title="服务与 Key 设置"]'), ] let opened = false for (const c of cands) { if (await c.count() > 0) { await c.first().click(); opened = true; break } } expect(opened, '应能找到设置入口').toBe(true) } await page.waitForTimeout(700) // 设置默认打开「通用」标签(2026-11-25 用户裁定)→ 显式切到生图服务 await page.locator('.iwb-set-nav-item', { hasText: '生图服务' }).first().click() const kindSel = page.locator('select[aria-label="厂商类型"]').first() await expect(kindSel).toBeVisible() await expect(kindSel).toHaveValue('openai') // 切到自定义 → 出现模板输入 await kindSel.selectOption('custom') const tpl = page.locator('textarea[aria-label="请求体模板"]').first() await expect(tpl).toBeVisible() await tpl.fill('{ "model": "$model", "prompt": "$prompt", "resolution": "$res_k" }') await page.waitForTimeout(200) // 非法 JSON 时显示提示,且不写入 await tpl.fill('{ 坏 JSON') await expect(page.getByText('JSON 格式有误,暂未生效').first()).toBeVisible() // 模型级覆盖下拉存在 await expect(page.locator('select[aria-label="厂商分类 gpt-image-2.5"]').first()).toBeVisible() // 保存配置后再读回:custom + 模板生效 await tpl.fill('{ "model": "$model", "prompt": "$prompt", "resolution": "$res_k" }') await page.getByRole('button', { name: '保存配置' }).first().click() await page.waitForTimeout(600) const saved = await page.evaluate(() => { try { return JSON.parse(localStorage.getItem('iwb_web_cfg') || '{}') } catch (e) { return {} } }) const pr = (saved.providers || [])[0] || {} expect(pr.kind, '厂商类型应被保存(且不再被白名单吞掉)').toBe('custom') expect(pr.requestShape && pr.requestShape.body && pr.requestShape.body.resolution, '模板应被保存').toBe('$res_k') expect(errors).toEqual([]) })