34 lines
4.5 KiB
JavaScript
34 lines
4.5 KiB
JavaScript
const {chromium}=require('playwright');const assert=require('node:assert/strict');const fs=require('node:fs');const path=require('node:path');const {pathToFileURL}=require('node:url');const engine=require('../site/engine.js');
|
|
(async()=>{
|
|
const out=path.resolve(__dirname,'../evidence');const url=pathToFileURL(path.resolve(__dirname,'../site/index.html')).href;
|
|
const browser=await chromium.launch({executablePath:process.env.CHROME_PATH || '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',args:['--no-sandbox']});const errors=[],external=[];
|
|
try {
|
|
for(const [name,width,height] of [['desktop',1280,900],['phone',390,844]]){
|
|
const page=await browser.newPage({viewport:{width,height},acceptDownloads:true});page.on('pageerror',e=>errors.push(e.message));page.on('request',r=>{if(/^https?:/.test(r.url()))external.push(r.url());});
|
|
await page.goto(url);await page.waitForFunction(()=>document.querySelector('#status').textContent.includes('exchanges kept'));
|
|
assert.equal(await page.evaluate(()=>document.documentElement.scrollWidth<=innerWidth),true);
|
|
const source=await page.locator('#source').textContent();const priorities={e001:'pinned',e002:'normal',e003:'aside',e004:'normal'};
|
|
assert.equal(await page.locator('#packet').textContent(),engine.select(engine.parse(source),priorities,1000).packet);
|
|
assert.match(await page.locator('#packet').textContent(),/tool_call_id/);assert.doesNotMatch(await page.locator('#packet').textContent(),/green hat/);
|
|
await page.screenshot({path:path.join(out,name+'.png'),fullPage:true});
|
|
for(const [selector,filename] of [['#download',name+'-packet.md'],['#manifest-download',name+'-manifest.json']]){
|
|
const [download]=await Promise.all([page.waitForEvent('download'),page.locator(selector).click()]);await download.saveAs(path.join(out,filename));
|
|
}
|
|
assert.equal(fs.readFileSync(path.join(out,name+'-packet.md'),'utf8'),await page.locator('#packet').textContent());
|
|
assert.equal(JSON.parse(fs.readFileSync(path.join(out,name+'-manifest.json'),'utf8')).packetBytes,Buffer.byteLength(fs.readFileSync(path.join(out,name+'-packet.md'),'utf8')));
|
|
await page.locator('select[data-id="e003"]').selectOption('pinned');assert.match(await page.locator('#packet').textContent(),/green hat/);
|
|
await page.locator('#budget').fill('100');assert.match(await page.locator('#status').textContent(),/Budget too small/);assert.equal(await page.locator('#download').isDisabled(),true);assert.equal(await page.locator('#manifest-download').isDisabled(),true);
|
|
await page.locator('#budget').fill('2000');assert.equal(await page.locator('#download').isDisabled(),false);
|
|
const form=await page.locator('#join-form').evaluate(f=>({method:f.method,action:f.getAttribute('action'),enctype:f.enctype,fields:Object.fromEntries(new FormData(f))}));
|
|
assert.equal(form.method,'post');assert.equal(form.action,'/api/signup');assert.equal(form.enctype,'application/x-www-form-urlencoded');assert.equal(form.fields.venture,'context-priority');assert.equal(form.fields.website,'');assert.equal(form.fields.plan,'free');
|
|
assert.equal(await page.locator('a[download]').getAttribute('href'),'context-priority.zip');
|
|
const [bundle]=await Promise.all([page.waitForEvent('download'),page.locator('a[download]').click()]);
|
|
const bundlePath='/tmp/priority-'+name+'-download.zip';await bundle.saveAs(bundlePath);
|
|
assert.deepEqual(fs.readFileSync(bundlePath),fs.readFileSync(path.resolve(__dirname,'../site/context-priority.zip')));
|
|
await page.goto(url+'?joined=1#join');assert.equal(await page.locator('#thanks').isVisible(),true);assert.equal(await page.locator('#join-form').isVisible(),false);await page.close();
|
|
}
|
|
assert.deepEqual(errors,[]);assert.deepEqual(external,[]);
|
|
fs.writeFileSync(path.join(out,'browser.json'),JSON.stringify({platform:process.platform,browser:await browser.version(),viewports:['1280x900','390x844'],route:'file:// site/index.html (publication happens after reply)',checks:['no horizontal overflow','shared engine parity','paired tool exchange','priority changes','pin budget refusal','packet + manifest + free bundle downloads','plain signup form','thank-you redirect state','no external requests','no JS errors'],htmlSha256:require('node:crypto').createHash('sha256').update(fs.readFileSync(path.resolve(__dirname,'../site/index.html'))).digest('hex')},null,2)+'\n');console.log('PASS: desktop and phone screenshots, download parity, pins, budget refusal, form, thank-you, no external requests or JS errors');
|
|
}finally{await browser.close();}
|
|
})().catch(e=>{console.error(e);process.exitCode=1;});
|