tools/client/test_walk_approach.mjs (2894B)
1 import assert from 'node:assert/strict'; 2 import fs from 'node:fs/promises'; 3 import {createRequire} from 'node:module'; 4 import {GameTest} from './game_test.mjs'; 5 6 const {chromium} = createRequire(import.meta.url)('playwright'); 7 const [url, output] = process.argv.slice(2); 8 const browser = await chromium.launch({executablePath: '/usr/bin/chromium', 9 args: ['--enable-gpu', '--use-gl=angle', '--use-angle=gl', '--no-sandbox', '--disable-dev-shm-usage', 10 '--disable-background-timer-throttling', '--disable-renderer-backgrounding']}); 11 let game; 12 const evidence = {waypoints: []}; 13 try { 14 const context = await browser.newContext({viewport: {width: 1024, height: 768}}); 15 await context.addCookies([{name: 'ao_client', value: 'walk-approach', url}]); 16 const page = await context.newPage(); 17 game = await GameTest.attach(page); 18 const server = async () => (await page.request.get(url + '/test-state')).json(); 19 await page.goto(url); 20 await game.ready(); 21 await page.waitForFunction(() => touchRegion(500, 400)?.world === true); 22 evidence.initial = await server(); 23 24 // Approach both fractional coordinates and integers, including a lateral turn. 25 for (const [x, z] of [[15, 31.5], [15, 33], [15, 34.5], [16.5, 33.5], [15, 33]]) { 26 await game.walk(x, z); 27 const position = game.local().position; 28 assert(Math.hypot(position[0] - x, position[2] - z) < .35); 29 // Compact movement positions use 1/8-metre X/Z coordinates. 30 let state; 31 const deadline = Date.now() + 3000; 32 do { 33 await game.snapshot(); 34 state = await server(); 35 evidence.currentWaypoint = {target: [x, z], native: game.local().position, server: state.position}; 36 assert(Date.now() < deadline, 'Server did not retain the reached waypoint'); 37 } while (Math.hypot(state.position[0] - position[0], state.position[2] - position[2]) >= .2); 38 evidence.waypoints.push({target: [x, z], native: position, server: state.position}); 39 delete evidence.currentWaypoint; 40 await game.save(output + '/waypoint-' + evidence.waypoints.length); 41 } 42 43 // A blocked route must still fail, release forward input and allow recovery. 44 await assert.rejects(game.walk(15, 49), /Route is not approaching its destination/); 45 evidence.blocked = await server(); 46 assert(evidence.blocked.position[2] < 48.5); 47 await game.save(output + '/blocked'); 48 await game.walk(15, 43); 49 evidence.final = await server(); 50 assert.deepEqual(evidence.final.inventory, evidence.initial.inventory); 51 assert.deepEqual(game.errors, []); 52 console.log('PASS: fractional/integer approaches, real wall refusal and recovery at Run Speed ' + evidence.initial.speed); 53 } finally { 54 try { 55 await fs.mkdir(output, {recursive: true}); 56 await fs.writeFile(output + '/verification.json', JSON.stringify(evidence, null, 2) + '\n'); 57 if (game) await game.save(output + '/final'); 58 } finally { await browser.close(); } 59 }