tools/client/test_stationary_clinic.mjs (7592B)
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 const games = [], sockets = [], evidence = {}; 12 try { 13 for (const index of [0,1]) { 14 const context = await browser.newContext({viewport:{width:1024,height:768}}); 15 await context.addCookies([{name:'ao_client',value:'stationary-clinic-'+index,url}]); 16 const page = await context.newPage(), game = await GameTest.attach(page); 17 page.on('websocket', socket => { if (socket.url().endsWith('/browser-world')) sockets[index] = socket; }); 18 games.push(game); 19 await page.goto(url); 20 await game.ready(); assert.equal((await game.page.request.post(url + '/test-defer-recovery')).status(), 204); 21 await page.waitForFunction(() => touchRegion(500,400)?.world === true); 22 await game.snapshot(); 23 } 24 const [owner, observer] = games; 25 const server = async () => (await owner.page.request.get(url+'/test-state')).json(); 26 const inventoryClick = async () => { 27 await owner.wait('implant actions end', state => !owner.local(state).actions.includes(3) && !owner.local(state).actions.includes(6)); 28 const cell = owner.state.grids.flatMap(grid=>grid.cells).find(cell=>cell.identity[0]===104 && cell.identity[1]===48 && !cell.dummy); 29 assert(cell,'retained implant is visible in ordinary inventory'); 30 await owner.click((cell.bounds[0]+cell.bounds[2])/2,(cell.bounds[1]+cell.bounds[3])/2,'right'); 31 }; 32 const reload = async () => { 33 await owner.page.reload(); await owner.ready(); assert.equal((await owner.page.request.post(url + '/test-defer-recovery')).status(), 204); 34 await owner.page.waitForFunction(() => touchRegion(500,400)?.world === true); 35 await owner.snapshot(); 36 }; 37 const wearPanel = async () => { 38 if (!owner.state.regions.some(([left,top,right,bottom])=>left===832 && top===0 && right===1024 && bottom===360)) 39 await owner.page.keyboard.press('Control+1'); 40 await owner.wait('native Wear panel is open',state=>state.regions.some(([left,top,right,bottom])=> 41 left===832 && top===0 && right===1024 && bottom===360)); 42 await owner.click(993,53); 43 }; 44 evidence.initial = await server(); 45 if (evidence.initial.phase === 'warm') { 46 assert.equal(evidence.initial.treatment,9); 47 assert.equal(owner.local().stats[224]&16,0); 48 await owner.key('KeyI'); 49 await wearPanel(); 50 await inventoryClick(); 51 assert.equal((await server()).inventory.Items[0].Slot,64); 52 await owner.save(output+'/before-access'); 53 await owner.page.keyboard.press('Control+1'); 54 if (!owner.state.camera.firstPerson) await owner.key('F8'); 55 56 // A real Use fails before any native fee or healing acknowledgement. 57 const failed = owner.sequence; 58 const closed = sockets[0].waitForEvent('close', {timeout:15000}); 59 await owner.click(...await owner.pick(51005,3221226655),'right'); 60 await owner.wait('failed clinic request reaches the server', () => owner.events.some(event=>event.sequence>failed && 61 event.direction==='framesent' && event.opcode==='52526858')); 62 await closed; 63 assert((await owner.page.request.post(url+'/test-clear-failure')).ok()); 64 await reload(); 65 evidence.failed = await server(); 66 assert.equal(evidence.failed.inventory.Credits,700); 67 assert.equal(evidence.failed.health,1); assert.equal(evidence.failed.nano,2); 68 assert.deepEqual(evidence.failed.programs,[]); 69 await owner.save(output+'/failed-recovered'); 70 71 const use = owner.sequence; 72 await owner.click(...await owner.pick(51005,3221226655),'right'); 73 await owner.wait('stationary surgery effect arrives', () => owner.events.some(event=>event.sequence>use && 74 event.direction==='framereceived' && event.opcode==='5e477770' && Buffer.from(event.hex,'hex').readUInt32BE(29)===177 && 75 Buffer.from(event.hex,'hex').readUInt32BE(37)===157490)); 76 await Promise.all(games.map(game=>game.wait('native clinic healing is visible', state=>state.actors.some(actor=>actor.id===1 && actor.type===50000 && actor.stats[27]===1001)))); 77 await owner.wait('native clinic cash, nano and permission agree', state=>owner.local(state).stats[61]===400 && 78 owner.local(state).stats[214]===1002 && (owner.local(state).stats[224]&16)!==0); 79 evidence.used = await server(); 80 assert.equal(evidence.used.treatment,109); assert.deepEqual(evidence.used.programs,[157490]); 81 assert.equal(evidence.used.inventory.Credits,400); 82 await owner.save(output+'/used'); 83 await observer.save(output+'/observer-used'); 84 await owner.key('KeyI'); 85 await wearPanel(); 86 await inventoryClick(); 87 await owner.wait('clinic-qualified native implant wear', state=>owner.local(state).inventory.some(item=>item.id===1 && item.slot===37)); 88 await owner.save(output+'/worn'); 89 await reload(); 90 } else { 91 assert.deepEqual(evidence.initial.programs,[157490]); 92 assert.equal(evidence.initial.treatment,109); 93 assert.equal(evidence.initial.inventory.Credits,400); 94 await wearPanel(); 95 await owner.click(927,148,'right'); 96 await owner.wait('cold clinic access permits implant removal', state=>owner.local(state).inventory.some(item=>item.id===1 && item.slot===48)); 97 await owner.key('KeyI'); 98 await inventoryClick(); 99 await owner.wait('cold clinic access permits implant rewear', state=>owner.local(state).inventory.some(item=>item.id===1 && item.slot===37)); 100 await owner.save(output+'/cold-reworn'); 101 102 // A controlled cross-playfield checkpoint isolates effect retirement from travel. 103 assert((await owner.page.request.post(url+'/test-zone')).ok()); 104 await owner.wait('native transition enters the destination', state=>owner.local(state)?.playfield===1180); 105 await owner.ready(); assert.equal((await owner.page.request.post(url + '/test-defer-recovery')).status(), 204); 106 await owner.page.waitForFunction(() => touchRegion(500,400)?.world === true); 107 await owner.snapshot(); 108 evidence.zoned = await server(); 109 assert.deepEqual(evidence.zoned.programs,[]); assert.equal(evidence.zoned.treatment,9); 110 assert.equal(evidence.zoned.permission,false); 111 assert.equal(owner.local().stats[224]&16,0); 112 await wearPanel(); 113 const refused = owner.sequence; 114 await owner.click(927,148,'right'); 115 assert.equal((await server()).inventory.Items[0].Slot,37); 116 assert(!owner.events.some(event=>event.sequence>refused && event.direction==='framesent' && event.opcode==='47537a24')); 117 await owner.save(output+'/zoned-refusal'); 118 await reload(); 119 } 120 evidence.final = await server(); 121 assert.equal(evidence.final.inventory.Credits,400); 122 assert.deepEqual(owner.local().inventory.map(item=>[item.id,item.slot,item.quality]),[[1,37,1]]); 123 assert(games.every(game=>game.errors.length===0)); 124 console.log('PASS: stationary clinic fee, healing, implant access and '+evidence.initial.phase+' recovery agree with native input and server state'); 125 } finally { 126 try { 127 await fs.mkdir(output,{recursive:true}); 128 await fs.writeFile(output+'/verification.json',JSON.stringify(evidence,null,2)+'\n'); 129 await Promise.all(games.map((game,index)=>game.save(output+'/final-'+index))); 130 } finally { await browser.close(); } 131 }