-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathintegration_gossip_test.go
More file actions
614 lines (510 loc) · 21.2 KB
/
Copy pathintegration_gossip_test.go
File metadata and controls
614 lines (510 loc) · 21.2 KB
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
603
604
605
606
607
608
609
610
611
612
613
614
package nara
import (
"fmt"
"net/http"
"net/http/httptest"
"testing"
"time"
"github.com/eljojo/nara/identity"
"github.com/eljojo/nara/types"
)
// TestIntegration_GossipOnlyMode validates that naras can operate in gossip-only mode
// without MQTT, spreading events purely via P2P zine exchanges using performGossipRound()
func TestIntegration_GossipOnlyMode(t *testing.T) {
t.Parallel()
// Create 5 naras in gossip-only mode with full mesh topology
mesh := testCreateMeshNetwork(t, []string{"gossip-nara-a", "gossip-nara-b", "gossip-nara-c", "gossip-nara-d", "gossip-nara-e"}, 50, 1000, 0)
// Nara A creates a social event
event := NewSocialSyncEvent("tease", mesh.Get(0).Me.Name, "gossip-nara-b", "high restarts", "")
mesh.Get(0).SyncLedger.AddEvent(event)
// Run gossip rounds using the REAL performGossipRound() production code
for round := 0; round < 3; round++ {
for i := 0; i < 5; i++ {
mesh.Get(i).Network.performGossipRound()
}
// Wait for async exchanges to complete
time.Sleep(50 * time.Millisecond)
}
// Verify event propagated to most naras via gossip
propagatedCount := 0
for i := 0; i < 5; i++ {
events := mesh.Get(i).SyncLedger.GetEventsByService(ServiceSocial)
for _, e := range events {
if e.Social != nil && e.Social.Type == "tease" && e.Social.Target == "gossip-nara-b" {
propagatedCount++
break
}
}
}
// Should reach all 5 naras via gossip (epidemic spread)
if propagatedCount < 5 {
t.Errorf("Expected event to reach all 5 naras via gossip, reached %d", propagatedCount)
}
t.Logf("✅ Gossip-only mode: event reached %d/5 naras via performGossipRound()", propagatedCount)
}
// TestIntegration_HybridMode validates that naras can use both MQTT and gossip simultaneously
// In hybrid mode, events should propagate via gossip using performGossipRound()
func TestIntegration_HybridMode(t *testing.T) {
t.Parallel()
// Create 3 naras in hybrid mode with full mesh topology
mesh := testCreateMeshNetwork(t, []string{"hybrid-nara-a", "hybrid-nara-b", "hybrid-nara-c"}, 50, 1000, 0)
for i := 0; i < 3; i++ {
mesh.Get(i).Network.TransportMode = TransportHybrid
}
// Nara A creates an event
event := NewSocialSyncEvent("tease", "hybrid-nara-a", "hybrid-nara-b", "came back", "")
mesh.Get(0).SyncLedger.AddEvent(event)
// Run gossip rounds using performGossipRound() production code
for round := 0; round < 2; round++ {
for i := 0; i < 3; i++ {
mesh.Get(i).Network.performGossipRound()
}
time.Sleep(50 * time.Millisecond)
}
// All naras should see the event via gossip transport
for i := 0; i < 3; i++ {
events := mesh.Get(i).SyncLedger.GetEventsByService(ServiceSocial)
if len(events) < 1 {
t.Errorf("Nara %d expected to see at least 1 event, got %d", i, len(events))
}
}
t.Logf("✅ Hybrid mode: event propagated to all naras via performGossipRound()")
}
// TestIntegration_MixedNetworkTopology validates that gossip-enabled naras (gossip-only and hybrid)
// can propagate events via performGossipRound(), while MQTT-only naras are excluded from gossip
func TestIntegration_MixedNetworkTopology(t *testing.T) {
t.Parallel()
tc := NewTestCoordinator(t)
// Create mixed network:
// - 2 MQTT-only naras (no gossip server)
// - 2 Gossip-only naras (gossip server)
// - 2 Hybrid naras (gossip server)
names := []string{"mixed-nara-a", "mixed-nara-b", "mixed-nara-c", "mixed-nara-d", "mixed-nara-e", "mixed-nara-f"}
modes := []TransportMode{TransportMQTT, TransportMQTT, TransportGossip, TransportGossip, TransportHybrid, TransportHybrid}
naras := make([]*LocalNara, 6)
for i := 0; i < 6; i++ {
var opts []CoordinatorNaraOption
if modes[i] == TransportMQTT {
opts = []CoordinatorNaraOption{WithoutServer(), NotBooting()}
} else {
opts = []CoordinatorNaraOption{WithHandlers("gossip"), NotBooting()}
}
naras[i] = tc.AddNara(names[i], opts...)
naras[i].Network.TransportMode = modes[i]
}
// Connect all naras (full mesh topology)
tc.ConnectAll()
// Gossip-only nara creates event
event := NewSocialSyncEvent("tease", "mixed-nara-c", "mixed-nara-a", "high restarts", "")
naras[2].SyncLedger.AddEvent(event) // mixed-nara-c is gossip-only
// Run gossip rounds using performGossipRound() - only gossip-enabled naras participate
for round := 0; round < 2; round++ {
for i := 2; i < 6; i++ { // Only gossip-enabled naras (indices 2-5)
naras[i].Network.performGossipRound()
}
time.Sleep(50 * time.Millisecond)
}
// Verify: gossip-enabled naras (indices 2-5) should have the event
gossipEnabledWithEvent := 0
for i := 2; i < 6; i++ {
events := naras[i].SyncLedger.GetEventsByService(ServiceSocial)
if len(events) >= 1 {
gossipEnabledWithEvent++
}
}
if gossipEnabledWithEvent < 4 {
t.Errorf("Expected all 4 gossip-enabled naras to have event, got %d", gossipEnabledWithEvent)
}
// Verify: MQTT-only naras (indices 0-1) should NOT have the event via gossip
// (they would need MQTT or a hybrid bridge in real deployment)
for i := 0; i < 2; i++ {
events := naras[i].SyncLedger.GetEventsByService(ServiceSocial)
if len(events) > 0 {
t.Errorf("MQTT-only nara %d should not receive events via gossip, got %d", i, len(events))
}
}
t.Logf("✅ Mixed topology: gossip-enabled naras propagated event via performGossipRound()")
}
// TestIntegration_ZineCreationAndExchange validates zine structure and bidirectional exchange
// Uses real HTTP servers and the production performGossipRound() code path
func TestIntegration_ZineCreationAndExchange(t *testing.T) {
t.Parallel()
// Create 2 naras with full mesh topology
mesh := testCreateMeshNetwork(t, []string{"alice", "bob"}, 50, 1000, 0)
alice := mesh.GetByName("alice")
bob := mesh.GetByName("bob")
// Alice creates some events
// NOTE: Each event must have unique content to avoid ID collisions when
// time.Now().UnixNano() returns the same value in a tight loop
for i := 0; i < 5; i++ {
event := NewSocialSyncEvent("tease", "alice", "bob", fmt.Sprintf("test-%d", i), "")
alice.SyncLedger.AddEvent(event)
}
// Verify alice has a zine to send
aliceZine := alice.Network.createZine()
if aliceZine == nil {
t.Fatal("Alice createZine returned nil")
}
if len(aliceZine.Events) != 5 {
t.Errorf("Expected alice's zine to have 5 events, got %d", len(aliceZine.Events))
}
if aliceZine.Signature == "" {
t.Error("Expected zine to be signed")
}
// Alice performs a gossip round - this triggers the REAL HTTP exchange
alice.Network.performGossipRound()
// Wait for async exchange to complete
time.Sleep(100 * time.Millisecond)
// Verify bob received alice's events via the gossip round
bobEvents := bob.SyncLedger.GetEventsByService(ServiceSocial)
if len(bobEvents) < 5 {
t.Errorf("Bob should have received alice's 5 events via gossip, got %d", len(bobEvents))
}
// Bob creates his own event
event := NewSocialSyncEvent("tease", "bob", "alice", "response", "")
bob.SyncLedger.AddEvent(event)
// Bob performs a gossip round back to alice
bob.Network.performGossipRound()
// Wait for async exchange
time.Sleep(100 * time.Millisecond)
// Verify alice received bob's event via gossip
aliceEvents := alice.SyncLedger.GetEventsByService(ServiceSocial)
if len(aliceEvents) < 6 { // original 5 + bob's 1
t.Errorf("Alice should have 6 events total (5 original + 1 from bob via gossip), got %d", len(aliceEvents))
}
t.Logf("✅ Zine exchange: bidirectional propagation via performGossipRound() working correctly")
}
// TestIntegration_GossipTargetSelection validates that gossip picks random mesh neighbors
// Uses the production selectGossipTargets() method instead of test helper
func TestIntegration_GossipTargetSelection(t *testing.T) {
t.Parallel()
ln := testLocalNaraWithParams(t, "test-nara", 50, 1000)
ln.Network.TransportMode = TransportGossip
// Add 10 mesh-enabled neighbors
for i := 0; i < 10; i++ {
neighborName := types.NaraName(fmt.Sprintf("neighbor-%c", 'a'+i))
neighbor := NewNara(neighborName)
neighbor.Status.MeshIP = fmt.Sprintf("100.64.0.%d", 1+i)
ln.Network.importNara(neighbor)
ln.setObservation(neighborName, NaraObservation{Online: "ONLINE"})
}
// Select gossip targets multiple times using production code
selections := make(map[string]int)
for i := 0; i < 50; i++ {
targets := ln.Network.selectGossipTargets()
for _, target := range targets {
selections[target.String()]++
}
}
// Verify randomness: each neighbor should be selected at least once
if len(selections) < 5 { // Should hit at least half the neighbors
t.Errorf("Expected gossip to select diverse neighbors, only selected %d unique targets", len(selections))
}
t.Logf("✅ Gossip target selection: selected %d unique neighbors across 50 rounds", len(selections))
}
// TestIntegration_GossipEventDeduplication validates that duplicate events arriving
// via both MQTT and gossip are deduplicated automatically
func TestIntegration_GossipEventDeduplication(t *testing.T) {
t.Parallel()
ledger := NewSyncLedger(1000)
// Create event
event := NewSocialSyncEvent("tease", "alice", "bob", "high restarts", "")
// Add same event multiple times (simulating arrival via MQTT and gossip)
added1 := ledger.AddEvent(event)
added2 := ledger.AddEvent(event) // Duplicate
added3 := ledger.AddEvent(event) // Duplicate
// First should succeed, duplicates should be rejected
if !added1 {
t.Error("First event should be added")
}
if added2 || added3 {
t.Error("Duplicate events should be rejected")
}
// Verify only one event in ledger
events := ledger.GetEventsByService(ServiceSocial)
if len(events) != 1 {
t.Errorf("Expected 1 event after deduplication, got %d", len(events))
}
t.Logf("✅ Event deduplication: same event via multiple transports correctly deduplicated")
}
// MockPeerDiscovery returns a predefined list of peers for testing
type MockPeerDiscovery struct {
peers []DiscoveredPeer
}
func (m *MockPeerDiscovery) ScanForPeers(myIP string) []DiscoveredPeer {
return m.peers
}
// TestIntegration_MeshDiscovery validates the discovery mechanism using a mock strategy
// This tests the actual discoverMeshPeers() production code path:
// 1. Strategy pattern scans for peers (mocked: returns predefined list)
// 2. Production code adds discovered peers to neighborhood
// 3. Production code marks them as ONLINE
// 4. Production code stores mesh IPs
// 5. Bootstrap is skipped in test (requires real HTTP mesh)
func TestIntegration_MeshDiscovery(t *testing.T) {
t.Parallel()
// Create a nara that will discover peers (use testSoul for valid keypair)
discoverer := testLocalNaraWithParams(t, "discovery-nara-a", 50, 1000)
discoverer.Network.TransportMode = TransportGossip
// Verify no neighbors initially
if len(discoverer.Network.NeighbourhoodOnlineNames()) != 0 {
t.Fatalf("Expected 0 initial neighbors, got %d", len(discoverer.Network.NeighbourhoodOnlineNames()))
}
// Set up mock discovery that returns 2 peers
// This replaces the real TailscalePeerDiscovery which would scan 100.64.0.1-254
mockDiscovery := &MockPeerDiscovery{
peers: []DiscoveredPeer{
{Name: types.NaraName("discovery-nara-b"), MeshIP: "100.64.0.2"},
{Name: types.NaraName("discovery-nara-c"), MeshIP: "100.64.0.3"},
},
}
discoverer.Network.peerDiscovery = mockDiscovery
// Mock tsnetMesh so discoverMeshPeers doesn't bail early
// (In real code, this would be the actual tsnet mesh)
// Server() returns nil, so bootstrap will be skipped
discoverer.Network.tsnetMesh = &TsnetMesh{}
// Run discovery - this is the ACTUAL production code path
// The only mock is the strategy that returns peers
discoverer.Network.discoverMeshPeers()
// Verify neighbors were discovered
neighborNames := discoverer.Network.NeighbourhoodOnlineNames()
if len(neighborNames) != 2 {
t.Errorf("Expected 2 neighbors after discovery, got %d: %v", len(neighborNames), neighborNames)
}
// Verify the specific naras were discovered
expectedNeighbors := map[string]bool{
"discovery-nara-b": false,
"discovery-nara-c": false,
}
for _, name := range neighborNames {
if _, ok := expectedNeighbors[name.String()]; ok {
expectedNeighbors[name.String()] = true
}
}
for name, found := range expectedNeighbors {
if !found {
t.Errorf("Expected to discover %s but didn't", name)
}
}
// Verify mesh IPs were stored correctly
meshIPb := discoverer.Network.getMeshIPForNara(types.NaraName("discovery-nara-b"))
if meshIPb != "100.64.0.2" {
t.Errorf("Expected mesh IP 100.64.0.2 for discovery-nara-b, got %s", meshIPb)
}
meshIPc := discoverer.Network.getMeshIPForNara(types.NaraName("discovery-nara-c"))
if meshIPc != "100.64.0.3" {
t.Errorf("Expected mesh IP 100.64.0.3 for discovery-nara-c, got %s", meshIPc)
}
// Verify observations were created
obsB := discoverer.getObservation(types.NaraName("discovery-nara-b"))
if obsB.Online != "ONLINE" {
t.Errorf("Expected discovery-nara-b to be marked ONLINE, got %s", obsB.Online)
}
obsC := discoverer.getObservation(types.NaraName("discovery-nara-c"))
if obsC.Online != "ONLINE" {
t.Errorf("Expected discovery-nara-c to be marked ONLINE, got %s", obsC.Online)
}
t.Logf("✅ Mesh discovery: successfully discovered 2 peers using strategy pattern")
t.Logf(" - discovery-nara-b at %s", meshIPb)
t.Logf(" - discovery-nara-c at %s", meshIPc)
}
// TestIntegration_GossipOnlyBootRecovery validates that in gossip-only mode,
// boot recovery discovers peers via mesh before trying to sync.
// BUG: Currently boot recovery runs before mesh discovery, so it finds no neighbors.
func TestIntegration_GossipOnlyBootRecovery(t *testing.T) {
t.Parallel()
// Create a nara in gossip-only mode
nara := testLocalNaraWithParams(t, "boot-recovery-nara", 50, 1000)
nara.Network.TransportMode = TransportGossip
// Set up mock peer discovery that returns peers
mockDiscovery := &MockPeerDiscovery{
peers: []DiscoveredPeer{
{Name: "peer-alpha", MeshIP: "100.64.0.10"},
{Name: "peer-beta", MeshIP: "100.64.0.11"},
},
}
nara.Network.peerDiscovery = mockDiscovery
nara.Network.tsnetMesh = &TsnetMesh{} // Mock mesh so discovery doesn't bail
// Verify no neighbors initially (simulates fresh boot)
if len(nara.Network.NeighbourhoodOnlineNames()) != 0 {
t.Fatalf("Expected 0 initial neighbors, got %d", len(nara.Network.NeighbourhoodOnlineNames()))
}
// THE BUG: In gossip-only mode, there are no MQTT-discovered neighbors.
// Boot recovery should trigger mesh discovery automatically before checking for neighbors.
// We test this by calling getNeighborsForBootRecovery() which should return
// discovered peers in gossip-only mode.
online := nara.Network.getNeighborsForBootRecovery()
// In gossip-only mode, this MUST return discovered peers (after triggering mesh discovery)
if len(online) != 2 {
t.Errorf("BUG: In gossip-only mode, getNeighborsForBootRecovery() should discover peers via mesh. Expected 2 neighbors, got %d", len(online))
t.Log("Boot recovery needs to call discoverMeshPeers() before checking for neighbors in gossip-only mode")
} else {
t.Logf("✅ Gossip-only boot recovery: found %d peers via mesh discovery", len(online))
}
}
// TestIntegration_SendDM validates that SendDM correctly sends events to another nara
func TestIntegration_SendDM(t *testing.T) {
t.Parallel()
tc := NewTestCoordinator(t)
sender := tc.AddNara("sender", WithHandlers("dm"))
receiver := tc.AddNara("receiver", WithHandlers("dm"))
tc.Connect("sender", "receiver")
// Create a signed event
event := NewTeaseSyncEvent("sender", "receiver", "high-restarts", sender.Keypair)
// Send DM
success := sender.Network.SendDM("receiver", event)
if !success {
t.Error("SendDM should return true on success")
}
// Verify receiver got the event
events := receiver.SyncLedger.GetEventsByService(ServiceSocial)
found := false
for _, e := range events {
if e.Social != nil && e.Social.Type == "tease" && e.Social.Actor == "sender" {
found = true
break
}
}
if !found {
t.Error("Receiver should have the tease event in their ledger")
}
t.Log("✅ SendDM: successfully sent event directly to receiver")
}
// TestIntegration_SendDM_UnreachableTarget validates that SendDM handles unreachable targets gracefully
func TestIntegration_SendDM_UnreachableTarget(t *testing.T) {
t.Parallel()
sender := testLocalNara(t, "sender")
sender.Network.testHTTPClient = &http.Client{Timeout: 100 * time.Millisecond}
sender.Network.testMeshURLs = map[types.NaraName]string{} // No URL for receiver
event := NewTeaseSyncEvent("sender", "receiver", "high-restarts", sender.Keypair)
// Should return false when target is unreachable
success := sender.Network.SendDM("receiver", event)
if success {
t.Error("SendDM should return false when target has no mesh URL")
}
t.Log("✅ SendDM: correctly handles unreachable target")
}
// TestIntegration_TeaseDM validates the full tease flow using DM instead of MQTT
func TestIntegration_TeaseDM(t *testing.T) {
t.Parallel()
// Create two naras
alice := testLocalNara(t, "alice")
bob := testLocalNara(t, "bob")
// Create HTTP test server for bob
mux := http.NewServeMux()
mux.HandleFunc("/dm", bob.Network.httpDMHandler)
server := httptest.NewServer(mux)
defer server.Close()
// Alice knows bob
bobNara := NewNara(types.NaraName("bob"))
bobNara.ID = bob.ID // Set ID so nameToID mapping is created
bobNara.Status.ID = bob.ID
bobNara.Status.PublicKey = identity.FormatPublicKey(bob.Keypair.PublicKey)
alice.Network.importNara(bobNara)
alice.Network.testHTTPClient = &http.Client{Timeout: 5 * time.Second}
alice.Network.testMeshURLs = map[types.NaraName]string{types.NaraName("bob"): server.URL}
// Configure meshClient with bob's ID
alice.Network.meshClient.EnableTestMode(map[types.NaraID]string{
bob.ID: server.URL,
})
// Bob knows alice (to verify signature)
aliceNara := NewNara("alice")
aliceNara.ID = alice.ID // Set ID so nameToID mapping is created
aliceNara.Status.ID = alice.ID
aliceNara.Status.PublicKey = identity.FormatPublicKey(alice.Keypair.PublicKey)
bob.Network.importNara(aliceNara)
// Alice teases bob
success := alice.Network.Tease("bob", "high-restarts")
if !success {
t.Error("Tease should return true")
}
// Verify alice has the event in her ledger
aliceEvents := alice.SyncLedger.GetEventsByService(ServiceSocial)
aliceHasEvent := false
for _, e := range aliceEvents {
if e.Social != nil && e.Social.Type == "tease" && e.Social.Target == "bob" {
aliceHasEvent = true
break
}
}
if !aliceHasEvent {
t.Error("Alice should have the tease in her ledger")
}
// Verify bob received the DM
bobEvents := bob.SyncLedger.GetEventsByService(ServiceSocial)
bobHasEvent := false
for _, e := range bobEvents {
if e.Social != nil && e.Social.Type == "tease" && e.Social.Actor == "alice" && e.Social.Target == "bob" {
bobHasEvent = true
break
}
}
if !bobHasEvent {
t.Error("Bob should have received the tease via DM")
}
t.Log("✅ Tease DM: alice teased bob, both have the event in their ledgers")
}
// TestIntegration_TeaseDM_SpreadViaGossip validates that teases spread via gossip when DM fails
func TestIntegration_TeaseDM_SpreadViaGossip(t *testing.T) {
t.Parallel()
tc := NewTestCoordinator(t)
alice := tc.AddNara("alice", WithHandlers("gossip"), NotBooting())
bob := tc.AddNara("bob", WithoutServer(), NotBooting()) // unreachable - no server
charlie := tc.AddNara("charlie", WithHandlers("gossip"), NotBooting())
// Connect alice <-> charlie (gossip)
tc.Connect("alice", "charlie")
tc.SetOnline("alice", "charlie")
tc.SetOnline("charlie", "alice")
// Alice knows bob exists (but can't reach via DM)
bobNara := NewNara("bob")
bobNara.ID = bob.ID
bobNara.Status.ID = bob.ID
bobNara.Status.PublicKey = identity.FormatPublicKey(bob.Keypair.PublicKey)
alice.Network.importNara(bobNara)
tc.SetOnline("alice", "bob")
// Charlie knows bob exists
bobNaraForCharlie := NewNara("bob")
bobNaraForCharlie.ID = bob.ID
bobNaraForCharlie.Status.ID = bob.ID
bobNaraForCharlie.Status.PublicKey = identity.FormatPublicKey(bob.Keypair.PublicKey)
charlie.Network.importNara(bobNaraForCharlie)
tc.SetOnline("charlie", "bob")
// Bob knows alice (to verify when gossip arrives)
aliceNaraForBob := NewNara("alice")
aliceNaraForBob.ID = alice.ID
aliceNaraForBob.Status.ID = alice.ID
aliceNaraForBob.Status.PublicKey = identity.FormatPublicKey(alice.Keypair.PublicKey)
bob.Network.importNara(aliceNaraForBob)
// Set transport mode to gossip
alice.Network.TransportMode = TransportGossip
charlie.Network.TransportMode = TransportGossip
// Alice teases bob (DM will fail since bob is unreachable)
success := alice.Network.Tease("bob", "high-restarts")
if !success {
t.Error("Tease should return true even if DM fails")
}
// Verify alice has the event
aliceEvents := alice.SyncLedger.GetEventsByService(ServiceSocial)
if len(aliceEvents) == 0 {
t.Error("Alice should have the tease in her ledger")
}
// Run gossip rounds - alice gossips with charlie
for round := 0; round < 3; round++ {
alice.Network.performGossipRound()
charlie.Network.performGossipRound()
time.Sleep(50 * time.Millisecond)
}
// Verify charlie got the event via gossip
charlieEvents := charlie.SyncLedger.GetEventsByService(ServiceSocial)
charlieHasEvent := false
for _, e := range charlieEvents {
if e.Social != nil && e.Social.Type == "tease" && e.Social.Actor == "alice" && e.Social.Target == "bob" {
charlieHasEvent = true
break
}
}
if !charlieHasEvent {
t.Error("Charlie should have received the tease via gossip")
}
t.Log("✅ Tease DM fallback: tease spread via gossip when DM failed")
}