Files
aigc-home/e2e/hel809.cjs
T

70 lines
5.5 KiB
JavaScript

// Targeted real drawer -> HTTP -> database -> library regression; no generation.
const { chromium } = require(process.env.PLAYWRIGHT_MODULE_PATH || 'playwright');
const fs = require('node:fs'), path = require('node:path'), http = require('node:http');
const assert = require('node:assert/strict');
const phase = process.env.HEL809_PHASE, out = process.env.HEL809_EVIDENCE;
const graph = {
'1': {class_type:'PrimitiveStringMultiline',inputs:{value:'isolated test prompt'},_meta:{title:'Prompt (Input:prompt)'}},
'2': {class_type:'LoadImage',inputs:{image:'isolated.png'},_meta:{title:'Image (Input:image)'}},
'3': {class_type:'LoadImageMask',inputs:{image:'isolated.png',channel:'red'},_meta:{title:'Mask (Input:mask)'}},
'4': {class_type:'SaveImage',inputs:{images:['2',0]},_meta:{title:'Result (Output:image)'}}
};
const build = path.resolve('calliope-web/build');
const mime = {'.js':'text/javascript','.css':'text/css','.html':'text/html;charset=utf-8','.json':'application/json','.svg':'image/svg+xml','.woff2':'font/woff2'};
const sockets = new Set();
const server = http.createServer((req,res)=>{
if(req.url.startsWith('/api/')) {
const proxy=http.request({hostname:'127.0.0.1',port:18249,path:req.url,method:req.method,headers:req.headers},r=>{res.writeHead(r.statusCode,r.headers);r.pipe(res)});
proxy.on('error',()=>{res.writeHead(502);res.end()});req.pipe(proxy);return;
}
let file=path.join(build,new URL(req.url,'http://localhost').pathname);
if(!fs.existsSync(file)||fs.statSync(file).isDirectory())file=path.join(build,'index.html');
res.setHeader('Content-Type',mime[path.extname(file)]||'application/octet-stream');fs.createReadStream(file).pipe(res);
});
server.on('connection',s=>{sockets.add(s);s.on('close',()=>sockets.delete(s))});
(async()=>{
await new Promise((resolve,reject)=>{server.once('error',reject);server.listen(18250,'127.0.0.1',resolve)});
let browser; const errors=[],responses=[],checks=[];
try {
browser=await chromium.launch({args:['--no-sandbox']});
const context=await browser.newContext({viewport:{width:1440,height:900}});
await context.addInitScript(()=>{localStorage.setItem('aigc-lang','zh');localStorage.setItem('aigc-theme','night')});
const page=await context.newPage();page.on('pageerror',e=>errors.push(e.message));
page.on('response',r=>{if(r.url().includes('/api/workflows') && ['POST','PATCH'].includes(r.request().method()))responses.push((async()=>({method:r.request().method(),url:new URL(r.url()).pathname,request:r.request().postDataJSON(),status:r.status(),response:await r.json()}))())});
await page.goto('http://127.0.0.1:18250/workflows');
await page.getByRole('button',{name:'导入工作流',exact:true}).click();
await page.getByPlaceholder('Qwen Image 2.1 文生图').fill('HEL809 图像与遮罩');
await page.locator('textarea.json').fill(JSON.stringify(graph,null,2));
await page.getByRole('button',{name:'分析',exact:true}).click();
await page.getByRole('button',{name:'确认保存',exact:true}).click();
const row=page.locator('tbody tr').filter({hasText:'HEL809 图像与遮罩'});
await row.waitFor();
await page.screenshot({path:path.join(out,phase+'-library.png'),fullPage:true});
const rowText=await row.innerText();
assert(rowText.includes(phase==='before'?'仅提示词':'图像'),rowText);checks.push('real drawer row label');
await page.getByRole('combobox',{name:'素材类型',exact:true}).selectOption('image');
// The output is image too: media filter uses both input and output declarations.
if(phase==='before')await row.waitFor({state:'hidden'});else await row.waitFor();
await page.screenshot({path:path.join(out,phase+'-image-filter.png'),fullPage:true});
checks.push('image filter '+(phase==='before'?'miss reproduced':'hit'));
const api=async(p,b,method)=>{const r=await fetch('http://127.0.0.1:18249/api'+p,{method:method||(b?'POST':'GET'),headers:{'Content-Type':'application/json'},body:b?JSON.stringify(b):undefined});assert(r.ok,await r.clone().text());return r.json()};
const meta=await api('/workflows?view=meta'),detail=await api('/workflows/'+meta[0].id);
assert(detail.input_schema.some(x=>x.role==='mask'&&x.kind==='image'));checks.push('mask is image');
if(phase==='after'){
assert.deepEqual(meta[0].media_io,{in:['image'],out:['image']});
const promptGraph={'1':graph['1']};
const analyzed=await api('/workflows/analyze',{workflow_json:promptGraph});
const prompt=await api('/workflows',{name:'HEL809 纯提示词',workflow_json:promptGraph,input_schema:analyzed.inputs,usage:'text2image'});
assert.deepEqual(prompt.media_io,{in:[],out:[]});
await page.reload();await page.getByRole('combobox',{name:'素材类型',exact:true}).selectOption('all');
const promptRow=page.locator('tbody tr').filter({hasText:'HEL809 纯提示词'});await promptRow.waitFor();assert((await promptRow.innerText()).includes('仅提示词'));
await page.getByRole('combobox',{name:'素材类型',exact:true}).selectOption('image');await promptRow.waitFor({state:'hidden'});await row.waitFor();
checks.push('pure prompt label and exclusion from image filter');
await page.screenshot({path:path.join(out,phase+'-prompt-excluded.png'),fullPage:true});
}
const network=await Promise.all(responses);
fs.writeFileSync(path.join(out,phase+'-responses.json'),JSON.stringify({network,meta,detail,rowText,checks,errors},null,2));
assert.deepEqual(errors,[]);console.log(phase,checks);
} finally {if(browser)await browser.close();for(const s of sockets)s.destroy();await new Promise(r=>server.close(r));}
})().catch(e=>{console.error(e);process.exitCode=1});