Files
meshcore-analyzer/cmd
Kpa-clawbot dbb013a6bf test(#1201): regression coverage for hop disambiguator tier-1 + end-to-end top-hops fixture (#1202)
Mutation test confirmed: reverting cmd/server/store.go:2975
(`setContext(buildHopContextPubkeys(tx, pm))` → `setContext(nil)`) in
`buildDistanceIndex` produces failing assertion in
`TestTopHopsRespectsContextAcrossAllCallSites`: top-hops ranking flips
to `72dddd→8acccc@13.0km` (Berlin↔Berlin misresolution), CA↔CA pair
absent. After reverting the mutation, the test passes again.

Fixes #1201

## Summary
Pure test addition. No production code changed. Adds regression coverage
for the hop disambiguator's tier-1 (neighbor affinity) path and an
end-to-end fixture that catches revert-to-nil-context regressions across
all 9 call sites of `pm.resolveWithContext`.

## Sub-tasks (all 4 landed)

1. **Tier-1 explicit** — `hop_disambig_tier1_test.go`:
   - `Tier1_StrongAffinityPicksX` (strong-X edge wins)
- `Tier1_StrongAffinityPicksY` (reverse weights — proves score is read)
   - `Tier1_AmbiguousEdgeSkipsToTier2` (`Ambiguous=true` → skip)
2. **Tier ordering** — `Tier1_BeatsTier2WhenBothSignal` (tier 1 wins
when both signal)
3. **Tier-1 fallback** —
   - `Tier1_EmptyGraphFallsThrough` (graph has no edges for context)
   - `Tier1_NilGraphFallsThrough` (graph is nil)
- `Tier1_ScoresTooCloseFallsThrough` (best < `affinityConfidenceRatio` ×
runner-up)
4. **End-to-end fixture** — `hop_disambig_e2e_test.go`:
- 9 nodes with intentional prefix collisions across SLO/LA/NYC/Berlin
(prefix `72`) and SF/CA/Berlin (prefix `8a`); Berlin candidates have
`obsCount=200` so they'd win tier-3 absent context.
   - 50 transmissions path `["72","8a"]`, sender + observer in CA.
- Affinity graph seeded with strong `sender↔72aa` and `sender↔8aaa`
edges.
- Asserts: CA↔CA hop present, no Berlin pubkeys in `distHops`, max
distance < 300 km cap.

## TDD exemption
Net-new regression-sentinel tests for behavior already correct on master
post-#1198. Each test passed on first run (no production bug surfaced).
The mutation test on sub-task 4 is the gating proof: forcing
`setContext(nil)` at `store.go:2975` makes the test fail with the exact
misresolution class the issue describes (Berlin↔Berlin leaks into
top-hops).

## Acceptance criteria
- [x] Tier-1 affinity test added with 3 cases
- [x] Tier-ordering test added
- [x] Tier-1 fallback tests added (nil / empty / scores-too-close)
- [x] End-to-end fixture added with multi-candidate-prefix nodes
- [x] End-to-end fixture fails if any call site reverts to `nil` context
(mutation-verified)
- [x] Test files live in `cmd/server/` alongside
`prefix_map_role_test.go`

---------

Co-authored-by: openclaw-bot <bot@openclaw.local>
Co-authored-by: corescope-bot <bot@corescope.local>
2026-05-15 20:24:55 -07:00
..