aorecomp

Anarchy Online classic in the browser

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


tools/client/test_stack_family.mjs (2706B)


      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',
      9   args: ['--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 try {
     13   const context = await browser.newContext({viewport: {width: 1024, height: 768}});
     14   await context.addCookies([{name: 'ao_client', value: 'stack-family', url}]);
     15   const page = await context.newPage();
     16   game = await GameTest.attach(page);
     17   await page.goto(url);
     18   await game.ready();
     19   await game.key('i');
     20   const click = async slot => {
     21     const source = game.state.grids.flatMap(grid => grid.cells).find(cell =>
     22       cell.identity[0] === 104 && cell.identity[1] === slot && !cell.dummy);
     23     assert(source, 'the exact selected-quality source must be usable');
     24     await game.click((source.bounds[0] + source.bounds[2]) / 2, (source.bounds[1] + source.bounds[3]) / 2);
     25   };
     26 
     27   // Opposite stored anchors describe the same selected native contract.
     28   for (const [removed, kept, quality] of [[48, 49, 2], [51, 50, 101]]) {
     29     const sequence = game.sequence;
     30     await click(removed);
     31     await click(kept);
     32     await game.wait('native selected-family join request', () => game.events.some(event => event.sequence > sequence &&
     33       event.direction === 'framesent' && event.opcode === '5e477770' && Buffer.from(event.hex, 'hex').readUInt32BE(29) === 53));
     34     await game.save(output + '/requested-' + quality);
     35     await game.wait('eight charges retained in the kept source', state => game.local(state).inventory.some(item =>
     36       item.slot === kept && item.quality === quality && item.count === 8) &&
     37       !game.local(state).inventory.some(item => item.slot === removed));
     38     assert.deepEqual(game.state.dragged, [0, 0]);
     39     await game.save(output + '/joined-' + quality);
     40   }
     41   await page.reload();
     42   await game.ready();
     43   assert.deepEqual(game.local().inventory.map(item => [item.id, item.slot, item.quality, item.count, ...item.templates]).sort((a, b) => a[0] - b[0]),
     44     [[2, 49, 2, 8, 25812, 25811], [3, 50, 101, 8, 25812, 25811]]);
     45   assert.deepEqual(game.errors, []);
     46   console.log('PASS: native reviewed-anchor joins conserve sixteen charges and exact page/cold identities');
     47 } finally {
     48   try {
     49     await fs.mkdir(output, {recursive: true});
     50     if (game) await game.save(output + '/final');
     51   } finally { await browser.close(); }
     52 }