// Bounded diagnostic of the stock parser; passing means the defect reproduced. // No network, credentials, vendor patch, or production implementation. import assert from 'node:assert/strict'; import {createRequire} from 'node:module'; const require = createRequire(import.meta.url); const Client = require('stanza/Client').default; const {StreamParser} = require('stanza/jxt'); assert.equal(require('stanza/package.json').version, '12.22.1'); const tick = () => new Promise(resolve => setImmediate(resolve)); function harness() { const client = new Client({autoReconnect: false}); // Same parser options as shipped transports/websocket.js. const parser = new StreamParser({registry: client.stanzas, wrappedStream: false, allowComments: false}); const received = [], errors = []; parser.on('data', value => received.push(value)); parser.on('error', error => errors.push(error)); return {parser, received, errors}; } const opening = ''; const closing = ''; const split = harness(); split.parser.write(opening); for (let i = 0; i < 16; i++) split.parser.write('a'.repeat(4096)); await tick(); assert.equal(split.errors.length, 0); assert.equal(split.received.length, 0); assert.equal(split.parser.destroyed, false); split.parser.write(closing); await tick(); assert.equal(split.errors.length, 0); assert.equal(split.received.length, 1); assert.equal(split.received[0].stanza.body.length, 65536); split.parser.destroy(); console.log('stock: 18 separate writes reassembled into one 65536-byte body; no error'); const large = harness(); large.parser.write(opening + 'b'.repeat(1048576) + closing); await tick(); assert.equal(large.errors.length, 0); assert.equal(large.received.length, 1); assert.equal(large.received[0].stanza.body.length, 1048576); large.parser.destroy(); console.log('stock: 1048576-byte body accepted; no error'); const deep = harness(); deep.parser.write('' + ''.repeat(256) + ''.repeat(256) + ''); await tick(); assert.equal(deep.errors.length, 0); assert.equal(deep.received.length, 1); let element = deep.received[0].xml, depth = 0; while (element.children[0]) {element = element.children[0]; depth++;} assert.equal(depth, 256); deep.parser.destroy(); console.log('stock: 256 nested child elements accepted; no error');