/** Upload owned files via the real composer menu and Qt's actual file chooser. */ import assert from 'node:assert/strict'; import {writeFile,readdir,readFile} from 'node:fs/promises'; import path from 'node:path'; export async function verifyFileUi(c,output){ const wait=async(expression)=>{ const end=Date.now()+30000; while(Date.now()setTimeout(r,100));} throw Error('File UI timed out: '+expression); }; const fixtures=path.join(output,'file-fixtures'); const files=['dsh-upload.txt','dsh-upload.zip'].map(name=>path.join(fixtures,name)); await writeFile(path.join(output,'file-picker-request.json'),JSON.stringify(files)); // Plus opens the official command menu; choose its native attachment action. const plus=`[...document.querySelectorAll('button[aria-label="添加文件或调用指令"]')].find(e=>e.getBoundingClientRect().width>0)`; await c.click(plus); const fileOption=`[...document.querySelectorAll('[role="option"],button')].find(e=>e.getBoundingClientRect().width>0&&/^文件\\s*file/.test(e.textContent.trim()))`; await wait(`!!(${fileOption})`); await c.click(fileOption); await wait(`document.body.innerText.includes('dsh-upload.txt')&&document.body.innerText.includes('dsh-upload.zip')`); await wait(`![...document.querySelectorAll('[role="progressbar"]')].some(e=>e.getBoundingClientRect().width>0)`); await c.screenshot(path.join(output,'file-uploaded.png')); // Validate the uploaded bytes in Harness's actual owned storage, not the DOM echo. const roots=(await readdir(output)).filter(x=>x.startsWith('data-')); assert.equal(roots.length,1); const home=path.join(output,roots[0],'dsh/harness-home'); const expected=await Promise.all(files.map(f=>readFile(f))); const found=new Set(); async function scan(dir){ for(const entry of await readdir(dir,{withFileTypes:true})){ const filename=path.join(dir,entry.name); if(entry.isDirectory())await scan(filename); else if(entry.isFile()){ const data=await readFile(filename); expected.forEach((bytes,i)=>{if(data.equals(bytes))found.add(i);}); } } } const end=Date.now()+20000; while(found.sizesetTimeout(r,150));} assert.equal(found.size,2,'text and ZIP must reach actual Harness file storage unchanged'); return {status:'passed',realQtFilePicker:true,textAndZipUploaded:true,storedBytesMatched:true}; }