const {chromium}=require('playwright-core'); const assert=require('node:assert/strict'),fs=require('node:fs'); const root='D:/web/dj/integration-work/',base='http://127.0.0.1:18883'; const fixture=JSON.parse(fs.readFileSync(root+'hd-test-regenerate/ui-fixture.json')); (async()=>{ const browser=await chromium.launch({channel:'chrome',headless:true}); try{ const page=await browser.newPage({viewport:{width:1600,height:1100}}),errors=[]; page.on('pageerror',e=>errors.push(e.message)); await page.goto(base+'/drama/1/episode/1',{waitUntil:'networkidle'}); await page.getByRole('navigation').getByRole('button',{name:/^视频制作/}).click(); const selector=page.getByLabel('本次生成显卡',{exact:true}); await selector.waitFor(); assert.deepEqual(await selector.locator('option').evaluateAll(es=>es.map(e=>e.value)),['','auto','gpu1','gpu2','gpu3']); const pick=page.locator('.model-select').filter({has:page.locator('.model-select-label',{hasText:/^视频$/})}); await pick.locator('button').click(); const modelLabel=gpu=>new RegExp('^'+gpu+' · (?:ComfyUI 8188(?:(容器内))? · )?MiniMax-H3$'); for(const gpu of ['GPU1','GPU2','GPU3'])await page.getByText(modelLabel(gpu)).last().waitFor(); await page.getByText(modelLabel('GPU2')).last().click(); assert.match(await selector.locator('option').first().innerText(),/GPU2/); await selector.selectOption('gpu3'); const button=page.getByRole('button',{name:'取消并换卡重新生成',exact:true}); assert.ok(await button.isEnabled()); await page.screenshot({path:root+'gpu-regenerate-video-ui.png'}); let payload; await page.route('**/api/v1/tasks',route=>{ if(route.request().method()!=='POST')return route.continue(); payload=route.request().postDataJSON(); return route.fulfill({status:400,contentType:'application/json',body:JSON.stringify({message:'隔离界面测试:未提交实际生成'})}); }); await button.click(); await page.waitForFunction(()=>!document.querySelector('.video-inspector-action')?.disabled); assert.equal(payload.gpu,'gpu3'); assert.equal(payload.replace_task_id,fixture.task); assert.equal(payload.force_new,true); assert.ok(payload.config_id>10); assert.equal(payload.model,'MiniMax-H3'); await page.getByRole('navigation').getByRole('button',{name:/^高清制作/}).click(); const hd=page.getByLabel('高清模型',{exact:true}); await hd.waitFor(); assert.equal(await hd.locator('option').count(),4); const option=await hd.locator('option').filter({hasText:'GPU1'}).getAttribute('value'); await hd.selectOption(option); const hdGpu=page.getByLabel('高清生成显卡',{exact:true}); await hdGpu.selectOption('gpu3'); await page.locator('.hd-studio').getByRole('button',{name:'刷新',exact:true}).click(); assert.equal(await hdGpu.inputValue(),'gpu3'); await page.getByLabel('目标分辨率').selectOption('4K'); let hdBody; await page.route('**/api/v1/hd/storyboards/1',route=>{ hdBody=route.request().postDataJSON(); return route.fulfill({status:400,contentType:'application/json',body:JSON.stringify({message:'隔离界面测试:未提交实际生成'})}); }); await page.screenshot({path:root+'gpu-regenerate-hd-ui.png'}); await page.getByRole('button',{name:'取消并换卡重新生成 4K',exact:true}).click(); await page.getByRole('alert').filter({hasText:'隔离界面测试'}).waitFor(); assert.equal(hdBody.gpu,'gpu3'); assert.equal(hdBody.replace_task_id,fixture.task);assert.equal(hdBody.config_id,Number(option)); assert.deepEqual(errors,[]); fs.writeFileSync(root+'gpu-regenerate-ui-result.json',JSON.stringify({passed:true,checks:['all three fixed models visible','ordinary GPU override','exact task replacement payload','HD model and GPU selection','selection survives refresh'],errors},null,2)); console.log('PASS: fixed GPU models, video/HD selectors and targeted regeneration controls; no page errors'); }finally{await browser.close()} })().catch(e=>{console.error(e.stack);process.exit(1)});