Files
dxdesigner-part-replacement/tools/verify_dsh_native_ui.mjs
T
阿白叔 705c15eb93
Core regression / Python core and release configuration (push) Successful in 20s
Core regression / JavaScript syntax (push) Successful in 3s
Core regression / Python core and release configuration (pull_request) Successful in 15s
Core regression / JavaScript syntax (pull_request) Successful in 3s
fix(dsh): restore native file tools and official loading UI
2026-11-04 19:05:21 +08:00

127 lines
9.4 KiB
JavaScript

/** Click the actual embedded Chromium UI and record native SVG/animation evidence. */
import assert from 'node:assert/strict';
import {mkdir,writeFile} from 'node:fs/promises';
import path from 'node:path';
import {connect} from './dsh_cdp.mjs';
const output=path.resolve(process.argv[2] || 'build/dsh-native-acceptance/ui');
await mkdir(output,{recursive:true});
const c=await connect(Number(process.argv[3] || 9226));
const report={driver:'Qt Chromium CDP Input events',checks:[]};
const liveModel=process.argv.includes('--live-model');
async function wait(expression,timeout=15000) {
const end=Date.now()+timeout;
while(Date.now()<end){if(await c.evaluate(expression))return;await new Promise(r=>setTimeout(r,100));}
throw Error('UI condition timed out: '+expression);
}
try {
await wait(`!!document.querySelector('svg[class*="fish"]')`,45000);
for(let attempt=0;attempt<10 && !await c.evaluate(`document.body.innerText.includes('DSH助手')`);attempt++) {
if(await c.evaluate(`!!document.querySelector('button[aria-label="打开侧边栏"]')`))
await c.click(`document.querySelector('button[aria-label="打开侧边栏"]')`);
await new Promise(resolve=>setTimeout(resolve,150));
}
await wait(`document.body.innerText.includes('DSH助手')`);
await wait(`!!document.querySelector('[data-testid="dx-task-panel"]')`);
report.checks.push('official frontend and native right dock loaded');
assert.equal(await c.evaluate(`!!document.querySelector('[role="dialog"],[data-desktop-onboarding]')`),false,'Fresh launch must not show account or product onboarding');
const accountEntries=`[...document.querySelectorAll('button,a')].filter(e=>/^(登录|登入|注册|账户|账号|充值|开始使用|Sign in|Log in|Account)$/.test(e.textContent.trim()))`;
assert.equal(await c.evaluate(`${accountEntries}.length`),0);
report.checks.push('fresh profile opens without login, account or product onboarding');
await c.click(`document.querySelector('[data-testid="dx-tool-settings"]')`);
await wait(`!!document.querySelector('[data-testid="dx-tool-settings-panel"]')`);
assert.equal(await c.evaluate(`${accountEntries}.length`),0);
report.checks.push('one click opens native tool settings with DSH capabilities and no account entry');
await c.screenshot(path.join(output,'dsh-tool-settings.png'));
await c.click(`[...document.querySelectorAll('[data-shortcut-modal="settings"] nav button')].find(e=>e.textContent.trim()==='模型')`);
await wait(`document.body.innerText.includes('自定义模型 API')||document.body.innerText.includes('添加模型提供商')`);
if(!await c.evaluate(`document.body.innerText.includes('自定义模型 API')`))
await c.click(`[...document.querySelectorAll('button')].find(e=>e.textContent.includes('添加模型提供商'))`);
await wait(`document.body.innerText.includes('自定义模型 API')`);
await c.click(`[...document.querySelectorAll('button')].find(e=>e.textContent.trim()==='自定义模型 API')`);
await wait(`!!document.querySelector('input[aria-label="Provider ID"]')&&document.body.innerText.includes('获取可用模型')`);
report.checks.push('actual model settings clicks reveal custom API and fetch-model controls');
await c.screenshot(path.join(output,'dsh-custom-model-settings.png'));
if(process.argv.includes('--model-settings-check')){
const {verifyModelSettings}=await import('./verify_dsh_model_settings.mjs');
report.modelSettings=await verifyModelSettings(c,output);
}
await c.click(`[...document.querySelectorAll('[data-shortcut-modal="settings"] button')].find(e=>e.textContent.trim()==='关闭')`);
await wait(`!document.querySelector('[role="dialog"]')`);
await c.screenshot(path.join(output,'dsh-tool-home.png'));
const context=await c.evaluate(`fetch('/dx/context').then(r=>r.json())`);
assert.ok(context.task_id,'Select a task in the task center before running this test.');
report.checks.push('current task received from task center');
await c.click(`[...document.querySelectorAll('button')].find(e=>e.textContent.trim()==='刷新任务上下文')`);
await wait(`fetch('/dx/context').then(r=>r.json()).then(d=>d.revision!==${JSON.stringify(context.revision)})`);
report.checks.push('refresh clicked and confirmed through Qt task bridge');
await c.click(`document.querySelectorAll('button[aria-label="新建会话"]')[1]`);
await wait(`!!document.querySelector('[data-testid="dx-task-panel"]')`);
report.checks.push('native new conversation retains task dock');
if(process.argv.includes('--file-check')){
const {verifyFileUi}=await import('./verify_dsh_file_ui.mjs');
report.files=await verifyFileUi(c,output);
}
if(!liveModel) {
await c.click(`document.querySelector('button[aria-label="收起侧边栏"]')`);
await wait(`!!document.querySelector('button[aria-label="打开侧边栏"]')`);
await c.click(`document.querySelector('button[aria-label="打开侧边栏"]')`);
await wait(`!!document.querySelector('button[aria-label="收起侧边栏"]')`);
report.checks.push('native sidebar collapsed and expanded');
}
const fish=await c.evaluate(`(()=>{const r=document.querySelector('svg[class*="fish"]').getBoundingClientRect();return {x:r.x+r.width/2,y:r.y+r.height/2};})()`);
await c.call('Input.dispatchMouseEvent',{type:'mouseMoved',...fish});
await wait(`document.getAnimations().length>0 || document.querySelectorAll('svg animate').length>0`);
report.nativeSvgCount=await c.evaluate(`document.querySelectorAll('svg').length`);
report.nativeAnimations=await c.evaluate(`({css:document.getAnimations().length,svg:document.querySelectorAll('svg animate').length})`);
assert.ok(report.nativeSvgCount>=15);
for(let i=0;i<8;i++) {
await c.screenshot(path.join(output,`hover-${i}.png`));
await new Promise(resolve=>setTimeout(resolve,120));
}
report.checks.push('upstream whale SVG hover animation runs in Qt Chromium');
const transforms=await c.evaluate(`document.getAnimations().map(a=>({name:a.animationName,time:a.currentTime}))`);
report.animationState=transforms;
const modelButton=`[...document.querySelectorAll('button')].find(e=>e.getBoundingClientRect().width>0 && (e.getAttribute('aria-label')==='请选择模型' || /skyworth-deepseek/.test(e.title+' '+e.getAttribute('aria-label'))))`;
await c.click(modelButton);
await wait(`document.querySelector('[role="dialog"],[role="menu"],[role="listbox"]')!==null`);
report.modelPickerEntries=await c.evaluate(`[...new Set((document.body.innerText.match(/skyworth-deepseek[\\w.-]*/g)||[]))]`);
report.checks.push('native model picker opened');
await c.call('Input.dispatchKeyEvent',{type:'keyDown',key:'Escape',code:'Escape'});
await c.call('Input.dispatchKeyEvent',{type:'keyUp',key:'Escape',code:'Escape'});
await c.click(`document.querySelector('[contenteditable="true"]')`);
const fileCheck=process.argv.includes('--file-check');
const prompt=liveModel ? (fileCheck?'请分析当前任务的附件:读取上传的 dsh-upload.txt,再解压 dsh-upload.zip 并读取其中说明.txt,分别告诉我这两份文本的完整内容和解压后的真实目录。不要修改原文件或运行 CAD。':'请分析当前任务的状态和异常,告诉我任务名称、现在进展到哪一步以及接下来可以做什么。不要修改工程。') : '请分析当前任务的异常,并说明允许的处理方式。';
report.prompt=prompt;
report.explicitToolNamesInPrompt=false;
await c.call('Input.insertText',{text:prompt});
await wait(`document.querySelector('[contenteditable="true"]').textContent.includes('请分析当前任务')`);
report.checks.push('typed into official composer with native keyboard input');
report.liveModelReplyTested=false;
if(liveModel) {
await c.click(`document.querySelector('button[aria-label="发送消息"]')`);
const replies=`[...document.querySelectorAll('[data-chat-group-part="response"]')].map(e=>e.innerText).join('\\n')`;
await wait(fileCheck?`(${replies}).includes('DSH_UPLOAD_CONTENT')&&(${replies}).includes('DSH_ZIP_UPLOAD_CONTENT')`:`(${replies}).length>30 && /任务|状态/.test(${replies})`,fileCheck?180000:100000);
await wait(`![...document.querySelectorAll('button[aria-label="停止生成"]')].some(e=>e.getBoundingClientRect().width>0)`,fileCheck?180000:100000);
report.reply=await c.evaluate(replies);
report.liveModelReplyTested=true;
report.liveTurnCompleted=true;
report.checks.push('real API reply rendered through the official Harness conversation');
await c.click(`document.querySelector('[contenteditable="true"]')`);
await c.call('Input.insertText',{text:'请分析当前任务的下一步。'});
} else report.reason='Live model generation was not requested for this acceptance run.';
await c.screenshot(path.join(output,'dsh-native-final.png'));
if(process.argv.includes('--confirm-cancel')) {
await c.click(`[...document.querySelectorAll('button')].find(e=>e.textContent.trim()==='准备失败项重试')`);
await wait(`fetch('/dx/context').then(r=>r.json()).then(d=>d.action_result.includes('已取消'))`,20000);
report.checks.push('sensitive action required Qt confirmation and was cancelled');
}
report.status='passed';
await writeFile(path.join(output,'report.json'),JSON.stringify(report,null,2));
console.log(JSON.stringify(report));
} catch(error) {
await c.screenshot(path.join(output,'failure.png')).catch(()=>{});
await writeFile(path.join(output,'report.json'),JSON.stringify({...report,status:'failed',error:error.message},null,2));
throw error;
} finally {c.close();}