/** 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"]')`); await c.call('Input.insertText',{text:'请现在调用 dx_task_create 创建名为“DSH对话换料验收”的工程任务,备注“真实对话验收”,替换规则 OLD123 → NEW456,把料号复制到 Value。工程目录我会在本机原生窗口中选择。仅创建任务,不采集、不替换。完成后告诉我实际创建数量和真实 task_id。'}); 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();}