Files
corescope-rx/test/msgwait.test.mjs
efitenandClaude Opus 5.5 f5c231f58e feat(msgwait): count direct messages only, filter every companion channel
The first version filtered only #coredrive. Reading every channel slot of
the companion (CMD_GET_CHANNEL, once per connection, only with the notice
on) lets the app recognise any channel message the way the firmware does:
channel hash, then MAC (Mesh.cpp:225-236), for GRP_TXT and GRP_DATA. What
still triggers a count is a direct message or a room-server post.

The slots cannot change during the connection: the MeshCore app cannot
reach the companion while CoreDrive RX holds the BLE link. A slot the
uplink ping writes is added to the list as well.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 22:13:43 +01:00

67 lines
2.6 KiB
JavaScript

import { test } from 'node:test';
import assert from 'node:assert/strict';
import {
createMsgWait, noteChannelPacket, onMessageWaiting, clearCount, MATCH_WINDOW_MS, SEEN_TTL_MS,
} from '../src/msgwait.js';
test('a message-waiting push with no channel packet before it is a direct message', () => {
const s = createMsgWait();
assert.equal(onMessageWaiting(s, 1000), 'message');
assert.equal(s.count, 1);
});
test('another client\'s channel message swallows the push that follows it', () => {
const s = createMsgWait();
noteChannelPacket(s, { hash: 'aa', own: false, now: 1000 });
assert.equal(onMessageWaiting(s, 1010), 'channel');
assert.equal(s.count, 0);
});
test('only the first copy of a channel message expects a push (firmware wasSeen dedup)', () => {
const s = createMsgWait();
noteChannelPacket(s, { hash: 'aa', own: false, now: 1000 });
noteChannelPacket(s, { hash: 'aa', own: false, now: 1200 }); // re-broadcast by a second repeater
assert.equal(onMessageWaiting(s, 1210), 'channel');
assert.equal(onMessageWaiting(s, 1300), 'message');
assert.equal(s.count, 1);
});
test('echoes of our own ping expect no push (sendFlood marks it seen)', () => {
const s = createMsgWait();
noteChannelPacket(s, { hash: 'bb', own: true, now: 1000 });
assert.equal(onMessageWaiting(s, 1010), 'message');
});
test('an expectation older than the match window no longer swallows a push', () => {
const s = createMsgWait();
noteChannelPacket(s, { hash: 'aa', own: false, now: 1000 });
assert.equal(onMessageWaiting(s, 1000 + MATCH_WINDOW_MS + 1), 'message');
});
test('two different pings swallow two pushes', () => {
const s = createMsgWait();
noteChannelPacket(s, { hash: 'aa', own: false, now: 1000 });
noteChannelPacket(s, { hash: 'cc', own: false, now: 1005 });
assert.equal(onMessageWaiting(s, 1010), 'channel');
assert.equal(onMessageWaiting(s, 1011), 'channel');
assert.equal(onMessageWaiting(s, 1012), 'message');
});
test('a hash is forgotten after the seen TTL and counts as new again', () => {
const s = createMsgWait();
noteChannelPacket(s, { hash: 'aa', own: false, now: 1000 });
onMessageWaiting(s, 1010);
noteChannelPacket(s, { hash: 'aa', own: false, now: 1000 + SEEN_TTL_MS + 1 });
assert.equal(onMessageWaiting(s, 1000 + SEEN_TTL_MS + 5), 'channel');
});
test('clearCount resets the visible count only', () => {
const s = createMsgWait();
onMessageWaiting(s, 1000);
onMessageWaiting(s, 1001);
noteChannelPacket(s, { hash: 'aa', own: false, now: 1002 });
clearCount(s);
assert.equal(s.count, 0);
assert.equal(onMessageWaiting(s, 1003), 'channel');
});