/** Use real native conversation input to create tasks through the Qt confirmation. */ import assert from 'node:assert/strict'; import {writeFile,mkdir} 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:[]}; async function wait(expression,timeout=30000){ const end=Date.now()+timeout; while(Date.now()setTimeout(resolve,150));} throw Error('Task creation UI condition timed out: '+expression); } try{ await wait(`!!document.querySelector('[contenteditable="true"]')`,50000); await c.click(`document.querySelector('[contenteditable="true"]')`); const prompt='帮我建个换料任务,名字叫“DSH对话换料验收”,备注写“真实对话验收”。把 OLD123 换成 NEW456,料号也复制到 Value。工程目录我来选,先别开始替换。建好后告诉我数量和任务编号。'; report.prompt=prompt; report.explicitToolNamesInPrompt=false; await c.call('Input.insertText',{text:prompt}); await c.click(`document.querySelector('button[aria-label="发送消息"]')`); report.checks.push('typed and sent natural-language task creation request through official composer'); await wait(`fetch('/dx/context').then(r=>r.json()).then(d=>d.creation?.result?.status==='created')`,180000); const context=await c.evaluate(`fetch('/dx/context').then(r=>r.json())`); assert.equal(context.creation.result.created_count,2); assert.equal(context.creation.result.task_ids.length,2); assert.equal(context.creation.result.cad_execution_started,false); await wait(`![...document.querySelectorAll('button[aria-label="停止生成"]')].some(e=>e.getBoundingClientRect().width>0)`,100000); const reply=await c.evaluate(`[...document.querySelectorAll('[data-chat-group-part="response"]')].map(e=>e.innerText).join(String.fromCharCode(10))`); assert.ok(context.creation.result.task_ids.every(id=>reply.includes(id)),'The model must report the actual committed task IDs'); report.checks.push('native model tool completed after Qt confirmation and reported both committed task IDs'); report.created=context.creation.result; report.reply=reply; report.liveTurnCompleted=true; await c.screenshot(path.join(output,'dsh-created-tasks.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();}