51 lines
3.1 KiB
JavaScript
51 lines
3.1 KiB
JavaScript
/** Verify the auto-started conversation and evidence/issue closure using real UI input. */
|
|
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]);
|
|
await mkdir(output,{recursive:true});
|
|
const c=await connect(Number(process.argv[3]||9227));
|
|
const report={driver:'Qt Chromium CDP Input events',checks:[]};
|
|
const outboxOnly=process.argv.includes('--outbox-only');
|
|
async function wait(expression,timeout=30000){
|
|
const end=Date.now()+timeout;
|
|
while(Date.now()<end){if(await c.evaluate(expression))return;await new Promise(resolve=>setTimeout(resolve,200));}
|
|
throw Error('Incident UI timeout: '+expression);
|
|
}
|
|
try{
|
|
await wait(`!!document.querySelector('[data-testid="dx-auto-incident"]')`,50000);
|
|
report.checks.push('error automatically opened native assistant with incident status');
|
|
await c.screenshot(path.join(output,'automatic-diagnosis.png'));
|
|
await wait(`fetch('/dx/context').then(r=>r.json()).then(d=>d.automation?.status==='${outboxOnly?'pending_issue':'escalated'}')`,300000);
|
|
const value=await c.evaluate(`fetch('/dx/context').then(r=>r.json())`);
|
|
assert.equal(value.automation.attempts,0);
|
|
if(!outboxOnly){
|
|
assert.equal(value.automation.ticket.attachment_status,'uploaded');
|
|
assert.match(value.automation.ticket.url,/git\.simgreek\.com\/Skyworth_Digital_Hardware\/dxdesigner-part-replacement\/issues\/\d+/);
|
|
}
|
|
await wait(`document.body.innerText.includes('DSH自动诊断')`);
|
|
await wait(`document.querySelector('[data-chat-group-part="response"]')?.innerText.length>40`);
|
|
report.checks.push('native auto-created diagnostic conversation visible without manual send');
|
|
report.checks.push(outboxOnly?'unresolved incident reflected and local outbox retained after publication unavailable':
|
|
'unresolved incident reflected, evidence saved and real Git issue with attachment submitted');
|
|
report.ticket=value.automation.ticket;
|
|
if(outboxOnly){
|
|
const before=await c.evaluate(`fetch('/dx/context').then(r=>r.json()).then(d=>d.revision)`);
|
|
await c.click(`[...document.querySelectorAll('button')].find(e=>e.textContent==='重新提交工单')`);
|
|
await wait(`fetch('/dx/context').then(r=>r.json()).then(d=>d.revision!==${JSON.stringify(before)}&&d.automation.status==='pending_issue')`);
|
|
report.checks.push('clicked resubmit and retained pending evidence without replaying CAD');
|
|
}else await wait(`!!document.querySelector('[data-testid="dx-auto-ticket"]')`);
|
|
await c.screenshot(path.join(output,'automatic-issue.png'));
|
|
await c.click(`document.querySelector('[contenteditable="true"]')`);
|
|
await c.call('Input.insertText',{text:'请分析当前任务的后续核验。'});
|
|
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();}
|