fix(ci): observe reminder progress and capture painted desktop views
This commit is contained in:
@@ -23,19 +23,31 @@ fs.writeFileSync(path.join(projectRoot,'README.md'),original,{flag:'wx'});
|
||||
const reservation=net.createServer();await new Promise(resolve=>reservation.listen(0,'127.0.0.1',resolve));const port=reservation.address().port;await new Promise(resolve=>reservation.close(resolve));
|
||||
const controller=new HostController({appRoot,dataRoot,port,nodePath:process.execPath,timeoutMs:60000});
|
||||
const report={schemaVersion:1,passed:false,startedAt:new Date().toISOString(),ownedRoot,port,groups:[],screenshots:[],pageErrors:[],externalRequests:[],scope:'Actual isolated product Microsoft Edge/Electron through locked Playwright and owned source/data only; no model or formal installation.'};
|
||||
let browser,application,electronPid,hostIdentity,stage='host-start';
|
||||
let browser,application,electronPid,hostIdentity,activePage,stage='host-start';
|
||||
const record=(name,detail={})=>report.groups.push({name,passed:true,...detail});
|
||||
const watched=new WeakSet();
|
||||
const watch=(page)=>{if(watched.has(page))return;watched.add(page);page.on('pageerror',error=>report.pageErrors.push(error.message));page.on('request',request=>{const url=new URL(request.url());if(['http:','https:'].includes(url.protocol) && !(url.hostname==='127.0.0.1' && Number(url.port)===port))report.externalRequests.push(request.url());});};
|
||||
const watch=(page)=>{activePage=page;if(watched.has(page))return;watched.add(page);page.on('pageerror',error=>report.pageErrors.push(error.message));page.on('request',request=>{const url=new URL(request.url());if(['http:','https:'].includes(url.protocol) && !(url.hostname==='127.0.0.1' && Number(url.port)===port))report.externalRequests.push(request.url());});};
|
||||
async function capture(page,mode,width,height){
|
||||
const id=mode+'-'+width,file=path.join(evidence,id+'.png');
|
||||
if(mode==='electron'){
|
||||
await application.evaluate(({BrowserWindow},size)=>BrowserWindow.getAllWindows()[0].setContentSize(...size),[width,height]);
|
||||
await page.waitForFunction(size=>innerWidth===size[0] && innerHeight===size[1],[width,height]);
|
||||
}else await page.setViewportSize({width,height});
|
||||
const dialog=page.getByRole('dialog',{name:'模型中心',exact:true});
|
||||
await dialog.getByRole('heading',{name:'新任务默认模型',exact:true}).waitFor({timeout:30000});
|
||||
await dialog.getByRole('combobox',{name:'新任务默认模型',exact:true}).and(page.locator('select:enabled')).waitFor({timeout:30000});
|
||||
const painted=await dialog.evaluate(async element=>{
|
||||
await document.fonts.ready;
|
||||
await Promise.all(element.getAnimations({subtree:true}).filter(animation=>animation.effect?.getTiming().iterations!==Infinity).map(animation=>animation.finished.catch(()=>{})));
|
||||
const frames=[];await new Promise(resolve=>requestAnimationFrame(first=>{frames.push(first);requestAnimationFrame(second=>{frames.push(second);resolve();});}));
|
||||
return{fontStatus:document.fonts.status,frames};
|
||||
});
|
||||
assert.equal(painted.fontStatus,'loaded');assert.ok(painted.frames[1]>painted.frames[0]);
|
||||
if(mode==='electron'){
|
||||
const value=await application.evaluate(async({BrowserWindow})=>{const window=BrowserWindow.getAllWindows()[0];const [width,height]=window.getContentSize();const image=await window.capturePage({x:0,y:0,width,height},{stayHidden:true,stayAwake:true});return{base64:image.toPNG().toString('base64'),visible:window.isVisible(),size:image.getSize()};});
|
||||
assert.equal(value.visible,false);assert.ok(value.size.width>0 && value.size.height>0);fs.writeFileSync(file,Buffer.from(value.base64,'base64'),{flag:'wx'});
|
||||
}else{await page.setViewportSize({width,height});await page.screenshot({path:file,fullPage:false});}
|
||||
writeNewJson(path.join(evidence,id+'.dom.json'),{title:await page.title(),width,height,html:await page.content(),overflow:await page.evaluate(()=>document.documentElement.scrollWidth>innerWidth)});
|
||||
assert.equal(value.visible,false);assert.equal(value.size.width,width);assert.equal(value.size.height,height);fs.writeFileSync(file,Buffer.from(value.base64,'base64'),{flag:'wx'});
|
||||
}else await page.screenshot({path:file,fullPage:false});
|
||||
writeNewJson(path.join(evidence,id+'.dom.json'),{title:await page.title(),width,height,painted,html:await page.content(),overflow:await page.evaluate(()=>document.documentElement.scrollWidth>innerWidth)});
|
||||
assert.equal(await page.evaluate(()=>document.documentElement.scrollWidth>innerWidth),false,'Document overflows');
|
||||
const bytes=fs.readFileSync(file);assert.equal(bytes.subarray(1,4).toString(),'PNG');assert.ok(bytes.length>1000);
|
||||
report.screenshots.push({file,width,height,sha256:fileDigest(file),bytes:bytes.length});
|
||||
@@ -60,14 +72,32 @@ try{
|
||||
stage='electron';const executable=desktopExecutableIdentity(appRoot).path;
|
||||
application=await _electron.launch({executablePath:executable,args:[path.join(appRoot,'dist-desktop/main.cjs'),'--app-root',appRoot,'--data-root',dataRoot,'--node',process.execPath,'--port',String(port),'--hidden-window'],cwd:appRoot,env:projectEnvironment(),timeout:60000});
|
||||
electronPid=await application.evaluate(()=>process.pid);report.electron={pid:electronPid,executable,sha256:fileDigest(executable),version:await application.evaluate(()=>process.versions.electron)};
|
||||
const window=await application.firstWindow();await userPath(window,'electron',project.id);
|
||||
const window=await application.firstWindow();
|
||||
// Keep this owned QA window hidden while giving its renderer foreground
|
||||
// frame scheduling. This affects capture only and ends with the process.
|
||||
await application.evaluate(({BrowserWindow})=>BrowserWindow.getAllWindows()[0].webContents.setBackgroundThrottling(false));
|
||||
report.electron.capturePolicy={hiddenWindow:true,backgroundThrottling:false,requireLoadedModelCard:true,waitForFontsAndTwoFrames:true};
|
||||
await userPath(window,'electron',project.id);
|
||||
const status=await controller.status();assert.equal(status.identity.pid,hostIdentity.pid);assert.ok(status.desktopWindows.entries.some(entry=>entry.pid===electronPid));
|
||||
record('same owned host and actual registered Electron');
|
||||
const center=await controller.api('/model-center');assert.equal(center.attempts.length,0,'No model request is permitted in CI smoke');
|
||||
assert.deepEqual(fs.readFileSync(path.join(projectRoot,'README.md')),original);assert.deepEqual(report.pageErrors,[]);assert.deepEqual(report.externalRequests,[]);
|
||||
record('original source retained; zero model attempts or outside page requests');
|
||||
report.passed=true;
|
||||
}catch(error){report.failure={stage,name:error.name,message:error.message,stack:error.stack};process.exitCode=1;}
|
||||
}catch(error){
|
||||
report.failure={stage,name:error.name,message:error.message,stack:error.stack};process.exitCode=1;
|
||||
if(activePage&&!activePage.isClosed()){
|
||||
try{
|
||||
const domFile=path.join(evidence,'failure-'+stage+'.html'),imageFile=path.join(evidence,'failure-'+stage+'.png');
|
||||
fs.writeFileSync(domFile,await activePage.content(),{flag:'wx'});
|
||||
if(stage==='electron'&&application){
|
||||
const base64=await application.evaluate(async({BrowserWindow})=>{const window=BrowserWindow.getAllWindows()[0];const [width,height]=window.getContentSize();return(await window.capturePage({x:0,y:0,width,height},{stayHidden:true,stayAwake:true})).toPNG().toString('base64');});
|
||||
fs.writeFileSync(imageFile,Buffer.from(base64,'base64'),{flag:'wx'});
|
||||
}else await activePage.screenshot({path:imageFile,fullPage:true,timeout:10000});
|
||||
report.failureCapture={url:activePage.url(),dom:{file:domFile,bytes:fs.statSync(domFile).size,sha256:fileDigest(domFile)},image:{file:imageFile,bytes:fs.statSync(imageFile).size,sha256:fileDigest(imageFile)}};
|
||||
}catch(captureError){report.failureCaptureError={message:captureError.message};}
|
||||
}
|
||||
}
|
||||
finally{
|
||||
try{if(browser)await browser.close();if(application)await application.close();
|
||||
if(await controller.health())report.hostStop=await controller.stop();
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
export async function openWorkbenchTool(page, name) {
|
||||
const aliases = { '打开模型中心': '选择与管理模型', '项目MCP工具': '项目 MCP 工具' };
|
||||
const direct = page.getByRole('button', { name: aliases[name] ?? name, exact: true });
|
||||
if (await direct.first().isVisible()) { await direct.first().click(); return; }
|
||||
// The sidebar becomes inert after a responsive resize. The persistent
|
||||
// toolbox is the model-center entry at both desktop and narrow widths.
|
||||
if (name !== '打开模型中心' && await direct.first().isVisible()) { await direct.first().click(); return; }
|
||||
await page.getByRole('button', { name: '打开工具箱', exact: true }).click();
|
||||
const toolbox = page.getByRole('dialog', { name: '工具箱', exact: true });
|
||||
const actionName = name === '打开模型中心' ? '模型中心' : aliases[name] ?? name;
|
||||
|
||||
Reference in New Issue
Block a user