tools/client/test_mission_key_name.mjs (4171B)
1 import assert from 'node:assert/strict'; 2 import {createRequire} from 'node:module'; 3 import {GameTest} from './game_test.mjs'; 4 5 const {chromium} = createRequire(import.meta.url)('playwright'); 6 const [url, output] = process.argv.slice(2); 7 const browser = await chromium.launch({executablePath: '/usr/bin/chromium', args: [ 8 '--enable-gpu', '--use-gl=angle', '--use-angle=gl', '--no-sandbox', '--disable-dev-shm-usage', 9 '--disable-background-timer-throttling', '--disable-renderer-backgrounding']}); 10 let game; 11 try { 12 const context = await browser.newContext({viewport: {width: 1024, height: 768}}); 13 await context.addCookies([{name: 'ao_client', value: 'mission-key-name', url}]); 14 const page = await context.newPage(); 15 game = await GameTest.attach(page); 16 const openBank = async () => { 17 if (!game.state.camera.firstPerson) await game.key('F8'); 18 await game.click(...await game.pick(51005, 3221357727), 'right'); 19 await game.wait('bank opens', state => state.regions.some(region => 20 region[0] === 0 && region[1] === 0 && region[2] === 178 && region[3] === 128)); 21 }; 22 const roundTrip = async phase => { 23 await openBank(); 24 await game.click(681, 45); 25 await game.click(30, 45); 26 await game.wait('exact key banked', state => !game.local(state).inventory.some(item => item.id === 1)); 27 assert.deepEqual((await (await page.request.get(url + '/test-state')).json()).Bank.map(item => [item.ID, item.Slot]), [[1, 0]]); 28 await game.click(170, 8); 29 await game.wait('bank closes', state => !state.regions.some(region => 30 region[0] === 0 && region[1] === 0 && region[2] === 178 && region[3] === 128)); 31 await openBank(); 32 await page.keyboard.down('Shift'); 33 try { await game.click(30, 45); } 34 finally { await page.keyboard.up('Shift'); } 35 await game.save(output + '/bank-info-' + phase); 36 await game.click(30, 45); 37 await game.wait('same key withdrawn', state => game.local(state).inventory.some(item => item.id === 1 && item.slot === 48)); 38 await page.keyboard.down('Shift'); 39 try { await game.click(681, 45); } 40 finally { await page.keyboard.up('Shift'); } 41 await game.save(output + '/withdrawn-info-' + phase); 42 await game.click(170, 8); 43 await game.wait('bank closes after withdrawal', state => !state.regions.some(region => 44 region[0] === 0 && region[1] === 0 && region[2] === 178 && region[3] === 128)); 45 }; 46 await page.goto(url); 47 await game.ready(); 48 await page.waitForFunction(() => touchRegion(500, 400)?.world === true); 49 await game.snapshot(); 50 await game.key('KeyI'); 51 await game.save(output + '/before'); 52 // Flag2 must also permit ordinary keys without an instantiated custom name. 53 await roundTrip('unnamed'); 54 assert((await page.request.post(url + '/test-name')).ok()); 55 await game.wait('both named keys attached to real instances', state => 56 game.events.filter(event => event.direction === 'framereceived' && event.opcode === '3b11256f').length === 2 && 57 game.local(state).inventory.length === 2 && 58 game.local(state).inventory.every(item => item.type === 51053 && item.id !== 0)); 59 const updates = game.events.filter(event => event.direction === 'framereceived' && event.opcode === '3b11256f'); 60 assert.deepEqual(updates.map(event => Buffer.from(event.hex, 'hex')[54]), [48, 49]); 61 for (const slot of [48, 49]) { 62 const cell = game.state.grids.flatMap(grid => grid.cells).find(cell => 63 cell.identity[0] === 104 && cell.identity[1] === slot && !cell.dummy); 64 assert(cell, 'named key row remains usable'); 65 await page.keyboard.down('Shift'); 66 try { 67 await game.click((cell.bounds[0] + cell.bounds[2]) / 2, (cell.bounds[1] + cell.bounds[3]) / 2); 68 } finally { await page.keyboard.up('Shift'); } 69 await game.save(output + '/info-' + slot); 70 await game.key('Escape'); 71 } 72 73 // Reopening must retain the live name without another FullUpdate. 74 await roundTrip('named'); 75 assert.deepEqual(game.errors, []); 76 console.log('PASS: distinct native key names, unnamed/named bank round trips and exact cold ownership'); 77 } finally { 78 try { if (game) await game.save(output + '/final'); } 79 finally { await browser.close(); } 80 }