summaryrefslogtreecommitdiffstats
path: root/packages/meshbay-hub/tests/harness
diff options
context:
space:
mode:
authorChristophe Besson <cbesson@gmail.com>2026-10-17 19:08:52 +0200
committerChristophe Besson <cbesson@gmail.com>2026-10-17 19:08:52 +0200
commit84946b1fef64ee619f1c161d57ef4afdc533eae2 (patch)
tree55d13c6536b5cc2bdb8754eb0d82b6339f01072b /packages/meshbay-hub/tests/harness
parent7e01b7e8c2ce2ef9fce8b6c053c3b7210b64f9bf (diff)
downloadmeshbay-84946b1fef64ee619f1c161d57ef4afdc533eae2.tar.gz
fix(spa): search hears a refused local network from the connection
On a Pixel, Chrome still lists the refused address when search gives up, so nothing tells it from a silent node. The connection given up on now runs to its own verdict and the refusal is reported then. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'packages/meshbay-hub/tests/harness')
-rw-r--r--packages/meshbay-hub/tests/harness/local_network_harness.mjs9
-rw-r--r--packages/meshbay-hub/tests/harness/search_connect_harness.mjs30
2 files changed, 24 insertions, 15 deletions
diff --git a/packages/meshbay-hub/tests/harness/local_network_harness.mjs b/packages/meshbay-hub/tests/harness/local_network_harness.mjs
index 3c86cf77..9afdf59e 100644
--- a/packages/meshbay-hub/tests/harness/local_network_harness.mjs
+++ b/packages/meshbay-hub/tests/harness/local_network_harness.mjs
@@ -151,13 +151,6 @@ if (cfg.classify) {
undefined, undefined, '', 'pk')
.then(() => { outcome = 'connected'; },
(err) => { outcome = err.message; reason = err.reason || null; main.close(); });
- // What a caller that stops waiting early reads (connection-pool.js): at
- // `probeAt` ms, while ICE is still checking, or after it connected.
- let early = null;
- if (cfg.probeAt) {
- await run(cfg.probeAt);
- early = await main.localNetworkRefused();
- }
await run(60000);
- process.stdout.write(JSON.stringify({ outcome, reason, statsCalls, early }));
+ process.stdout.write(JSON.stringify({ outcome, reason, statsCalls }));
}
diff --git a/packages/meshbay-hub/tests/harness/search_connect_harness.mjs b/packages/meshbay-hub/tests/harness/search_connect_harness.mjs
index 71c7e8c4..0c10a39d 100644
--- a/packages/meshbay-hub/tests/harness/search_connect_harness.mjs
+++ b/packages/meshbay-hub/tests/harness/search_connect_harness.mjs
@@ -28,9 +28,11 @@ const {
nodes = 1,
// Which of them answer (resolveAt applies to these). null: all.
answering = null,
- // Which of them this device refuses to reach on the local network: what the
- // transport reads from its connection when search gives up on it.
+ // Which of them this device refuses to reach on the local network. As
+ // measured on a Pixel: no progress, and connect() names the refusal only
+ // when ICE gives up, `refusedAt` ms in.
lanRefused = [],
+ refusedAt = 30000,
// How far to run the clock before giving up on the harness itself.
runUntil = 300000,
} = cfg;
@@ -70,6 +72,8 @@ async function run(until) {
// ── The environment ──────────────────────────────────────────────────────────
let closed = 0;
+const closedAt = [];
+const lateRefusals = [];
let made = 0;
class FakeTransport {
@@ -79,8 +83,6 @@ class FakeTransport {
this.index = made++;
}
- async localNetworkRefused() { return lanRefused.includes(this.index); }
-
connect() {
const started = now;
for (const at of progressAt) {
@@ -92,14 +94,25 @@ class FakeTransport {
}
}, at);
}
- return new Promise((resolve) => {
+ return new Promise((resolve, reject) => {
+ if (lanRefused.includes(this.index)) {
+ setTimeout(() => {
+ const err = new Error('This device refused to reach the local network');
+ err.reason = 'local_network_blocked';
+ reject(err);
+ }, refusedAt);
+ return;
+ }
if (resolveAt !== null && (answering === null || answering.includes(this.index))) {
setTimeout(() => resolve({ ok: true, at: now - started }), resolveAt);
+ } else {
+ // The transport's own deadline for the channel: every connect() ends.
+ setTimeout(() => reject(new Error('DataChannel open timeout')), 30000);
}
});
}
- close() { closed += 1; }
+ close() { closed += 1; closedAt.push(now); }
}
globalThis.window = { MeshBayTransport: FakeTransport };
@@ -134,7 +147,8 @@ const connectToGroup = make(hubFetch, ensureFreshToken, globalThis.window);
// ── The scenario ─────────────────────────────────────────────────────────────
let outcome = null;
-connectToGroup('https://hub.example', 'g1', 'tok', null, 'alice', 'u1')
+connectToGroup('https://hub.example', 'g1', 'tok', null, 'alice', 'u1',
+ (groupId) => { lateRefusals.push({ groupId, at: now }); })
.then(() => { outcome = { result: 'connected', at: now }; })
.catch((e) => {
outcome = { result: 'failed', at: now, error: String(e.message), reason: e.reason || null };
@@ -145,4 +159,6 @@ await run(runUntil);
console.log(JSON.stringify({
...(outcome || { result: 'still-waiting', at: now }),
closed,
+ closedAt,
+ lateRefusals,
}));