tools/client/test_pending_stale_hand.mjs (5403B)
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', 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: 'pending-stale-hand', 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 const armor = [5, 5, 1, 1, 5, 5, 1, 5]; 20 await page.goto(url); 21 await game.ready(); 22 assert(game.local().inventory.some(item => item.id === 1 && item.slot === 6)); 23 await game.key('i'); 24 await page.keyboard.press('Control+1'); 25 await game.click(953, 53); 26 assert((await page.request.post(url + '/test-stale-view')).ok()); 27 28 // Hold vest wear while the native weapon still occupies its old hand. 29 const carried = game.state.grids.flatMap(grid => grid.cells).find(cell => 30 cell.identity[0] === 104 && cell.identity[1] === 48 && !cell.dummy); 31 assert(carried); 32 const first = game.sequence; 33 await game.click((carried.bounds[0] + carried.bounds[2]) / 2, (carried.bounds[1] + carried.bounds[3]) / 2); 34 await game.click(927, 148); 35 await game.wait('actual vest equip request', () => game.events.some(event => event.sequence > first && 36 event.direction === 'framesent' && event.opcode === '47537a24')); 37 evidence.pending = await server(); 38 assert.equal(evidence.pending.pending.itemID, 2); 39 await game.wait('native vest animation ends', state => !game.local(state).actions.includes(3) && !game.local(state).actions.includes(6)); 40 41 // A real removal request addresses the now-empty authoritative weapon hand. 42 await game.click(867, 53); 43 const sequence = game.sequence; 44 await game.click(867, 206, 'right'); 45 await game.wait('actual stale hand removal request', () => game.events.some(event => event.sequence > sequence && 46 event.direction === 'framesent' && event.opcode === '47537a24' && 47 Buffer.from(event.hex, 'hex').readUInt32BE(29) === 101 && Buffer.from(event.hex, 'hex').readUInt32BE(33) === 6)); 48 evidence.refused = await server(); 49 assert.deepEqual(evidence.refused, evidence.pending); 50 await game.save(output + '/requested'); 51 await game.wait('stale weapon hand cleared during pending vest wear', state => !game.local(state).inventory.some(item => item.slot === 6)); 52 const replies = game.events.filter(event => event.sequence > sequence && event.direction === 'framereceived' && 53 event.opcode === '5e477770').map(event => Array.from({length: 5}, (_, index) => Buffer.from(event.hex, 'hex').readUInt32BE(29 + index * 4))); 54 assert.deepEqual(replies, [[146, 101, 6, 0, 0], [97, 0, 0, 0, 6], [112, 101, 6, 0, 0]]); 55 await game.save(output + '/corrected'); 56 assert((await page.request.post(url + '/test-complete')).ok()); 57 await game.wait('original vest equip completes', state => game.local(state).inventory.some(item => item.id === 2 && item.slot === 21)); 58 assert.deepEqual(game.local().effectiveArmor, armor); 59 evidence.completed = await server(); 60 assert.equal(evidence.completed.pending, null); 61 62 // Replay exposes the exact axe at its committed carried slot for ordinary wear. 63 await page.reload(); 64 await game.ready(); 65 if (!game.state.grids.some(grid => grid.cells.some(cell => cell.identity[0] === 104 && cell.identity[1] === 49))) await game.key('i'); 66 await page.keyboard.press('Control+1'); 67 await game.wait('retained axe carried row available', state => state.grids.some(grid => grid.cells.some(cell => 68 cell.identity[0] === 104 && cell.identity[1] === 49 && !cell.dummy))); 69 const axe = game.state.grids.flatMap(grid => grid.cells).find(cell => 70 cell.identity[0] === 104 && cell.identity[1] === 49 && !cell.dummy); 71 const recovered = game.sequence; 72 await game.click((axe.bounds[0] + axe.bounds[2]) / 2, (axe.bounds[1] + axe.bounds[3]) / 2, 'right'); 73 await game.wait('actual recovered axe wear request', () => game.events.some(event => event.sequence > recovered && 74 event.direction === 'framesent' && event.opcode === '47537a24')); 75 assert((await page.request.post(url + '/test-complete')).ok()); 76 await game.wait('retained axe wears again', state => game.local(state).inventory.some(item => item.id === 1 && item.slot === 6)); 77 evidence.after = await server(); 78 assert.deepEqual(evidence.after.inventory.Items.map(item => [item.ID, item.Slot, item.Count]), [[1, 6, 1], [2, 21, 1]]); 79 assert.deepEqual(evidence.after.armor, armor); 80 assert.deepEqual(game.errors, []); 81 assert.equal(game.dropped, 0); 82 await game.save(output + '/retained'); 83 console.log('PASS: stale hand clears without changing pending armor wear; both exact items remain usable'); 84 } finally { 85 try { 86 await fs.mkdir(output, {recursive: true}); 87 await fs.writeFile(output + '/verification.json', JSON.stringify(evidence, null, 2) + '\n'); 88 if (game) await game.save(output + '/final'); 89 } finally { await browser.close(); } 90 }