Add per-task image and video cancellation with confirmed worker receipts

This commit is contained in:
Codex
2026-11-12 11:43:20 +08:00
parent e02f031378
commit 0af38fa742
18 changed files with 353 additions and 55 deletions
@@ -0,0 +1,27 @@
// Inspect the installed app using GET requests only; never cancel live jobs.
const {chromium}=require('playwright-core'),fs=require('node:fs'),assert=require('node:assert/strict');
(async()=>{
const root='D:/web/dj',api=JSON.parse(fs.readFileSync(root+'/huobao-data/last-launch.json')).api;
const tasks=(await (await fetch(api+'/episodes/7/generation-tasks')).json()).data.tasks;
const browser=await chromium.launch({channel:'chrome',headless:true});
try {
const page=await browser.newPage({viewport:{width:1600,height:1200}}),errors=[];
page.on('pageerror',e=>errors.push(e.message));
await page.addInitScript(()=>localStorage.setItem('huobao:tours',JSON.stringify(['episode'])));
await page.route('**/api/**',r=>['GET','HEAD'].includes(r.request().method())?r.continue():r.abort());
await page.goto(api.replace('/api/v1','')+'/drama/6/episode/1',{waitUntil:'networkidle'});
await page.getByRole('button',{name:/^任务/}).click();
const drawer=page.locator('.task-drawer-overlay');await drawer.waitFor();
const row=id=>drawer.locator('.gen-task-row').filter({has:page.locator('.video-task-meta-line').filter({hasText:'#'+id})});
const active=tasks.filter(t=>t.can_cancel);
for(const task of active) {
assert.equal(await row(task.id).getByRole('button',{name:/^(重试)?取消任务$/,exact:true}).count(),1);
}
const cancelled=tasks.filter(t=>t.error_code==='user_cancelled');
for(const task of cancelled)assert.equal(await row(task.id).locator('.video-task-status.is-cancelled').count(),1);
if(active.length)await row(active[active.length-1].id).scrollIntoViewIfNeeded();
await page.screenshot({path:root+'/integration-work/cancel-installed.png'});
assert.deepEqual(errors,[]);
console.log('PASS: installed cancel buttons for tasks',active.map(t=>t.id),'; cancelled history',cancelled.length,'; GET-only verification');
}finally{await browser.close()}
})().catch(e=>{console.error(e.stack);process.exit(1)});
@@ -0,0 +1,49 @@
const {chromium}=require('playwright-core'),assert=require('node:assert/strict');
(async()=>{
const browser=await chromium.launch({channel:'chrome',headless:true});
try {
const page=await browser.newPage({viewport:{width:1500,height:1100}}),errors=[],calls=[],states={};
page.on('pageerror',e=>errors.push(e.message));
await page.addInitScript(()=>localStorage.setItem('huobao:tours',JSON.stringify(['episode'])));
await page.route('**/api/**',async route=>{
const req=route.request(),url=req.url(),match=url.match(/\/tasks\/(\d+)\/cancel$/);
if(req.method()==='POST'&&match){
const id=+match[1];assert.ok([237,239].includes(id));calls.push(id);
states[id]=id===239&&!states[id]?'pending':'cancelled';
return route.fulfill({status:200,json:{code:200,data:{outcome:states[id]}}});
}
if(!['GET','HEAD'].includes(req.method()))throw Error('Unexpected mutation: '+req.method()+' '+url);
if(url.includes('/generation-tasks')){
const response=await route.fetch(),body=await response.json();
for(const task of body.data.tasks){
if(![237,239].includes(task.id))continue;
task.status=states[task.id]==='cancelled'?'failed':'processing';
task.error_code=states[task.id]==='cancelled'?'user_cancelled':null;
task.error_msg=states[task.id]==='cancelled'?'任务已取消,历史记录和已有素材保留':null;
task.stage=states[task.id]==='pending'?'cancelling':task.id===239?'queued':'running';
task.can_cancel=task.status==='processing';
}
return route.fulfill({response,json:body});
}
return route.continue();
});
await page.goto('http://127.0.0.1:18938/drama/6/episode/1',{waitUntil:'networkidle'});
await page.getByRole('button',{name:/^任务/}).click();
const drawer=page.locator('.task-drawer-overlay');await drawer.waitFor();
const row=id=>drawer.locator('.gen-task-row').filter({has:page.locator('.video-task-meta-line').filter({hasText:'#'+id})});
assert.equal(await row(237).getByRole('button',{name:'取消任务',exact:true}).count(),1);
await row(239).getByRole('button',{name:'取消任务',exact:true}).click();
await row(239).getByRole('button',{name:'重试取消任务',exact:true}).waitFor();
assert.match(await row(239).innerText(),/正在等待显卡确认/);
assert.equal(await row(237).getByRole('button',{name:'取消任务',exact:true}).count(),1);
await row(239).getByRole('button',{name:'重试取消任务',exact:true}).click();
await row(239).locator('.video-task-status.is-cancelled').waitFor();
assert.match(await row(239).innerText(),/已取消/);
assert.equal(await row(239).getByRole('button',{name:/取消任务/}).count(),0);
await row(237).getByRole('button',{name:'取消任务',exact:true}).click();
await row(237).locator('.video-task-status.is-cancelled').waitFor();
assert.deepEqual(calls,[239,239,237]);assert.deepEqual(errors,[]);
await page.screenshot({path:'D:/web/dj/integration-work/cancel-ui-fixture.png'});
console.log('PASS: per-image/video cancel buttons; pending confirmation/retry; cancelled styling/counts; no real cancellations');
}finally{await browser.close()}
})().catch(e=>{console.error(e.stack);process.exit(1)});