Files
shanhe-puzzle/tests/shake-preview.mjs
codex-bot 4845826deb
Shanhe source and offline package checks / verify (pull_request) Failing after 5s
feat: sync Shanhe 2.2 source and add remote package verification
2026-11-01 17:13:46 +08:00

17 lines
2.3 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import {chooseProvince,setDifficulty} from './helpers.mjs';
// Exercise only public game controls. The virtual clock accelerates a real round.
import {chromium} from 'playwright';import fs from 'node:fs';import assert from 'node:assert/strict';
const browser=await chromium.launch({executablePath:'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',headless:true});
const context=await browser.newContext({viewport:{width:390,height:844},deviceScaleFactor:2});
const page=await context.newPage(),errors=[];page.on('pageerror',e=>errors.push(e.message));await page.clock.install();await page.goto('http://localhost:4173');await page.waitForFunction(()=>window.shanheDebug);await setDifficulty(page,{speed:3});await page.locator('#start').click();await page.clock.runFor(7800);
let maxAngularSpeed=0,maxTilt=0,maxSpeed=0,maxEffects=0,collisions=0,observations=[];
for(let k=0;k<16;k++){
const key=k%2?'ArrowRight':'ArrowLeft';await page.keyboard.down(key);
for(let j=0;j<4;j++){await page.clock.runFor(90);const s=await page.evaluate(()=>window.shanheDebug.state());maxTilt=Math.max(maxTilt,...s.regions.map(r=>Math.abs(r.angle)));maxAngularSpeed=Math.max(maxAngularSpeed,...s.regions.map(r=>Math.abs(r.angularVelocity)));maxSpeed=Math.max(maxSpeed,...s.regions.map(r=>Math.hypot(r.vx,r.vy)));maxEffects=Math.max(maxEffects,s.impactCount);collisions=Math.max(collisions,s.collisionCount);observations.push({pieceCount:s.dropped,frame:s.shakeOffset,impactCount:s.impactCount,status:s.status});if(s.status!=='playing')break;}
await page.keyboard.up(key);await page.clock.runFor(120);
if([3,7,11,15].includes(k))await page.screenshot({path:'artifacts/shake-motion-'+k+'.png'});
}
await page.clock.runFor(1200);const final=await page.evaluate(()=>window.shanheDebug.state());assert.ok(collisions>0);assert.ok(maxEffects>0);assert.ok(maxAngularSpeed<=.0251);assert.ok(maxSpeed<18);assert.deepEqual(errors,[]);
fs.writeFileSync('artifacts/shake-preview-report.json',JSON.stringify({passed:true,method:'390×844 modern Chrome; real controls; virtual clock; 16 alternating holds',pieces:final.dropped,collisions,maxEffects,maxTiltDegrees:maxTilt*180/Math.PI,maxAngularSpeed,maxSpeed,errors,observations},null,2));
await context.close();console.log(JSON.stringify({pieces:final.dropped,collisions,maxEffects,maxTiltDegrees:maxTilt*180/Math.PI,maxAngularSpeed,maxSpeed}));await browser.close();