Files
meshcore-analyzer/cmd/server/packet_path_bridge_test.go
T
dborupandClaude Sonnet 5 575743efda feat: View Path highlights confirmed bridge repeaters
Adds IsBridge to PacketPathPoint/PacketPathObserver and PublicKey to
PacketPathObserver (needed to look bridges up, and useful on its own
for future features). Set by a new markBridgeRepeaters handler-level
step in routes.go, not GetPacketPath itself, since the underlying data
(TransportedScopes per repeater) lives in the in-memory store, not
SQL -- same "relays for 2+ distinct regions" definition and data
source as the Foreign Traffic tab's existing Bridge badge
(ScopeStatsResponse.bridgeRepeaters), just applied to whichever
handful of pubkeys one packet's path touches.

The map gives a bridge repeater a bold purple outline (on top of
whatever primary/approx styling already applies) plus a tooltip note,
so the mesh's backbone nodes stand out regardless of which branch
they're in.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-24 18:16:15 +02:00

77 lines
2.6 KiB
Go

package main
import (
"testing"
"time"
)
// TestMarkBridgeRepeaters_NilStore covers the graceful no-op when the
// in-memory store isn't available (s.store can legitimately be nil --
// see handlePacketPath). Must not panic and must leave every IsBridge
// at its zero value (false).
func TestMarkBridgeRepeaters_NilStore(t *testing.T) {
resp := &PacketPathResponse{
Hash: "deadbeef",
Branches: []PacketPathBranch{
{Points: []PacketPathPoint{{PublicKey: "pk1"}}, Observer: &PacketPathObserver{PublicKey: "obs1"}},
},
}
markBridgeRepeaters(resp, nil, &Config{})
if resp.Branches[0].Points[0].IsBridge {
t.Errorf("Points[0].IsBridge = true, want false -- store is nil, nothing should be marked")
}
if resp.Branches[0].Observer.IsBridge {
t.Errorf("Observer.IsBridge = true, want false -- store is nil, nothing should be marked")
}
}
// TestMarkBridgeRepeaters_TwoScopesIsBridge covers the actual
// determination: a pubkey relaying 2+ distinct region scopes (the same
// definition/data source as the Foreign Traffic tab's "Bridge" badge,
// ScopeStatsResponse.bridgeRepeaters) gets IsBridge=true on every point
// and observer entry referencing it; a pubkey with 0 or 1 scope, or one
// missing from the relay map entirely, stays false.
func TestMarkBridgeRepeaters_TwoScopesIsBridge(t *testing.T) {
store := &PacketStore{
repeaterRelayCache: map[string]RepeaterRelayInfo{
"bridgepk": {TransportedScopes: []string{"#dk", "#se"}},
"regionalpk": {TransportedScopes: []string{"#dk"}},
"unknownscopepk": {TransportedScopes: nil},
},
repeaterRelayCacheWin: 24,
repeaterRelayAt: time.Now(),
}
resp := &PacketPathResponse{
Hash: "deadbeef",
Branches: []PacketPathBranch{
{
Points: []PacketPathPoint{
{PublicKey: "bridgepk"},
{PublicKey: "regionalpk"},
{PublicKey: "unknownscopepk"},
{PublicKey: "notinrelaymap"},
},
Observer: &PacketPathObserver{PublicKey: "BridgePK"}, // case-insensitive match
},
},
}
markBridgeRepeaters(resp, store, &Config{})
pts := resp.Branches[0].Points
if !pts[0].IsBridge {
t.Errorf("Points[0] (bridgepk, 2 scopes) IsBridge = false, want true")
}
if pts[1].IsBridge {
t.Errorf("Points[1] (regionalpk, 1 scope) IsBridge = true, want false")
}
if pts[2].IsBridge {
t.Errorf("Points[2] (unknownscopepk, 0 scopes) IsBridge = true, want false")
}
if pts[3].IsBridge {
t.Errorf("Points[3] (notinrelaymap, absent from relay map) IsBridge = true, want false")
}
if !resp.Branches[0].Observer.IsBridge {
t.Errorf("Observer (BridgePK, case-insensitive match on bridgepk) IsBridge = false, want true")
}
}