test: repair native acceptance entry portability T01-T03

This commit is contained in:
Codex committed 2026-10-21 15:47:25 +09:00
1 parent 9724fc70bc
commit f3be60bf2d
6 files changed
+335 -58

No files matched your search

+18 -4
View File
@@ -8,22 +8,36 @@ const fixture=path.resolve(process.argv[2]||'')
if(!process.argv[2]||!fs.existsSync(path.join(fixture,'index.html')))throw Error('Supply build-only fixture directory')
const profile=fs.mkdtempSync(path.join(os.tmpdir(),'ycode-b04-native-'))
app.setPath('userData',profile)
let timer,win,finished=false
let timer,win,finished=false,phase='waiting-for-app'
const started=Date.now(), rendererErrors=[]
const scheduling={backgroundThrottling:false,show:true,deadlineMs:20000}
function mark(value){phase=value;console.log(JSON.stringify({phase,elapsedMs:Date.now()-started}))}
function finish(error,report){
if(finished)return;finished=true;clearTimeout(timer)
const result={result:error?'FAIL':'PASS',error:error?String(error):undefined,report,limits:'Synthetic own-component Electron fixture, not the installed application or original reference UI.'}
const result={result:error?'FAIL':'PASS',error:error?String(error):undefined,report,phase,elapsedMs:Date.now()-started,scheduling,rendererErrors,limits:'Synthetic own-component Electron fixture, not the installed application or original reference UI.'}
fs.writeFileSync(path.join(fixture,'native-report.json'),JSON.stringify(result,null,2))
console.log(JSON.stringify({result:result.result,error:result.error,output:path.join(fixture,'native-report.json')}))
if(win&&!win.isDestroyed())win.destroy()
app.exit(error?1:0)
}
// Bound startup as well as page loading and real rAF completion.
timer=setTimeout(()=>finish(Error('Bounded native probe timed out after 20s; phase='+phase)),20000)
app.whenReady().then(async()=>{
if(finished)return
mark('creating-window')
session.defaultSession.webRequest.onBeforeRequest((details,callback)=>callback({cancel:!['file:','data:','blob:','devtools:'].some(p=>details.url.startsWith(p))}))
win=new BrowserWindow({width:1000,height:800,show:true,webPreferences:{nodeIntegration:false,contextIsolation:true,sandbox:true}})
win=new BrowserWindow({width:1000,height:800,show:true,webPreferences:{nodeIntegration:false,contextIsolation:true,sandbox:true,backgroundThrottling:false}})
win.webContents.on('render-process-gone',(_,details)=>finish(Error('Renderer gone: '+details.reason)))
timer=setTimeout(()=>finish(Error('Bounded native probe timed out after 20s')),20000)
win.webContents.on('console-message',event=>{if(event.level==='error'||event.level>=3)rendererErrors.push(event.message)})
win.webContents.on('did-fail-load',(_,code,description)=>finish(Error('Page load failed: '+code+' '+description)))
mark('loading-fixture')
await win.loadFile(path.join(fixture,'index.html'))
if(finished)return
mark('waiting-for-native-frames')
const report=await win.webContents.executeJavaScript(`new Promise((resolve,reject)=>{const check=()=>{if(window.__b04Error)return reject(Error(window.__b04Error));if(window.__b04Report)return resolve(window.__b04Report);setTimeout(check,25)};check()})`)
if(finished)return
mark('checking-native-report')
if(rendererErrors.length)throw Error('Renderer console errors: '+rendererErrors.join('; '))
if(!report.samples.some(s=>s.height>0))throw Error('No nonzero native layout measured')
if(report.samples.some(s=>s.textLength>1000||s.height>2000))throw Error('Unexpected address-sized text/height spike')
finish(null,report)