/** Mobile publication workflow, isolated API fixtures: no GPU or dataset writes. */ import {chromium,webkit} from 'playwright'; import {readFile,writeFile} from 'node:fs/promises'; import {createServer} from 'node:http'; import {resolve,extname} from 'node:path'; import assert from 'node:assert/strict'; const root=resolve('frontend/dist'),origin='http://127.0.0.1:7860'; const pixel='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQIHWP4z8DwHwAFgAI/ScLbtAAAAABJRU5ErkJggg=='; const editorial={title:'Green leaf',description:'EN: A green leaf.\n\nFR : Une feuille verte.',category:'plants',tags:['green','leaf']}; const job=status=>({id:'description',status,...(status==='ready'?{result:{editorial}}:{})}); const server=createServer(async(req,res)=>{try{ const p=resolve(root,'.'+(new URL(req.url,origin).pathname==='/'?'/index.html':new URL(req.url,origin).pathname));assert.ok(p.startsWith(root+'/')); res.setHeader('Content-Type',{'.html':'text/html','.js':'text/javascript','.css':'text/css','.json':'application/json'}[extname(p)]||'application/octet-stream');res.end(await readFile(p)); }catch{res.writeHead(404);res.end();}}); await new Promise(ok=>server.listen(7860,'127.0.0.1',ok)); const results=[]; try{for(const engine of [chromium,webkit]){ const browser=await engine.launch({headless:true,...(engine===chromium?{args:['--no-sandbox','--disable-dev-shm-usage','--disable-webgl']}: {})}); try{for(const language of ['en','fr']){ const context=await browser.newContext({viewport:{width:390,height:844},hasTouch:true}),page=await context.newPage(); let status='generating',reserve='generating',posts=0,published=0;const errors=[];page.on('pageerror',e=>errors.push(e.message)); await page.addInitScript(lang=>localStorage.setItem('idol:language',lang),language); await page.clock.install(); await context.route('**/*',async route=>{ const req=route.request(),u=new URL(req.url()),p=u.pathname; if(u.origin!==origin)return route.abort(); if(p==='/api/session')return route.fulfill({json:{csrf:'fixture',user:{username:'fffiloni'},sign_in_available:true,generation_available:true,image_generation_available:true,publication_available:true,dataset:'test/fixture'}}); if(p==='/api/workspace')return route.fulfill({json:{image:{id:'input',url:pixel},job:{id:'result',image_id:'input',status:'ready',parameters:{mode:'synthetic',steps:50,cfg_strength:3,rescale_t:3,seed:42,randomize_requested:false,num_gaussians:32768},result:{id:'result',url:'/fixture.ply',preview:pixel,bytes:1000,count:32768}}}}); if(p==='/api/generations/result/editorial'){ if(req.method()==='GET')return route.fulfill({json:{prompt:null}}); posts++;return route.fulfill({json:job(reserve)}); } if(p==='/api/editorial-jobs/description')return route.fulfill({json:job(status)}); if(p==='/api/publications'){published++;throw Error('Unexpected publication');} if(p==='/api/catalogue')return route.fulfill({json:{meta:{assetCount:0,generators:{}},assets:[]}}); if(p.startsWith('/api/')||p==='/fixture.ply'||p==='/examples/result.json')return route.fulfill({status:404,json:{detail:'Fixture'}}); return route.continue(); }); try{ await page.goto(origin+'/?tab=create',{waitUntil:'domcontentloaded'}); await page.locator('.result-actions .primary').click(); const panel=page.locator('.publish-panel'),notice=panel.locator('.editorial-status'),title=panel.locator('input[name=title]'),tags=panel.locator('input[name=tags]'); await notice.locator('.spin').waitFor();await title.fill('My leaf');await tags.fill('maple, green'); status='ready';await page.waitForFunction(()=>document.querySelector('.publish-panel textarea[name=description]')?.value.includes('FR :')); assert.equal(await notice.locator('.spin').count(),0);assert.equal(await title.inputValue(),'My leaf');assert.equal(await tags.inputValue(),'maple, green'); // A new page starts another private editing session; manual input immediately ends waiting. status=reserve='generating';await page.reload();await page.locator('.result-actions .primary').click();await notice.locator('.spin').waitFor(); await title.fill('Manual title');await panel.locator('select[name=category]').selectOption('plants');await tags.fill('leaf'); await notice.getByRole('button').click();assert.equal(await notice.locator('.spin').count(),0);assert.equal(await notice.getAttribute('aria-busy'),'false'); status='ready';await page.clock.fastForward(3000);assert.equal(await title.inputValue(),'Manual title');assert.equal(await panel.locator('textarea[name=description]').inputValue(),''); await panel.locator('header button').click();await page.locator('.result-actions .primary').click();assert.equal(await title.inputValue(),'Manual title');assert.equal(await notice.locator('.spin').count(),0); // A stalled request becomes an actionable timeout, then retry preserves prior edits. status='generating';await notice.getByRole('button').click();await notice.locator('.spin').waitFor(); await page.clock.fastForward(121000); await notice.filter({hasText:language==='fr'?'prend trop de temps':'taking too long'}).waitFor();assert.equal(await notice.locator('.spin').count(),0);assert.equal(await title.inputValue(),'Manual title'); reserve='ready';await notice.getByRole('button').click();await notice.filter({hasText:language==='fr'?'relisez et modifiez':'review and edit'}).waitFor(); assert.equal(await title.inputValue(),'Manual title');assert.equal(await tags.inputValue(),'leaf');assert.match(await panel.locator('textarea[name=description]').inputValue(),/FR :/); // A backend failure has no fake busy indicator and does not block rights review. status=reserve='failed';await page.reload();await page.locator('.result-actions .primary').click();await notice.filter({hasText:language==='fr'?'indisponible':'unavailable'}).waitFor(); assert.equal(await notice.locator('.spin').count(),0);await title.fill('Manual leaf');await panel.locator('select[name=category]').selectOption('plants'); await panel.locator('.publish-actions .primary').click();assert.equal(await notice.count(),0);assert.equal(await panel.locator('fieldset').nth(1).isVisible(),true); assert.equal(published,0);assert.deepEqual(errors,[]);assert.equal(await page.evaluate(()=>document.documentElement.scrollWidth>innerWidth+1),false); results.push({browser:engine.name(),language,lateResultPreservesEdits:true,manualStopsWaiting:true,draftSurvivesClose:true,timeoutAndRetry:true,failureAllowsManualReview:true,publicWrites:0}); console.log('EDITORIAL_LOADING_CASE '+JSON.stringify(results.at(-1))); if(engine===webkit&&language==='fr'){await panel.locator('.publish-actions .quiet').click();await notice.scrollIntoViewIfNeeded();await page.screenshot({path:'/tmp/editorial-loading-fr.png'});} }catch(error){console.log('EDITORIAL_LOADING_FAILURE '+JSON.stringify({browser:engine.name(),language,error:String(error),status:await page.locator('.editorial-status').innerText().catch(()=>''),errors,posts}));throw error;} finally{await context.close();} }}finally{await browser.close();} } await writeFile('/tmp/editorial-browser.json',JSON.stringify(results,null,2));console.log('EDITORIAL_LOADING_RESULT '+JSON.stringify(results)); }finally{await new Promise(ok=>server.close(ok));}