tests/e2e/arrival-hall.test.mjs (6568B)
1 import assert from 'node:assert/strict'; 2 import {before, test} from 'node:test'; 3 import {buildServer, withFixture} from './fixture.mjs'; 4 5 before(buildServer); 6 7 async function createHallCharacter(fixture, name) { 8 const context = await fixture.visitor(); 9 const launched = await context.request.post(fixture.url + '/browser-launch?create=1'); 10 assert.equal(launched.status(), 200); 11 const prepared = await context.request.post(fixture.url + '/browser-create', 12 {form: {name, password: 'arrival hall regression password'}}); 13 assert.equal(prepared.status(), 204); 14 // Controlled precondition: the original create packet supplies a Hall player; 15 // creation-screen coverage belongs to the separate complete-flow regression. 16 // Same original Atrox Enforcer packet as server/native_creation_test.go. 17 const setup = await context.newPage(); 18 await setup.goto(fixture.url + '/_test/player'); 19 const body = Buffer.from('000000040000000061' + 20 '0000c79c00000000000000000000000000009c5000000000' + 21 '000000000000000400000000' + name.length.toString(16).padStart(8, '0') + Buffer.from(name).toString('hex') + 22 '000000040000000100000009000000000000000000000000000000000000001d0000006e00000002', 'hex'); 23 const packet = Buffer.alloc((20 + body.length + 3) & ~3); 24 for (const offset of [0, 2, 4]) packet.writeUInt16BE(1, offset); 25 packet.writeUInt16BE(20 + body.length, 6); 26 packet.writeUInt32BE(1, 8); 27 packet.writeUInt32BE(0x0f, 16); 28 body.copy(packet, 20); 29 const result = await setup.evaluate(bytes => new Promise((resolve, reject) => { 30 const socket = new WebSocket(location.origin.replace('http', 'ws') + '/browser-create'); 31 socket.binaryType = 'arraybuffer'; 32 socket.onopen = () => socket.send(new Uint8Array(bytes)); 33 socket.onerror = () => reject(new Error('Native creation fixture connection failed')); 34 socket.onmessage = event => { resolve(Array.from(new Uint8Array(event.data))); socket.close(); }; 35 }), Array.from(packet)); 36 assert.equal(Buffer.from(result).readUInt32BE(16), 0x11); 37 await setup.close(); 38 return context; 39 } 40 41 test('Arrival Hall native choice can be cancelled and commits departure once', {timeout: 360_000}, async () => 42 withFixture('arrival-hall', async fixture => { 43 const context = await createHallCharacter(fixture, 'Observer'); 44 const before = await fixture.setup(context, 'position', {playfield: 4604, 45 position: [186.17244, 1.8, 168], rotation: [0, 1, 0, 0]}); 46 assert.equal(before.items.length, 4); 47 const game = await fixture.game(context); 48 if (!game.state.camera.firstPerson) await game.key('F8'); 49 const representative = game.state.actors.find(actor => actor.type === 50000 && 50 Math.abs(actor.position[0] - 186.17244) < 0.1 && Math.abs(actor.position[2] - 163.2037) < 0.1); 51 assert(representative); 52 await game.save(fixture.output + '/before-conversation'); 53 54 await game.click(...await game.pick(50000, representative.id), 'right'); 55 await game.wait('representative menu', () => game.events.some(event => 56 event.direction === 'framereceived' && event.opcode === '55704d31')); 57 await game.save(fixture.output + '/conversation'); 58 let sequence = game.sequence; 59 // Original native choice rows in the reset 1024x768 client layout. 60 await game.click(170, 390); 61 await game.wait('conversation cancelled', () => game.events.some(event => event.sequence > sequence && 62 event.direction === 'framereceived' && event.opcode === '270a4c62')); 63 assert.equal((await fixture.state(context)).playfield, 4604); 64 assert.deepEqual((await fixture.state(context)).items, before.items); 65 sequence = game.sequence; 66 await game.click(...await game.pick(50000, representative.id), 'right'); 67 await game.wait('representative reopened', () => game.events.some(event => event.sequence > sequence && 68 event.direction === 'framereceived' && event.opcode === '55704d31')); 69 await game.click(170, 373); 70 await game.wait('training destination', state => game.local(state)?.playfield === 954, 60000); 71 await game.ready(); 72 await game.save(fixture.output + '/training'); 73 74 const departed = await fixture.state(context); 75 assert.equal(departed.playfield, 954); 76 assert.equal(departed.items.length, 5); 77 assert.equal(departed.items.filter(item => item.templates.includes(116697)).length, 1); 78 assert(game.events.some(event => event.sequence > sequence && event.direction === 'framereceived' && 79 event.opcode === '270a4c62'), 'Departure ends the native conversation before zoning'); 80 const cookies = await context.cookies(); 81 await fixture.restart(); 82 const restored = await fixture.context(); 83 await restored.addCookies(cookies); 84 const resumed = await fixture.game(restored); 85 assert.equal(resumed.local().playfield, 954); 86 assert.deepEqual((await fixture.state(restored)).items, departed.items); 87 for (const client of [game, resumed]) assert.deepEqual(client.errors, []); 88 })); 89 90 test('All Arrival Hall corridors choose a faction without talking to an NPC', {timeout: 360_000}, async () => 91 withFixture('arrival-hall-corridors', async fixture => { 92 for (const scenario of [ 93 {name: 'neutral', x: 183, side: 0, playfield: 954, templates: [116697]}, 94 {name: 'clan', x: 192, side: 1, playfield: 952, templates: [116696, 96358]}, 95 {name: 'omni', x: 173, side: 2, playfield: 950, templates: [116693, 99719, 29426]}, 96 ]) { 97 const context = await createHallCharacter(fixture, scenario.name); 98 // Isolate each authored corridor from the independently verified lobby route. 99 const before = await fixture.setup(context, 'position', {playfield: 4604, 100 position: [scenario.x, 1.52, 164], rotation: [0, 1, 0, 0]}); 101 assert.equal(before.items.length, 4); 102 const game = await fixture.game(context); 103 if (!game.state.camera.firstPerson) await game.key('F8'); 104 await game.save(fixture.output + '/' + scenario.name + '-before'); 105 106 await game.walk(scenario.x, 154); 107 await game.wait('corridor training destination', state => game.local(state)?.playfield === scenario.playfield, 60000); 108 await game.ready(); 109 await game.save(fixture.output + '/' + scenario.name + '-training'); 110 111 const departed = await fixture.state(context); 112 assert.equal(departed.playfield, scenario.playfield); 113 assert.equal(game.local().stats[33], scenario.side); 114 assert.equal(departed.items.length, 4 + scenario.templates.length); 115 for (const template of scenario.templates) { 116 assert.equal(departed.items.filter(item => item.templates.includes(template)).length, 1); 117 } 118 assert.deepEqual(game.errors, []); 119 await context.close(); 120 } 121 }));