diff --git a/src/proxy/mailbox/store.js b/src/proxy/mailbox/store.js index c0142cb..4c4f938 100644 --- a/src/proxy/mailbox/store.js +++ b/src/proxy/mailbox/store.js @@ -210,6 +210,8 @@ class MailboxStore { writeInbound({ id, type, payload, channel, priority, refId, expiresAt }) { const msgId = id || generateUUIDv7(); + if (this._messages.has(msgId)) return msgId; + const now = Date.now(); const msg = { id: msgId, diff --git a/test/mailboxStore.test.js b/test/mailboxStore.test.js index 9078613..0745cae 100644 --- a/test/mailboxStore.test.js +++ b/test/mailboxStore.test.js @@ -99,6 +99,19 @@ describe('MailboxStore', () => { const id = store.writeInbound({ id: customId, type: 'hub_event', payload: {} }); assert.equal(id, customId); }); + + it('ignores duplicate inbound ids', () => { + const store2 = new MailboxStore(tmpDataDir()); + const customId = generateUUIDv7(); + + store2.writeInbound({ id: customId, type: 'hub_event', payload: { n: 1 } }); + const duplicateId = store2.writeInbound({ id: customId, type: 'hub_event', payload: { n: 2 } }); + + assert.equal(duplicateId, customId); + assert.equal(store2.countPending({ direction: 'inbound' }), 1); + assert.deepEqual(store2.poll({ type: 'hub_event' }).map(m => m.payload), [{ n: 1 }]); + store2.close(); + }); }); describe('writeInboundBatch()', () => {