'use strict'; const test = require('node:test'); const assert = require('node:assert'); const { MCStream } = require('../src/bot/compression'); test('MCStream: deflate below threshold is passthrough', () => { const s = new MCStream(); s.setThreshold(256); const data = Buffer.from('hello'); assert.strictEqual(s.deflate(data), data); }); test('MCStream: inflate of uncompressed data is passthrough', () => { const s = new MCStream(); s.setThreshold(256); const data = Buffer.from('hello'); assert.strictEqual(s.inflate(data), data); }); test('MCStream: deflate then inflate round-trip', () => { const s = new MCStream(); s.setThreshold(8); const data = Buffer.from('a'.repeat(64)); const compressed = s.deflate(data); assert.ok(compressed.length < data.length, 'compressed should be smaller'); const back = s.inflate(compressed); assert.deepStrictEqual([...back], [...data]); }); test('MCStream: corrupt zlib stream returns original', () => { const s = new MCStream(); s.setThreshold(8); const bad = Buffer.from('not a zlib stream at all - just bytes'); const result = s.inflate(bad); assert.strictEqual(result, bad); }); test('MCStream: disabled returns input as-is', () => { const s = new MCStream(); assert.strictEqual(s.isEnabled(), false); const data = Buffer.from('x'.repeat(1024)); assert.strictEqual(s.deflate(data), data); assert.strictEqual(s.inflate(data), data); });