1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602 | /**
* The social layer, black-box against dist/ over a fake pubsub, two real
* identities and the headless browser-global shims.
*
* This suite USED to import ../dist/vendor/social/* — the hand-maintained
* TypeScript translation peer-kit carried. src/vendor/ is gone: everything
* below now comes from the real ardegazu-social-kit / ardegazu-id-kit at their
* pinned shas, which is exactly what makes it a regression test for the
* switch. The `brains` contract (social-kit 2.1.0) is unchanged, and the three
* things the vendored copy had DRIFTED away from are pinned at the bottom:
* - the fsync self-origin guard (a stranger could rewrite a vendored peer's
* friend list, because inbox room ids are publicly derivable);
* - the self-sync change gate (the copy deposited on every call);
* - the profileSync / appState hooks and syncNow(), absent from the copy.
*
* Wire contract under test:
* - the beacon payload gains ONE additive key, `br` (game id -> version
* string), only when the agent's optional `brains` thunk yields a non-empty
* map; every existing caller's payload bytes are unchanged (pinned exactly);
* - the SAME clamp runs on send and on receive (untrusted network input);
* - a received value surfaces as `brains` on the presence entry, and a legacy
* beacon (no `br`) leaves the key absent entirely;
* - Social.start forwards `brains`, `profileSync` and `appState` through.
*/
import test from "node:test";
import assert from "node:assert/strict";
// ---- headless browser globals (before importing the social layer) -----------
// installBrowserGlobals() would do, but the agent's visibilitychange handler is
// how a test fires an extra beacon on demand — so document must really record
// listeners, and the timers must be unref'd or node --test never exits.
const docListeners = new Map();
const timers = [];
const document = {
visibilityState: "visible",
addEventListener(type, cb) {
if (!docListeners.has(type)) docListeners.set(type, []);
docListeners.get(type).push(cb);
},
removeEventListener(type, cb) {
const l = docListeners.get(type);
if (l) docListeners.set(type, l.filter((x) => x !== cb));
},
};
const track = (t) => {
t.unref?.();
timers.push(t);
return t;
};
const window = {
setTimeout: (fn, ms) => track(setTimeout(fn, ms)),
setInterval: (fn, ms) => track(setInterval(fn, ms)),
clearTimeout,
clearInterval,
addEventListener() {},
removeEventListener() {},
};
const store = new Map();
const localStorage = {
getItem: (k) => (store.has(k) ? store.get(k) : null),
setItem: (k, v) => void store.set(k, String(v)),
removeItem: (k) => void store.delete(k),
};
// no mailbox in a unit test: every mailboxFor() resolves to null
const fetch = () => Promise.reject(new Error("offline test env"));
for (const [name, value] of Object.entries({ document, window, localStorage, fetch })) {
Object.defineProperty(globalThis, name, { value, configurable: true, writable: true });
}
// the REAL kits, at the shas package.json pins — no vendored copy any more
const { SocialAgent, FriendStore, pairChannel, inboxRoomId, applyFriendEnvelope, buildEnvelope, envCtx } =
await import("ardegazu-social-kit");
const { Identity } = await import("ardegazu-id-kit");
const { deriveSuiteXKeyPair, signXCert, SUITE_SALT } = await import("ardegazu-id-kit/xkey");
const { Social } = await import("../dist/index.js");
const dec = new TextDecoder();
const enc = new TextEncoder();
const tick = (ms = 60) => new Promise((r) => setTimeout(r, ms));
/**
* Wait until `read()` returns a non-empty array, or give up.
*
* The agent beacons on real timers, so a fixed `await tick(60)` is a race: with
* nine test files running concurrently the CPU can starve a 60 ms window and
* the assertion then fails on an empty beacon list rather than on behaviour.
* (Observed once in a full-suite run; four consecutive runs after this change
* are clean.) Polling keeps the test about the wire contract, not the machine.
*/
const settle = async (read, { tries = 40, every = 25 } = {}) => {
for (let i = 0; i < tries; i++) {
const got = await read();
if (got.length) return got;
await tick(every);
}
return read();
};
const seedA = Identity.newSeed();
const seedB = Identity.newSeed();
const idA = await Identity.fromSeed(seedA);
const idB = await Identity.fromSeed(seedB);
const xA = await deriveSuiteXKeyPair(seedA);
const xB = await deriveSuiteXKeyPair(seedB);
const certB = await signXCert(idB, SUITE_SALT, xB.pubB64);
// B's view of the shared pair channel: seals/opens the same wires A does.
const chB = await pairChannel(xB, idB.publicKeyB64, idA.publicKeyB64, xA.pubB64);
let nsSeq = 0;
function mkFriendStore(ns) {
const s = new FriendStore(ns);
s.upsert({
pub: idB.publicKeyB64,
x: xB.pubB64,
xs: certB,
pet: "",
name: "bot-b",
state: "friend",
addedTs: Date.now(),
petTs: 0,
lastSeenTs: 0,
lastApp: "",
});
return s;
}
function mkPubsub() {
const published = [];
const listeners = [];
return {
published,
listeners,
pubsub: {
subscribe: () => {},
unsubscribe: () => {},
addEventListener: (_ev, fn) => listeners.push(fn),
publish: async (topic, data) => void published.push([topic, dec.decode(data)]),
},
};
}
/** Beacon payloads A published on the PAIR channel, oldest first. */
async function beaconsOf(published) {
const out = [];
for (const [topic, wire] of published) {
if (topic !== chB.topic) continue;
const opened = await chB.open(wire, [idA.publicKeyB64]);
if (opened && opened.payload && opened.payload.k === "b") out.push(opened.payload);
}
return out;
}
/** A started SocialAgent for identity A with B as an accepted friend. */
async function mkAgent(brains, extra = {}) {
const ns = `t-brains-${nsSeq++}`;
const friends = mkFriendStore(ns);
const { published, listeners, pubsub } = mkPubsub();
const presence = [];
const opts = {
ns,
app: "game2.ardegazu.ro",
identity: idA,
seed: seedA,
myName: () => "ana",
store: friends,
pubsub,
events: { presence: (pub, info) => presence.push([pub, info]) },
...extra,
};
if (brains !== undefined) opts.brains = brains;
const agent = new SocialAgent(opts);
await agent.start();
await tick();
return {
agent,
store: friends,
published,
presence,
beacons: () => settle(() => beaconsOf(published)),
/** Fire the visibility handler => one more beacon round. */
refire: async () => {
const before = (await beaconsOf(published)).length;
for (const cb of [...(docListeners.get("visibilitychange") ?? [])]) cb();
await settle(async () => {
const now = await beaconsOf(published);
return now.length > before ? now : [];
});
},
/** Deliver a beacon sealed by B into A's wire handler. */
deliverFromB: async (payload) => {
const wire = await chB.seal(idB.publicKeyB64, payload);
for (const fn of listeners) fn({ detail: { topic: chB.topic, data: enc.encode(wire) } });
await tick();
},
};
}
// ---- send side --------------------------------------------------------------
test("no brains option: the beacon payload is byte-identical to 1.2.0", async () => {
const a = await mkAgent(undefined);
const bs = await a.beacons();
assert.ok(bs.length >= 1, "A beaconed to its friend");
assert.equal("br" in bs[0], false);
// pinned bytes: the exact payload JSON every existing caller still produces
assert.equal(
JSON.stringify(bs[0]),
`{"k":"b","name":"ana","app":"game2.ardegazu.ro","ts":${bs[0].ts}}`,
);
a.agent.stop();
});
test("beacon carries `br` when the thunk yields a non-empty map, and re-reads it every round", async () => {
let version = "v7";
const a = await mkAgent(() => ({ "valley-blocks": version, g2: "a.b-c_d@1" }));
let bs = await a.beacons();
assert.deepEqual(bs[0].br, { "valley-blocks": "v7", g2: "a.b-c_d@1" });
assert.equal(
JSON.stringify(bs[0]),
`{"k":"b","name":"ana","app":"game2.ardegazu.ro","br":{"valley-blocks":"v7","g2":"a.b-c_d@1"},"ts":${bs[0].ts}}`,
);
// the beacon is the whole update mechanism: change the value, next round carries it
version = "v8";
await a.refire();
bs = await a.beacons();
assert.ok(bs.length >= 2, "a second beacon went out");
assert.equal(bs[bs.length - 1].br["valley-blocks"], "v8", "fresh read at beacon time");
a.agent.stop();
});
test("payload key order stays {k, name, app, join, br, ts}", async () => {
const a = await mkAgent(() => ({ g1: "v1" }), { joinLink: () => "https://game2.ardegazu.ro/#r" });
const bs = await a.beacons();
assert.deepEqual(Object.keys(bs[0]), ["k", "name", "app", "join", "br", "ts"]);
assert.equal(
JSON.stringify(bs[0]),
`{"k":"b","name":"ana","app":"game2.ardegazu.ro","join":"https://game2.ardegazu.ro/#r","br":{"g1":"v1"},"ts":${bs[0].ts}}`,
);
a.agent.stop();
});
test("send-side clamp: 8-entry cap in key order", async () => {
const a = await mkAgent(() => ({
// 10 valid entries — only the first 8 survive
g1: "1", g2: "2", g3: "3", g4: "4", g5: "5", g6: "6", g7: "7", g8: "8", g9: "9", g10: "10",
}));
const bs = await a.beacons();
assert.equal(Object.keys(bs[0].br).length, 8, "capped at 8 entries");
assert.deepEqual(Object.keys(bs[0].br), ["g1", "g2", "g3", "g4", "g5", "g6", "g7", "g8"]);
a.agent.stop();
});
test("send-side clamp: the 8 kept entries are the first 8 VALID ones, not the first 8 keys", async () => {
const a = await mkAgent(() => ({
BAD1: "x", g1: "1", BAD2: "x", g2: "2", g3: "3", g4: "4", g5: "5",
g6: "6", g7: "7", g8: "8", g9: "9",
}));
const bs = await a.beacons();
assert.deepEqual(Object.keys(bs[0].br), ["g1", "g2", "g3", "g4", "g5", "g6", "g7", "g8"]);
a.agent.stop();
});
test("send-side clamp: key charset, non-string values, oversize/bad-charset values", async () => {
const a = await mkAgent(() => ({
ok: "fine",
Bad: "uppercase key", // key charset
"-lead": "leading dash", // key charset (first char)
a_b: "underscore key", // key charset
"": "empty key", // key charset
"way-too-long-game-id-abcdef": "25+ chars", // key length (>24)
n: 42, // non-string value
z: null,
t: true,
o: { v: 1 },
arr: ["v1"],
big: "x".repeat(33), // oversize value (>32)
empty: "", // empty value
spacey: "v 1", // value charset
slashy: "a/b", // value charset
}));
const bs = await a.beacons();
assert.deepEqual(bs[0].br, { ok: "fine" }, "only the clean entry survives");
a.agent.stop();
});
test("send-side clamp: a 24-char key is kept, a 25-char key is dropped", async () => {
const a = await mkAgent(() => ({ ["a".repeat(24)]: "v", ["b".repeat(25)]: "v" }));
const bs = await a.beacons();
assert.deepEqual(Object.keys(bs[0].br), ["a".repeat(24)]);
a.agent.stop();
});
test("send-side clamp: a 32-char value is kept, a 33-char value is dropped", async () => {
const a = await mkAgent(() => ({ g1: "v".repeat(32), g2: "v".repeat(33) }));
const bs = await a.beacons();
assert.deepEqual(Object.keys(bs[0].br), ["g1"]);
a.agent.stop();
});
test("send-side clamp: non-object input, empty result and a throwing thunk all omit `br`", async () => {
const bads = [
() => null,
() => undefined,
() => 42,
() => "v1",
() => true,
() => ["v1"], // array rejected outright
() => ({}),
() => ({ BAD: "x" }),
() => { throw new Error("bot bug"); },
null, // a falsy option is simply absent
];
for (const bad of bads) {
const a = await mkAgent(bad);
const bs = await a.beacons();
assert.ok(bs.length >= 1, "the beacon still went out");
assert.equal("br" in bs[0], false, `omitted for ${bad}`);
assert.equal(
JSON.stringify(bs[0]),
`{"k":"b","name":"ana","app":"game2.ardegazu.ro","ts":${bs[0].ts}}`,
"and the bytes are the no-option bytes",
);
a.agent.stop();
}
});
test("array rejection is load-bearing: an array's indices would pass the key charset", async () => {
// the type check is what stops an array — its "0"/"1" keys and string
// members would otherwise sail through the key AND value charsets, as the
// equivalent plain object (rightly) does
const a = await mkAgent(() => ["v1", "v2"]);
assert.equal("br" in (await a.beacons())[0], false, "an array is not a brains map");
a.agent.stop();
const b = await mkAgent(() => ({ 0: "v1", 1: "v2" }));
assert.deepEqual((await b.beacons())[0].br, { 0: "v1", 1: "v2" }, "a plain object is kept");
b.agent.stop();
});
test("send-side clamp: inherited properties are not advertised", async () => {
const proto = { inherited: "v1" };
const a = await mkAgent(() => Object.assign(Object.create(proto), { own: "v2" }));
const bs = await a.beacons();
assert.deepEqual(bs[0].br, { own: "v2" }, "own enumerable properties only");
a.agent.stop();
});
// ---- receive side -----------------------------------------------------------
test("received `br` surfaces as `brains` on the presence entry", async () => {
const a = await mkAgent(undefined);
await a.deliverFromB({
k: "b", name: "bot-b", app: "game2.ardegazu.ro", br: { "valley-blocks": "v7@3" }, ts: Date.now(),
});
const info = a.agent.presenceOf(idB.publicKeyB64);
assert.ok(info, "presence recorded");
assert.deepEqual(info.brains, { "valley-blocks": "v7@3" });
const [pub, fired] = a.presence[a.presence.length - 1];
assert.equal(pub, idB.publicKeyB64);
assert.equal(fired, info, "the event snapshot is the same entry");
a.agent.stop();
});
test("legacy peer: a beacon without `br` yields NO `brains` key on the entry", async () => {
const a = await mkAgent(undefined);
await a.deliverFromB({ k: "b", name: "bot-b", app: "game2.ardegazu.ro", ts: Date.now() });
const info = a.agent.presenceOf(idB.publicKeyB64);
assert.ok(info, "presence recorded");
assert.equal("brains" in info, false, "no brains key at all");
assert.deepEqual(Object.keys(info), ["name", "app", "join", "ts"], "1.2.0 entry shape");
// and a peer that stops advertising drops the key again on the next beacon
await a.deliverFromB({ k: "b", name: "bot-b", app: "game2.ardegazu.ro", br: { g1: "v1" }, ts: Date.now() });
assert.deepEqual(a.agent.presenceOf(idB.publicKeyB64).brains, { g1: "v1" });
await a.deliverFromB({ k: "b", name: "bot-b", app: "game2.ardegazu.ro", ts: Date.now() });
assert.equal("brains" in a.agent.presenceOf(idB.publicKeyB64), false, "key gone again");
a.agent.stop();
});
test("receive-side clamp is the same clamp: cap, key charset, value rules, junk input", async () => {
const a = await mkAgent(undefined);
const brainsAfter = async (br) => {
await a.deliverFromB({ k: "b", name: "b", app: "game2.ardegazu.ro", br, ts: Date.now() });
return a.agent.presenceOf(idB.publicKeyB64).brains;
};
assert.deepEqual(
Object.keys(await brainsAfter({
g1: "1", g2: "2", g3: "3", g4: "4", g5: "5", g6: "6", g7: "7", g8: "8", g9: "9",
})),
["g1", "g2", "g3", "g4", "g5", "g6", "g7", "g8"],
"8-entry cap on receive too",
);
assert.deepEqual(
await brainsAfter({
ok: "fine", Bad: "x", "-lead": "x", a_b: "x", "": "x",
"way-too-long-game-id-abcdef": "x",
n: 1, z: null, t: false, o: {}, arr: ["x"],
big: "y".repeat(33), empty: "", spacey: "v 1", slashy: "a/b",
}),
{ ok: "fine" },
"same drop rules on receive",
);
// a non-string is DROPPED, never stringified (which is also what bounds it)
assert.deepEqual(await brainsAfter({ g1: "v1", g2: 7 }), { g1: "v1" });
for (const junk of [null, undefined, 42, "v1", true, ["g1"], {}, { BAD: "x" }, { g1: 1 }]) {
await a.deliverFromB({ k: "b", name: "b", app: "game2.ardegazu.ro", br: junk, ts: Date.now() });
const info = a.agent.presenceOf(idB.publicKeyB64);
assert.equal("brains" in info, false, `dropped the whole field for ${JSON.stringify(junk) ?? "undefined"}`);
}
a.agent.stop();
});
// ---- the wrapper (the wiring gap this change closes) ------------------------
test("Social.start forwards `brains` through to the agent's beacons", async () => {
const ns = `t-brains-w-${nsSeq++}`;
const { published, pubsub } = mkPubsub();
const social = await Social.start({
suite: { seed: seedA, identity: idA, profile: { name: "ana" } },
app: "game2.ardegazu.ro",
ns,
pubsub,
brains: () => ({ seance: "59500@a625afba", "valley-blocks": "stock" }),
});
// the wrapper's own friend store is fresh — add B and beacon again
social.store.upsert({
pub: idB.publicKeyB64, x: xB.pubB64, xs: certB, pet: "", name: "bot-b",
state: "friend", addedTs: Date.now(), petTs: 0, lastSeenTs: 0, lastApp: "",
});
await social.agent.joinFriendChannel(social.store.get(idB.publicKeyB64));
for (const cb of [...(docListeners.get("visibilitychange") ?? [])]) cb();
const bs = await settle(() => beaconsOf(published));
assert.ok(bs.length >= 1, "the wrapper's agent beaconed");
assert.deepEqual(bs[bs.length - 1].br, { seance: "59500@a625afba", "valley-blocks": "stock" });
await social.stop();
});
test("Social.start without `brains` sends the unchanged payload", async () => {
const ns = `t-brains-w-${nsSeq++}`;
const { published, pubsub } = mkPubsub();
const social = await Social.start({
suite: { seed: seedA, identity: idA, profile: { name: "ana" } },
app: "game2.ardegazu.ro",
ns,
pubsub,
});
social.store.upsert({
pub: idB.publicKeyB64, x: xB.pubB64, xs: certB, pet: "", name: "bot-b",
state: "friend", addedTs: Date.now(), petTs: 0, lastSeenTs: 0, lastApp: "",
});
await social.agent.joinFriendChannel(social.store.get(idB.publicKeyB64));
for (const cb of [...(docListeners.get("visibilitychange") ?? [])]) cb();
const bs = await settle(() => beaconsOf(published));
assert.ok(bs.length >= 1, "the wrapper's agent beaconed");
const last = bs[bs.length - 1];
assert.equal(
JSON.stringify(last),
`{"k":"b","name":"ana","app":"game2.ardegazu.ro","ts":${last.ts}}`,
);
await social.stop();
});
// ---- what retiring src/vendor/ INHERITS ------------------------------------
/**
* These three were live drift in the vendored TypeScript copy. They are pinned
* here so the switch can never be silently walked back.
*/
test("fsync is held to its sender: a stranger cannot rewrite our friend list", async () => {
// The attack the vendored copy was open to. inboxRoomId() is derivable from a
// public identity pub, so anyone can deposit a VALIDLY SIGNED envelope into
// our inbox — signed with THEIR key. A `fsync` body is a whole friends blob,
// so folding a stranger's would replace our friend list and block
// tombstones wholesale.
const ns = `t-fsync-${nsSeq++}`;
const store = new FriendStore(ns);
store.upsert({
pub: idB.publicKeyB64, x: xB.pubB64, xs: certB, pet: "", name: "bot-b",
state: "friend", addedTs: Date.now(), petTs: 0, lastSeenTs: 0, lastApp: "",
});
assert.equal(store.list().length, 1, "we start with one friend");
// a hostile blob: a different "friend", newer than ours
const hostile = {
v: 1,
friends: [{
pub: "H".repeat(43), x: "h".repeat(43), xs: "s".repeat(86), pet: "",
name: "intruder", state: "friend", addedTs: Date.now(), petTs: 0,
lastSeenTs: 0, lastApp: "",
}],
blocked: [],
ts: Date.now() + 60_000,
};
const envFromStranger = {
t: "fsync",
id: "x".repeat(22),
from: { pub: idB.publicKeyB64, x: xB.pubB64, xs: certB, name: "bot-b" },
ts: Date.now(),
body: { soc: hostile },
};
assert.equal(
applyFriendEnvelope(store, envFromStranger, {}, idA.publicKeyB64),
false,
"refused: from.pub is not our own pub",
);
assert.equal(store.list().length, 1, "friend list untouched");
assert.equal(store.get("H".repeat(43)), null, "the intruder was never folded");
// and the same envelope from OURSELVES is accepted — the guard is an origin
// check, not a blanket refusal
const envFromSelf = { ...envFromStranger, from: { ...envFromStranger.from, pub: idA.publicKeyB64 } };
assert.equal(
applyFriendEnvelope(store, envFromSelf, {}, idA.publicKeyB64),
true,
"our own device's fsync still merges",
);
assert.ok(store.get("H".repeat(43)), "…and that blob did apply, so the refusal above was the guard");
// inbox ids really are derivable from a public key — the premise of the attack
assert.equal(await inboxRoomId(idA.publicKeyB64), await inboxRoomId(idA.publicKeyB64));
assert.notEqual(await inboxRoomId(idA.publicKeyB64), await inboxRoomId(idB.publicKeyB64));
assert.match(envCtx(idA.publicKeyB64), /^to\|v1\|/);
});
test("the agent's envelope router applies the same fsync origin check", async () => {
// Same attack, one layer up: B seals a real, correctly signed `fsync`
// envelope addressed to A and delivers it over the shared pair channel. The
// agent's router must drop it before applyFriendEnvelope ever sees it.
const a = await mkAgent(undefined);
const hostile = {
v: 1,
friends: [{
pub: "Z".repeat(43), x: "z".repeat(43), xs: "s".repeat(86), pet: "",
name: "intruder", state: "friend", addedTs: Date.now(), petTs: 0,
lastSeenTs: 0, lastApp: "",
}],
blocked: [],
ts: Date.now() + 60_000,
};
// buildEnvelope's `self` shape: { identity, x: {priv,pubB64}, xCert, name }
const built = await buildEnvelope(
{ identity: idB, x: xB, xCert: certB, name: "bot-b" },
envCtx(idA.publicKeyB64),
idA.publicKeyB64,
xA.pubB64,
"fsync",
{ soc: hostile },
undefined,
);
assert.ok(built && built.outer, "B really can build a valid envelope to A");
await a.deliverFromB({ k: "env", e: built.outer, ts: Date.now() });
assert.equal(
a.store.get("Z".repeat(43)),
null,
"the stranger's fsync never reached the store through the router",
);
a.agent.stop();
});
test("Social.start forwards profileSync and appState (absent from the vendored copy)", async () => {
const ns = `t-hooks-${nsSeq++}`;
const { pubsub } = mkPubsub();
let profileGets = 0;
const applied = [];
const social = await Social.start({
suite: { seed: seedA, identity: idA, profile: { name: "ana" } },
app: "game2.ardegazu.ro",
ns,
pubsub,
profileSync: {
get: () => { profileGets++; return { name: "ana", hue: 200, glyph: null, lang: "ro" }; },
apply: (p) => applied.push(["profile", p]),
},
appState: {
ns: "peer-kit-test",
get: () => ({ rooms: 3 }),
apply: (st) => applied.push(["app", st]),
},
});
// the agent must be holding both hooks (the wiring the wrapper used to drop)
assert.equal(typeof social.agent.syncNow, "function", "syncNow() exists upstream");
social.agent.syncNow();
await tick(120);
assert.ok(profileGets >= 1, "profileSync.get was read for the self-sync payload");
await social.stop();
});
test.after(() => {
for (const t of timers) clearInterval(t);
});
|