tools/client/test_effective_armor.mjs (3327B)
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, phase] = process.argv.slice(2); 8 const browser = await chromium.launch({executablePath: '/usr/bin/chromium', args: [ 9 '--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 = {}; 13 try { 14 const context = await browser.newContext({viewport: {width: 1024, height: 768}}); 15 await context.addCookies([{name: 'ao_client', value: 'effective-armor', url}]); 16 const page = await context.newPage(); 17 game = await GameTest.attach(page); 18 await page.goto(url); 19 await game.ready(); 20 const expected = [9, 10, 2, 2, 9, 9, 2, 6]; 21 const verify = async (label, armor) => { 22 await game.wait(label + ' effective armor', state => 23 JSON.stringify(game.local(state).effectiveArmor) === JSON.stringify(armor)); 24 const state = await (await page.request.get(url + '/test-state')).json(); 25 assert.deepEqual(state.armor, armor); 26 assert.deepEqual(game.local().stats.slice(90, 98), [0, 0, 0, 0, 0, 0, 0, 0]); 27 evidence[label] = {server: state, armor: game.local().effectiveArmor}; 28 await game.save(output + '/' + label); 29 }; 30 const protection = async label => { 31 await game.key('u'); 32 await game.click(302, 427); 33 await game.save(output + '/' + label + '-protection'); 34 await game.click(544, 622); 35 }; 36 const move = async (x, y, slot) => { 37 await game.wait('previous native equipment action ends', state => 38 !game.local(state).actions.includes(3) && !game.local(state).actions.includes(6)); 39 const sequence = game.sequence; 40 await game.click(x, y, 'right'); 41 await game.wait('real vest move request', () => game.events.some(event => event.sequence > sequence && 42 event.direction === 'framesent' && event.opcode === '47537a24')); 43 await game.wait('vest reaches its exact slot', state => game.local(state).inventory.some(item => item.id === 1 && item.slot === slot)); 44 }; 45 await game.key('i'); 46 await page.keyboard.press('Control+1'); 47 await game.click(953, 53); 48 if (phase === 'warm') { 49 await verify('unworn', [0, 0, 0, 0, 0, 0, 0, 0]); 50 await move(681, 45, 21); 51 await verify('worn', expected); 52 await protection('worn'); 53 await move(927, 148, 48); 54 await verify('removed', [0, 0, 0, 0, 0, 0, 0, 0]); 55 await protection('removed'); 56 await move(681, 45, 21); 57 await verify('reworn', expected); 58 await page.reload(); 59 await game.ready(); 60 await verify('page-replay', expected); 61 await protection('page-replay'); 62 } else { 63 assert.equal(phase, 'cold'); 64 await verify('cold', expected); 65 await protection('cold'); 66 } 67 assert.deepEqual(game.errors, []); 68 assert.equal(game.dropped, 0); 69 console.log('PASS: ' + phase + ' raw/effective AC snapshots retain all eight vest defenses'); 70 } finally { 71 try { 72 await fs.mkdir(output, {recursive: true}); 73 await fs.writeFile(output + '/verification.json', JSON.stringify(evidence, null, 2) + '\n'); 74 if (game) await game.save(output + '/final'); 75 } finally { await browser.close(); } 76 }