tools/client/test_depleted_stack_split.mjs (4148B)
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: 'depleted-stack-split', 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 await game.key('KeyI'); 22 evidence.initial = await server(); 23 assert((await page.request.post(url + '/test-deplete-source')).ok()); 24 evidence.depleted = await server(); 25 assert.equal(evidence.depleted.inventory.Items[1].Count, 1); 26 const sequence = game.sequence; 27 await page.keyboard.down('Control'); 28 try { await game.click(681, 45); } finally { await page.keyboard.up('Control'); } 29 await game.wait('actual equal-count stale split', () => game.events.some(event => event.sequence > sequence && 30 event.direction === 'framesent' && event.opcode === '5e477770' && Buffer.from(event.hex, 'hex').readUInt32BE(29) === 52)); 31 evidence.requested = await server(); 32 await game.save(output + '/requested'); 33 await game.wait('only the actual remaining charge survives', snapshot => game.local(snapshot).inventory.length === 2 && 34 game.local(snapshot).inventory.some(item => item.slot === 48 && item.count === 1)); 35 assert.deepEqual(await server(), evidence.depleted); 36 if (game.state.dragged[0] !== 0) { 37 await game.click(735, 45); 38 await game.wait('corrected selected stack places normally', snapshot => snapshot.dragged[0] === 0); 39 } 40 await game.wait('corrected exact source icon is usable', snapshot => snapshot.grids.some(grid => grid.cells.some(cell => 41 cell.identity[0] === 104 && cell.identity[1] === 48 && !cell.dummy))); 42 await game.save(output + '/corrected'); 43 const restored = game.local().inventory.find(item => item.slot === 48); 44 assert.deepEqual([restored.quality, restored.count, ...restored.templates], [2, 1, 25812, 25811]); 45 assert.deepEqual(await server(), evidence.depleted); 46 47 // The corrected one-charge source must still heal through ordinary native Use. 48 if (!game.state.grids.some(grid => grid.cells.some(cell => cell.identity[0] === 104))) await game.key('KeyI'); 49 await game.key('F1'); 50 await game.key('KeyX'); 51 await game.wait('seated laboratory user', snapshot => game.local(snapshot).stats[430] === 2); 52 const source = game.state.grids.flatMap(grid => grid.cells).find(cell => 53 cell.identity[0] === 104 && cell.identity[1] === 48 && !cell.dummy); 54 assert(source); 55 await game.click((source.bounds[0] + source.bounds[2]) / 2, (source.bounds[1] + source.bounds[3]) / 2, 'right'); 56 await game.wait('actual last charge heals and retires', snapshot => game.local(snapshot).stats[27] === 38 && 57 game.local(snapshot).inventory.length === 1); 58 evidence.used = await server(); 59 assert.equal(evidence.used.health, 38); 60 assert.equal(evidence.used.inventory.LastID, 2); 61 await game.save(output + '/used'); 62 await page.reload(); 63 await game.ready(); 64 assert.deepEqual(game.local().inventory.map(item => [item.id, item.slot]), [[1, 6]]); 65 assert.deepEqual(await server(), evidence.used); 66 assert.deepEqual(game.errors, []); 67 console.log('PASS: equal-count stale split corrects its phantom, retains equipment and permits exact one-charge use with page/cold conservation'); 68 } finally { 69 try { 70 await fs.mkdir(output, {recursive: true}); 71 await fs.writeFile(output + '/verification.json', JSON.stringify(evidence, null, 2) + '\n'); 72 if (game) await game.save(output + '/final'); 73 } finally { await browser.close(); } 74 }