Read an intermediate delivery notification as a report, and keep it out of the merge

This commit is contained in:
2026-09-03 17:30:09 +02:00
parent 94184a9c63
commit 50679ec2fe
8 changed files with 93 additions and 31 deletions
+17 -2
View File
@@ -145,6 +145,7 @@ describe('dlrFromPdu()', () => {
assert.equal(dlr.smsId, undefined);
assert.equal(dlr.statusMsg, 'UNKNOWN');
assert.equal(dlr.statusId, 7);
assert.equal(dlr.intermediate, false);
});
// pduToObj leaves a UDH-carrying short_message a buffer, so the body needs decoding before it
@@ -196,17 +197,31 @@ describe('dlrFromPdu()', () => {
assert.equal(dlr.statusMsg, 'DELIVERED');
});
test('leaves a message the peer marked as another type to arrive as an SMS', () => {
test('leaves a message the far-end SME marked as another type to arrive as an SMS', () => {
for (const esmClass of [
consts.ESM_CLASS.CONVERSATION_ABORT,
consts.ESM_CLASS.DELIVERY_ACKNOWLEDGEMENT,
consts.ESM_CLASS.INTERMEDIATE_DELIVERY,
consts.ESM_CLASS.USER_ACKNOWLEDGEMENT,
]) {
assert.equal(dlrFromPdu(deliverSm(receiptText, undefined, esmClass)), undefined);
}
});
test('reads an intermediate delivery notification as a report, marked as one', () => {
const enroute = 'id:0195f0c7 sub:001 dlvrd:000 submit date:2508251430 done date:2508251431 stat:ENROUTE err:000 text:';
const dlr = dlrFromPdu(deliverSm(enroute, undefined, consts.ESM_CLASS.INTERMEDIATE_DELIVERY));
assert.ok(dlr);
assert.equal(dlr.smsId, '0195f0c7');
assert.equal(dlr.statusMsg, 'ENROUTE');
assert.equal(dlr.intermediate, true);
const unreadable = dlrFromPdu(deliverSm('no fields here', undefined, consts.ESM_CLASS.INTERMEDIATE_DELIVERY));
assert.ok(unreadable, 'the marker makes it a report whatever the body parses to');
assert.equal(unreadable.intermediate, true);
});
test('exposes the raw receipt alongside the resolved fields', () => {
const dlr = dlrFromPdu(deliverSm(receiptText));
+20 -1
View File
@@ -203,10 +203,11 @@ describe('merged delivery reports', () => {
});
describe('merging segment statuses', () => {
function receipt(smsId: string, statusMsg: MessageState): Dlr {
function receipt(smsId: string, statusMsg: MessageState, intermediate = false): Dlr {
return {
doneDate: undefined,
errorCode: undefined,
intermediate,
receipt: undefined,
smsId,
statusId: consts.MESSAGE_STATE[statusMsg],
@@ -214,6 +215,24 @@ describe('merging segment statuses', () => {
};
}
// Filling every slot with a non-final report merges early and spends the base, so the receipts
// that say what actually happened would report nothing.
test('never counts an intermediate report toward a merge', () => {
const merger = new DlrMerger({ log: silentLog, max: 10, now: () => 0, timeout: 60_000 });
merger.expect(['msg-1', 'msg-2']);
assert.equal(merger.collect(receipt('msg-1', 'ENROUTE', true)), undefined);
assert.equal(merger.collect(receipt('msg-2', 'ENROUTE', true)), undefined);
assert.equal(merger.collect(receipt('msg-1', 'DELIVERED')), undefined);
const merged = merger.collect(receipt('msg-2', 'DELIVERED'));
assert.ok(merged);
assert.equal(merged.statusMsg, 'DELIVERED');
assert.equal(merged.segments.length, 2);
});
// MESSAGE_STATE is a flat enum: ACCEPTED is 6 where UNDELIVERABLE is 5, so reducing on the
// wire value called a part-failed message delivered.
test('reports the worse of two states the wire numbers the other way round', () => {
+24 -1
View File
@@ -685,7 +685,7 @@ describe('receiving', () => {
assert.equal(answered.pduObj.params.message_id, 'inbound-id');
});
test('hands a client a receipt it cannot read as a dlr rather than as an sms', async t => {
test('hands a client a report as a dlr rather than as an sms', async t => {
const { peer, session } = await inbound(t);
const reported = once<Dlr>(resolve => { session.on('dlr', resolve); });
let messages = 0;
@@ -711,6 +711,28 @@ describe('receiving', () => {
assert.ok(answered.pduObj);
assert.equal(answered.pduObj.cmdName, 'deliver_sm_resp');
const notified = once<Dlr>(resolve => { session.on('dlr', resolve); });
const notification = peer.send({
cmdName: 'deliver_sm',
params: {
destination_addr: '46709771337',
esm_class: consts.ESM_CLASS.INTERMEDIATE_DELIVERY,
short_message: 'id:0195f0c7 stat:ENROUTE err:000 text:',
source_addr: '46701113311',
},
});
const report = await raceWithin(2000, notified);
assert.ok(report, 'an intermediate notification is the MC reporting on our send, not an inbound SMS');
assert.equal(report.intermediate, true);
assert.equal(report.statusMsg, 'ENROUTE');
assert.equal(messages, 0);
const answeredNotification = await notification;
assert.ok(answeredNotification.pduObj);
assert.equal(answeredNotification.pduObj.cmdName, 'deliver_sm_resp');
});
test('reassembles a multipart inbound SMS before the sms event', async t => {
@@ -1494,6 +1516,7 @@ describe('merged delivery report bounds', () => {
return {
doneDate: undefined,
errorCode: undefined,
intermediate: false,
receipt: undefined,
smsId,
statusId: 2,