idol-commons / frontend /scripts /theme-acceptance.mjs
fffiloni's picture
Restore Hub ZeroGPU quota handshake and clarify recoverable errors
e4a8344 verified
Raw History Blame Contribute Delete
12 kB
import {chromium} from 'playwright';
import {readFile,writeFile,mkdir} from 'node:fs/promises';
import assert from 'node:assert/strict';
const browser=await chromium.launch({headless:true,args:['--no-sandbox','--disable-dev-shm-usage','--use-gl=angle','--use-angle=swiftshader','--enable-unsafe-swiftshader']});
const origin='http://127.0.0.1:7860',results=[];
const framing=JSON.parse(await readFile('reports/render-evidence/framing.json','utf8'));
const asset={id:'12345678-1234-4234-8234-123456789abc',sequence:0,name:'Reference backpack',dataset:'test/reference',author:'fixture-author',contributorVerified:true,category:'other',tags:['hiking','outdoors'],publishedAt:'2026-10-31T12:00:00Z',folder:'fixture',path:'model.ply',revision:'a'.repeat(40),source:'#',sourceFolder:'#',download:'/fixture/model.ply',image:'',imageFallback:'',preview:'/fixture/preview.png',previewSmall:'/fixture/preview.png',previewCrop:[...framing.crop,1024,1024],camera:framing.camera,model:'/fixture/model.ply',bytes:17826208,modelSha256:'4727fcad83cd97efd750a09e5db2a48d0b88817710a0f98ba570c05fc77723cb',imageSha256:'392e6aee53dd2882b58ec3e6c6bac37dcdbf0779be6fde867e85903619b017d9',license:'Apache-2.0',format:'ply-3dgs',generator:'IDOL',description:'Test reference only',workflow:'test',sourceId:'test',animationCount:0};
await mkdir('reports/screenshots',{recursive:true});
try{
for(const width of [1440,390,320]){
const checkpoint=step=>console.log(JSON.stringify({stage:'collection_browser',width,step}));checkpoint('start');
const context=await browser.newContext({viewport:{width,height:width===1440?1000:844},isMobile:width<700,hasTouch:width<700,colorScheme:'light',reducedMotion:'reduce'});
let assets=[];
const page=await context.newPage(),errors=[];
const choose=async name=>{if(width<1440)await page.getByRole('button',{name,exact:true}).click();};page.on('pageerror',e=>errors.push(e.message));
await page.route('**/api/session',r=>r.fulfill({json:{csrf:'test',user:null,sign_in_available:false,generation_available:false,image_generation_available:true,publication_available:false,dataset:'fffiloni/idol-community-assets'}}));
await page.route('**/api/workspace',r=>r.fulfill({json:{image:null,job:null}}));
await page.route('**/api/catalogue',r=>r.fulfill({json:{meta:{assetCount:assets.length,generators:{IDOL:assets.length}},assets}}));
await page.route('**/fixture/model.ply',r=>r.fulfill({path:'fixture/model.ply',contentType:'application/octet-stream'}));
await page.route('**/fixture/preview.png',r=>r.fulfill({path:'reports/render-evidence/reference-preview-small.png',contentType:'image/png'}));
await page.goto(origin,{waitUntil:'networkidle'});
const frame=page.frameLocator('iframe');
if(width<1440)await page.getByRole('button',{name:'Collection',exact:true}).getAttribute('aria-current').then(v=>assert.equal(v,'page'));
else {assert.equal(await page.locator('.create-page').isVisible(),true);assert.equal(await page.locator('.explore-page').isVisible(),true);}
assert.equal(await page.getByRole('link',{name:'View dataset',exact:true}).getAttribute('href'),'https://huggingface.co/datasets/fffiloni/idol-community-assets');
await frame.getByText('Let’s build the 3D commons together.',{exact:true}).waitFor();
await page.screenshot({path:`reports/screenshots/theme-${width}-collection-empty.jpg`,type:'jpeg',quality:75,timeout:60000});
await frame.getByRole('button',{name:'Contribute an asset',exact:true}).click();
await page.getByRole('heading',{name:'Bring an idea to the commons.',exact:true}).waitFor();
await page.getByRole('button',{name:'From a prompt',exact:true}).click();
await page.getByLabel('Describe an object').fill('A ceramic cup on a plain background');
await choose('Collection');
await choose('Contribute');
assert.equal(await page.getByLabel('Describe an object').inputValue(),'A ceramic cup on a plain background');
await page.getByRole('button',{name:'Upload image',exact:true}).click();
for (const [w,h] of [[400,400],[300,600],[600,300]]) {
const data=await page.evaluate(([w,h])=>{const c=document.createElement('canvas');c.width=w;c.height=h;const x=c.getContext('2d');x.fillStyle='#f5c84b';x.fillRect(0,0,w,h);return c.toDataURL('image/png').split(',')[1];},[w,h]);
const buffer=Buffer.from(data,'base64');
await page.route('**/api/images',r=>r.fulfill({json:{id:'image-fixture',url:`/fixture/input-${w}-${h}.png`}}));
await page.route(`**/fixture/input-${w}-${h}.png`,r=>r.fulfill({body:buffer,contentType:'image/png'}));
await page.locator('input[type=file]').setInputFiles({name:'input.png',mimeType:'image/png',buffer});
await page.waitForFunction(([w,h])=>{const i=document.querySelector('.upload-target img');return i&&i.complete&&i.naturalWidth===w&&i.naturalHeight===h;},[w,h]);
const bounds=await page.locator('.upload-target').boundingBox();assert.ok(Math.abs(bounds.width/bounds.height-w/h)<0.035,`Input border must follow image aspect ratio: ${w}x${h} -> ${JSON.stringify(bounds)}`);
await page.unroute(`**/fixture/input-${w}-${h}.png`);await page.unroute('**/api/images');
}
checkpoint('input_aspect_and_prompt_state_passed');
assets=[asset];checkpoint('empty_collection_and_contribution_route_passed');
const brand=await page.locator('.commons-brand').boundingBox(),account=await page.locator('.account').boundingBox();
assert.ok(brand&&account&&brand.x+brand.width<=account.x,'Brand and account controls must not overlap');
await page.getByRole('button',{name:'Dark theme',exact:true}).click();
await page.waitForFunction(()=>document.documentElement.dataset.theme==='dark'&&document.querySelector('iframe').contentDocument.documentElement.dataset.theme==='dark');
await page.screenshot({path:`reports/screenshots/theme-${width}-create-dark.jpg`,fullPage:true,type:'jpeg',quality:75,timeout:60000});
await choose('Collection');
await frame.locator('html').evaluate(()=>document.dispatchEvent(new Event('visibilitychange')));
assert.equal(await frame.getByRole('button',{name:'Night mode',exact:true}).count(),0);
await frame.getByLabel('Search objects',{exact:true}).fill('backpack');
await frame.getByRole('button',{name:'Zoom in',exact:true}).click();
await frame.getByRole('button',{name:'Inspect Reference backpack',exact:true}).click();
await frame.getByText('3D ready · Drag object to rotate',{exact:true}).waitFor({timeout:120000});checkpoint('real_splat_ready');
await frame.getByRole('button',{name:'Report this object',exact:true}).click();
await page.getByRole('dialog').waitFor();
await page.getByRole('link',{name:'HF’s reporting channels',exact:true}).waitFor();
await page.getByRole('button',{name:'Close dialog',exact:true}).click();
checkpoint('visible_report_route_passed');
await frame.getByRole('button',{name:'Add to basket',exact:true}).click();
await page.waitForTimeout(400);
const before=await frame.locator('.world').getAttribute('style');
assert.equal(await frame.locator('.selection-contributor a').getAttribute('href'),'https://huggingface.co/fixture-author');
assert.equal(await frame.locator('.selection-category').textContent(),'other');checkpoint('contributor_visible');
await frame.getByRole('button',{name:'Object information',exact:true}).click();
await frame.getByRole('list',{name:'Contributor tags'}).getByText('hiking',{exact:true}).waitFor();
await frame.getByText('2026-10-31',{exact:true}).waitFor();checkpoint('metadata_visible');
await frame.locator('.viewer-host canvas').evaluate(el=>el.dataset.themeProof='same-canvas');
// Keep the real rendered canvas, but pause the SwiftShader animation loop during screenshots.
// This uses the same visibility message as a hidden workspace; no renderer is replaced.
await page.evaluate(()=>document.querySelector('iframe').contentWindow.postMessage({type:'idol:active',active:false},location.origin));
await page.waitForTimeout(250);
if(width===1440)await page.screenshot({path:'reports/screenshots/theme-1440-contributor-info.jpg',type:'jpeg',quality:75,timeout:60000});
// A catalogue update refreshes labels of the selected object without recreating WebGL.
assets=[{...asset,tags:['hiking','woodland']}];
await frame.locator('html').evaluate(()=>document.dispatchEvent(new Event('visibilitychange')));
await frame.getByRole('list',{name:'Contributor tags'}).getByText('woodland',{exact:true}).waitFor();checkpoint('metadata_refresh_passed');
assert.equal(await frame.locator('.viewer-host canvas').getAttribute('data-theme-proof'),'same-canvas');
assert.equal(await frame.locator('.world').getAttribute('style'),before);
await frame.getByRole('button',{name:'Object information',exact:true}).click();
if(width===1440){
for(const size of [{width:820,height:1000},{width:1000,height:700},{width:390,height:844},{width:1440,height:1000}]){
await page.setViewportSize(size);
if(size.width<1440)await page.getByRole('button',{name:'Collection',exact:true}).click();
await page.waitForTimeout(150);
assert.equal(await frame.locator('.viewer-host canvas').getAttribute('data-theme-proof'),'same-canvas');
assert.equal(await frame.getByLabel('Search objects',{exact:true}).inputValue(),'backpack');
assert.equal(await frame.locator('.world').getAttribute('style'),before);
await frame.getByRole('button',{name:'Open basket, 1 objects',exact:true}).waitFor();
}
checkpoint('fold_and_resize_state_preserved');
}
await choose('Contribute');
await choose('Collection');
await page.evaluate(()=>document.querySelector('iframe').contentWindow.postMessage({type:'idol:active',active:false},location.origin));
for(const theme of ['light','dark']){
if(await page.locator('html').getAttribute('data-theme')!==theme)await page.getByRole('button',{name:theme==='light'?'Light theme':'Dark theme',exact:true}).click();
await page.waitForFunction(theme=>document.querySelector('iframe').contentDocument.documentElement.dataset.theme===theme,theme);
assert.equal(await frame.locator('.world').getAttribute('style'),before);
assert.equal(await frame.locator('.viewer-host canvas').getAttribute('data-theme-proof'),'same-canvas');
assert.equal(await frame.getByLabel('Search objects',{exact:true}).inputValue(),'backpack');
await frame.getByRole('button',{name:'Open basket, 1 objects',exact:true}).waitFor();
const palette=await page.evaluate(()=>{
const a=getComputedStyle(document.documentElement),b=getComputedStyle(document.querySelector('iframe').contentDocument.documentElement);
return ['--ink','--surface','--canvas','--primary','--line'].every(key=>a.getPropertyValue(key)===b.getPropertyValue(key));
});assert.ok(palette,'Both workspaces must use the same palette');
assert.equal(await page.evaluate(()=>document.documentElement.scrollWidth>innerWidth),false);
await page.screenshot({path:`reports/screenshots/theme-${width}-explore-${theme}.jpg`,type:'jpeg',quality:75,timeout:60000});
}
await choose('Contribute');
await page.reload({waitUntil:'networkidle'});
assert.equal(await page.locator('html').getAttribute('data-theme'),'dark');
const buttons=await page.getByRole('group',{name:'Color theme'}).boundingBox();assert.ok(buttons&&buttons.x>=0&&buttons.x+buttons.width<=width);
assert.deepEqual(errors,[]);
results.push({width,paletteUnified:true,themePersists:true,canvasPreserved:true,viewSelectionSearchBasketPreserved:true,collectionFirst:true,datasetLink:true,emptyContributionRoute:true,contributorCategoryTagsVisible:true,selectedMetadataRefreshWithoutRemount:true,inputAspectRatios:true,promptStatePreserved:true,visibleReportRoute:true,mobileEmulated:width<700,errors});
checkpoint('passed');await context.close();
}
console.log(JSON.stringify({stage:'theme_acceptance_passed',browser:browser.version(),results}));
await writeFile('reports/theme-acceptance.json',JSON.stringify({browser:browser.version(),results},null,2)+'\n');
}finally{await browser.close();}