// The updates wire (live.go's updatesGet): each update framed as a // 4-byte big-endian length then the bytes. A body that does not divide // cleanly is an error rather than a short read — a client that guessed // would be a client that silently lost the last update. import test from 'node:test' import assert from 'node:assert/strict' import { parseFrames, frame } from './frames.mjs' test('an empty body is no frames', () => { assert.deepEqual(parseFrames(new Uint8Array(0)), []) }) test('frames come back in order with their exact bytes', () => { const a = new Uint8Array([1, 2, 3]) const b = new Uint8Array([]) const c = new Uint8Array([9]) const body = new Uint8Array([...frame(a), ...frame(b), ...frame(c)]) const got = parseFrames(body) assert.equal(got.length, 3) assert.deepEqual(Array.from(got[0]), [1, 2, 3]) assert.deepEqual(Array.from(got[1]), []) assert.deepEqual(Array.from(got[2]), [9]) }) test('a length prefix is big-endian', () => { const body = new Uint8Array([0, 0, 1, 0, ...new Array(256).fill(7)]) assert.equal(parseFrames(body)[0].length, 256) }) test('a truncated frame throws rather than returning a short update', () => { assert.throws(() => parseFrames(new Uint8Array([0, 0, 0, 5, 1, 2])), /frame/) assert.throws(() => parseFrames(new Uint8Array([0, 0])), /frame/) })