import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { MessageBuffer } from './message-buffer.js';
describe('MessageBuffer poll', () => {
    it('keeps waiting until a new direct message arrives', async () => {
        const buffer = new MessageBuffer();
        let settled = false;
        const pendingPoll = buffer.poll().then((messages) => {
            settled = true;
            return messages;
        });
        await new Promise((resolve) => setTimeout(resolve, 30));
        assert.equal(settled, false, 'poll should remain pending when no message arrives');
        const directMessage = {
            msgId: 'dm-1',
            senderId: 'agent-1',
            senderName: 'Agent One',
            content: 'hello',
            requireReply: false,
            timestamp: new Date().toISOString()
        };
        buffer.push(directMessage);
        const messages = await pendingPoll;
        assert.equal(messages.directMessages.length, 1);
        assert.deepEqual(messages.directMessages[0], directMessage);
        assert.deepEqual(messages.groupMessages, []);
    });
    it('returns buffered group messages immediately without blocking', async () => {
        const buffer = new MessageBuffer();
        const groupMessage = {
            msgId: 1,
            senderId: 'human-1',
            senderName: 'Human One',
            content: 'announcement',
            timestamp: new Date().toISOString()
        };
        buffer.push(groupMessage);
        const messages = await buffer.poll();
        assert.deepEqual(messages.directMessages, []);
        assert.equal(messages.groupMessages.length, 1);
        assert.deepEqual(messages.groupMessages[0], groupMessage);
    });
});
//# sourceMappingURL=message-buffer.test.js.map