File size: 6,428 Bytes
ef987bb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
let enhancedFailed=0;
const fs=require('fs');const path=require('path');const{pathToFileURL}=require('url');const{chromium}=require('playwright');
function a(x,m){if(!x)throw new Error(m)}function near(x,y,m){a(Math.abs(x-y)<1e-9,`${m}: got ${x} want ${y}`)}function eq(x,y,m){a(require("node:util").isDeepStrictEqual(x,y),`${m}: got ${JSON.stringify(x)} want ${JSON.stringify(y)}`)}async function tc(id,f){try{await f();console.log(id+' PASS')}catch(e){console.error(id+' FAIL: '+e.message);enhancedFailed++}}
(async()=>{const b=await chromium.launch({headless:true,args:['--no-sandbox','--disable-dev-shm-usage']});const p=await b.newPage();await p.goto(pathToFileURL(path.join(process.cwd(),'index.html')).href);
// ENHANCED_CASE_1: non-16ms fixed steps use the specified semi-implicit integration and proportional pipe motion.
await tc('ENHANCED_CASE_1',async()=>{const s=await p.evaluate(()=>{__game.init({birdX:80,birdR:12,pipeWidth:52,gravity:2,pipeSpeed:4,width:500,height:400,birdY:100,birdVy:1,pipes:[{x:300,gapY:40,gapH:200,passed:false}],status:'playing'});return __game.step(8)});near(s.bird.vy,2,'vy');near(s.bird.y,101,'y');near(s.pipes[0].x,298,'pipe x');const dims=await p.locator('[data-testid=canvas]').evaluate(c=>[c.width,c.height]);eq(dims,[500,400],'injected canvas geometry');await p.waitForTimeout(100);eq(await p.evaluate(()=>__game.getState()),s,'manual state must not advance on rAF')});
// ENHANCED_CASE_2: each passed pipe scores exactly once across repeated fixed steps.
await tc('ENHANCED_CASE_2',async()=>{const r=await p.evaluate(()=>{__game.init({birdX:80,birdR:12,pipeWidth:52,gravity:0,pipeSpeed:10,width:500,height:400,birdY:200,birdVy:0,pipes:[{x:500,gapY:-100,gapH:800,passed:false}],status:'playing'});const scores=[];for(let i=0;i<100&&__game.getState().score===0;i++){scores.push(__game.step(16).score)}const crossed=__game.getState();for(let i=0;i<10;i++)__game.step(16);const final=__game.getState();__game.init({birdX:60,birdR:12,pipeWidth:52,gravity:0,pipeSpeed:3,width:300,height:300,birdY:250,birdVy:0,pipes:[{x:10,gapY:40,gapH:100,passed:false}],status:'playing'});const collision=__game.step(16);return{scores,crossed,final,collision}});eq(r.crossed.score,1,'score at crossing');eq(r.final.score,1,'score after crossing');a(r.crossed.pipes[0].passed,'pipe not marked passed');eq(r.collision.status,'over','unsafe crossing must collide');eq(r.collision.score,0,'unsafe crossing must not score')});
// ENHANCED_CASE_3: ground and ceiling use the center, even when the painted bird overlaps.
await tc('ENHANCED_CASE_3', async () => {
 const results = await p.evaluate(() => {
  const height = 300;
  const base = {birdX: 80, birdR: 12, gravity: 0, width: 500, height, pipes: [], status: 'playing'};
  return [[6, -3], [height - 6, 3]].map(([birdY, birdVy]) => {
   __game.init({...base, birdY, birdVy});
   const inside = __game.step(16);
   const boundary = __game.step(16);
   const frozen = __game.getState();
   __game.flap();
   __game.step(16);
   return {inside, boundary, frozen, after: __game.getState()};
  });
 });
 for (const [index, {inside, boundary, frozen, after}] of results.entries()) {
  const edge = index === 0 ? 'ceiling' : 'ground';
  eq(inside.status, 'playing', `${edge}: an overlapping outline must not end play before the center reaches the boundary`);
  eq(boundary.status, 'over', `${edge}: reaching the boundary with the center must end play`);
  eq(after, frozen, `${edge}: flap and step must leave the finished game unchanged`);
 }
});

await tc('EXACT_SEQUENCE_AND_SEEDS',async()=>{
 const result=await p.evaluate(()=>{
  const cfg={seed:19,status:'playing',gravity:.37,flapImpulse:3,pipeSpeed:1.5,birdY:150,birdVy:-1,width:600,height:900,pipes:[]};
  __game.init(cfg);let y=150,vy=-1;const steps=[4,16,7,24,0,9];
  const errors=[];for(const dt of steps){vy+=.37*dt/16;y+=vy*dt/16;const s=__game.step(dt);errors.push(Math.abs(s.bird.y-y)+Math.abs(s.bird.vy-vy))}
  const one=__game.init({seed:19}).pipes,two=__game.init({seed:27}).pipes,again=__game.init({seed:19}).pipes;
  const copy=__game.getState();copy.bird.y=-999;copy.pipes[0].gapY=-999;
  return {errors,one,two,again,safe:__game.getState()};
 });
 a(result.errors.every(error=>error<1e-8),'every variable step must follow exact public integration');
 eq(result.one,result.again,'seed reproducibility');a(!require('util').isDeepStrictEqual(result.one,result.two),'seeds must influence pipe generation');
 a(result.safe.bird.y!==-999&&result.safe.pipes[0].gapY!==-999,'public state must be copied');
});
await tc('ACTUAL_CANVAS_AND_INPUT',async()=>{
 const painted=await p.evaluate(()=>{
  const cfg={gravity:0,pipeSpeed:0,birdX:80,birdR:10,pipeWidth:30,width:400,height:300,birdY:120,pipes:[],status:'playing'};
  const data=()=>Array.from(document.querySelector('[data-testid=canvas]').getContext('2d').getImageData(0,0,400,300).data);
  __game.init(cfg);const first=data();__game.init({...cfg,birdY:220});const second=data();
  __game.init({...cfg,pipes:[{x:250,gapY:80,gapH:120,passed:false}]});const third=data();
  let oldBird=0,newBird=0,pipe=0;
  for(let y=0;y<300;y++)for(let x=0;x<400;x++){const i=(y*400+x)*4;
   const changed=(a,b)=>a.slice(i,i+4).some((v,n)=>v!==b[i+n]);
   if(changed(first,second)&&Math.abs(x-80)<=12){if(Math.abs(y-120)<=12)oldBird++;if(Math.abs(y-220)<=12)newBird++}
   if(changed(first,third)&&x>=250&&x<280&&(y<80||y>200))pipe++;
  }
  return {oldBird,newBird,pipe};
 });
 a(painted.oldBird>100&&painted.newBird>100&&painted.pipe>100,'render must follow bird and pipe geometry');
 fs.mkdirSync('/logs/verifier/visual-audit',{recursive:true});await p.screenshot({path:'/logs/verifier/visual-audit/injected-scene.png'});
 await p.evaluate(()=>__game.init({flapImpulse:3,gravity:0,birdY:150,pipes:[]}));
 await p.locator('[data-testid=flap]').click();near((await p.evaluate(()=>__game.getState())).bird.vy,-3,'real flap button');
 await p.keyboard.press('Space');near((await p.evaluate(()=>__game.getState())).bird.vy,-3,'space key');
 await p.evaluate(()=>__game.init({gravity:0,birdY:0,status:'playing',pipes:[]}));
 await p.evaluate(()=>__game.step(0));eq((await p.locator('[data-testid=status]').innerText()).trim(),'over','visible game over');
 await p.screenshot({path:'/logs/verifier/visual-audit/game-over.png'});
});
await b.close();console.log('ENHANCED_SCORE='+((5-enhancedFailed)/5));})().catch(e=>{console.error(e.stack||e);process.exit(1)});