aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


tools/client/test_backpack_uploads.mjs (4698B)


      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: 'backpack-uploads', url}]);
     16   const page = await context.newPage();
     17   game = await GameTest.attach(page);
     18   await page.goto(url);
     19   await game.ready();
     20   const server = async () => (await page.request.get(url + '/test-state')).json();
     21   const cell = (page, slot) => game.state.grids.flatMap(grid => grid.cells).find(cell =>
     22     cell.identity[0] === page && cell.identity[1] === slot && !cell.dummy);
     23   const click = async (source, button = 'left') => {
     24     assert(source, 'exact source cell is usable');
     25     await game.click((source.bounds[0] + source.bounds[2]) / 2, (source.bounds[1] + source.bounds[3]) / 2, button);
     26   };
     27   const upload = async slot => {
     28     const sequence = game.sequence;
     29     await click(cell(107, 65536 | slot), 'right');
     30     await game.wait('actual contained upload Use', () => game.events.some(event => event.sequence > sequence &&
     31       event.direction === 'framesent' && event.opcode === '52526858' && Buffer.from(event.hex, 'hex').readUInt32BE(53) === 107));
     32     const request = game.events.find(event => event.sequence > sequence && event.direction === 'framesent' && event.opcode === '52526858');
     33     const reference = Buffer.from(request.hex, 'hex').readUInt32BE(33);
     34     await game.wait('exact upload completion', () => game.events.some(event => event.sequence > sequence &&
     35       event.direction === 'framereceived' && event.opcode === '52526858' && Buffer.from(event.hex, 'hex').readUInt32BE(33) === reference));
     36     const reply = game.events.find(event => event.sequence > sequence && event.direction === 'framereceived' &&
     37       event.opcode === '52526858' && Buffer.from(event.hex, 'hex').readUInt32BE(33) === reference);
     38     return {reference, result: Buffer.from(reply.hex, 'hex').readUInt32BE(29)};
     39   };
     40   await game.key('KeyI');
     41   await click(cell(104, 48), 'right');
     42   await game.wait('token, map and companion visible', () => cell(107, 65536) && cell(107, 65537) && cell(107, 65538));
     43   evidence.before = await server();
     44   evidence.token = await upload(0);
     45   evidence.map = await upload(1);
     46   await game.save(output + '/upload-results');
     47   assert.equal(evidence.token.result, 1);
     48   assert.equal(evidence.map.result, 1);
     49   await game.wait('both exact uploaded rows disappear', () => !cell(107, 65536) && !cell(107, 65537) && cell(107, 65538));
     50   await game.wait('native token count and map option update', () => game.local().stats[75] === 3 && game.local().stats[470] === 16);
     51   evidence.uploaded = await server();
     52   assert.equal(evidence.uploaded.OmniTokens, 3);
     53   assert.equal(evidence.uploaded.ClanTokens, 0);
     54   assert.deepEqual(evidence.uploaded.MapFlags, [16, 0, 0]);
     55   assert.deepEqual(evidence.uploaded.Containers[1].map(item => item.ID), [4]);
     56 
     57   // The remaining item stays usable without closing or refreshing the bag.
     58   await click(cell(107, 65538));
     59   await game.wait('companion picked', state => state.dragged[0] === 107 && state.dragged[1] === 65538);
     60   await click(game.state.grids.find(grid => grid.totalCells === 30).cells.find(cell => cell.identity[0] === 0));
     61   await game.wait('exact companion withdraws', state => game.local(state).inventory.some(item => item.id === 4 && item.slot === 49));
     62   evidence.after = await server();
     63   await game.save(output + '/verified');
     64   await page.reload();
     65   await game.ready();
     66   assert.deepEqual(await server(), evidence.after);
     67   assert.equal(game.local().stats[75], 3);
     68   assert.equal(game.local().stats[470], 16);
     69   assert.deepEqual(game.local().inventory.map(item => [item.id, item.slot]), [[1, 48], [4, 49]]);
     70   assert.deepEqual(game.errors, []);
     71   assert.equal(game.dropped, 0);
     72   console.log('PASS: contained token/map uploads consume exact children with persistent metadata; companion and page/cold ownership remain exact');
     73 } finally {
     74   try {
     75     await fs.mkdir(output, {recursive: true});
     76     await fs.writeFile(output + '/verification.json', JSON.stringify(evidence, null, 2) + '\n');
     77     if (game) await game.save(output + '/final');
     78   } finally { await browser.close(); }
     79 }