import { describe, expect, it } from 'vitest'; import { Buffer } from 'node:buffer'; import { CHAT_CIPHERTEXT_MAX_BYTES, createChatEnvelope, normalizeChatCiphertext } from './chat.js'; const encoded = (length) => Buffer.alloc(length, 7).toString('base64url'); describe('encrypted chat relay envelopes', () => { it('accepts canonical base64url within the encrypted message bounds', () => { expect(normalizeChatCiphertext(encoded(29))).toBe(encoded(29)); expect(normalizeChatCiphertext(encoded(CHAT_CIPHERTEXT_MAX_BYTES))).toBe(encoded(CHAT_CIPHERTEXT_MAX_BYTES)); }); it('rejects malformed, padded, too-small, and oversized payloads', () => { expect(normalizeChatCiphertext('