tools/client/test_scanner_refusal.mjs (3054B)
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', 8 args: ['--enable-gpu', '--use-gl=angle', '--use-angle=gl', '--no-sandbox', '--disable-dev-shm-usage', 9 '--disable-background-timer-throttling', '--disable-renderer-backgrounding']}); 10 const games = []; 11 try { 12 for (const id of [1, 2]) { 13 const context = await browser.newContext({viewport: {width: 1024, height: 768}}); 14 await context.addCookies([{name: 'ao_client', value: 'scanner-' + id, url}]); 15 const page = await context.newPage(); 16 const game = await GameTest.attach(page); 17 games.push(game); 18 await page.goto(url); 19 await game.ready(); 20 const server = async () => (await page.request.get(url + '/test-state')).json(); 21 const before = await server(); 22 assert.equal(before.inventory.Reclaim[0].Item.ID, id); 23 for (let attempt = 0; attempt < 2; ++attempt) { 24 const sequence = game.sequence; 25 const [x, y] = await game.pick(51005, 0xc00802c1); 26 await game.click(x, y, 'right'); 27 await game.wait('native reclaim-before-save feedback', () => game.events.some(event => 28 event.sequence > sequence && event.direction === 'framereceived' && event.opcode === '50544d19' && 29 Buffer.from(event.hex, 'hex').readUInt32BE(29) === 64)); 30 assert.deepEqual(await server(), before); 31 await game.save(output + '/' + id + '-refused-' + attempt); 32 } 33 if (id === 2) { 34 const [x, y] = await game.pick(51059, 0xc00a02c1); 35 await game.click(x, y, 'right'); 36 await game.wait('native reclaim window', state => state.regions.some(region => 37 region[0] === 0 && region[1] === 0 && region[2] === 178 && region[3] === 128)); 38 await game.click(30, 45); 39 await game.wait('same item collected into native inventory', state => 40 game.local(state).inventory.some(item => item.id === 2)); 41 await game.click(170, 8); 42 const [saveX, saveY] = await game.pick(51005, 0xc00802c1); 43 await game.click(saveX, saveY, 'right'); 44 await game.wait('insurance after collection', state => game.local(state).stats[236] === 38650); 45 const after = await server(); 46 assert.equal(after.insurance, 0xc00802c1); 47 assert.equal(after.insuredExperience, 38650); 48 assert.equal(after.inventory.Reclaim, null); 49 assert.deepEqual(after.inventory.Items, [{...before.inventory.Reclaim[0].Item, Slot: 64}]); 50 await game.save(output + '/collected-and-saved'); 51 } 52 assert.deepEqual(game.errors, []); 53 await context.close(); 54 } 55 console.log('PASS: pending/available reclaim explains repeated native refusals; exact collection permits saving'); 56 } finally { 57 try { for (const [index, game] of games.entries()) if (!game.page.isClosed()) await game.save(output + '/final-' + index); } 58 finally { await browser.close(); } 59 }