Files
corescope-rx/test/asknext.test.mjs
efitenandClaude Opus 5.5 5da69305b8 feat: ask a repeater without a CoreScope name for its own name
Field case 2026-10-16: c0cdee59e0db981b answered every discover sweep,
but CoreScope has never seen its advert, so it stayed a bare prefix and
got no regions ask either.

- nodeNames flag (on when config.json exists and omits it, off without
  a config, like regionDiscovery). With it on, discover requests drop
  DISCOVER_PREFIX_ONLY, so replies carry the full 32-byte pubkey
  (+24 bytes each, simple_repeater/MyMesh.cpp:824).
- A repeater heard in range is looked up once per session. Only when
  CoreScope answers without a name is it asked ANON_REQ_TYPE_OWNER
  (MyMesh.cpp:165). The reply is "name\nowner_info"; owner_info is
  dropped.
- Name and regions asks share one queue and one per-encounter budget
  (src/asknext.js): the companion keeps one pending anon request
  (companion_radio/MyMesh.cpp:1570) and the repeater limiter is shared
  across request types. The name is asked first.
- The name replaces the prefix in the recent list and regions card, and
  is published on meshcore/client/{pk}/names as NODE_NAME with the
  companion's fix. New topic; /packets is unchanged.
- Debug header: a names row and nodeNames in the config row.

Not done: CoreScope does not ingest /names yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-16 09:25:48 +02:00

49 lines
2.0 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { nextAskKind, settledSet, settle } from '../src/asknext.js';
import { enqueue, takeNext } from '../src/regionsched.js';
const A = 'aa'.repeat(32);
const B = 'bb'.repeat(32);
const ctx = (over = {}) => ({
regionsOn: true, namesOn: true, regionsAnswered: new Set(), nameWanted: new Set(), named: new Map(), ...over,
});
test('nextAskKind: name first when CoreScope lacks it, then regions, then nothing', () => {
const c = ctx({ nameWanted: new Set([A]) });
assert.equal(nextAskKind(c, A), 'owner');
assert.equal(nextAskKind(c, B), 'regions');
c.named.set(A, 'BE-NEW-RPT');
assert.equal(nextAskKind(c, A), 'regions');
c.regionsAnswered.add(A);
assert.equal(nextAskKind(c, A), null);
});
test('nextAskKind honours each flag on its own', () => {
assert.equal(nextAskKind(ctx({ namesOn: false, nameWanted: new Set([A]) }), A), 'regions');
assert.equal(nextAskKind(ctx({ regionsOn: false }), A), null);
assert.equal(nextAskKind(ctx({ regionsOn: false, nameWanted: new Set([A]) }), A), 'owner');
});
test('settle keeps a target queued while it still owes the other answer', () => {
const c = ctx({ nameWanted: new Set([A]) });
const q = [A, B];
c.named.set(A, 'X');
settle(q, c, A);
assert.deepEqual(q, [A, B]);
c.regionsAnswered.add(A);
settle(q, c, A);
assert.deepEqual(q, [B]);
});
test('settledSet plugs into regionsched: a fully answered repeater is not queued again', () => {
const c = ctx({ regionsOn: false, nameWanted: new Set([A]) });
const q = [];
const opts = { targetGapMs: 30000, maxAsks: 3, forgetMs: 300000 };
assert.equal(enqueue(q, A, settledSet(c), new Map(), 0, opts), 'queued-now');
assert.equal(takeNext(q, settledSet(c)), A);
c.named.set(A, 'X');
assert.equal(enqueue(q, A, settledSet(c), new Map(), 60000, opts), 'answered');
assert.equal(enqueue(q, B, settledSet(c), new Map(), 60000, opts), 'answered', 'names only, and B has its name');
});