OverviewFilesCommitsIssuesDocsReleasesPeers

atproto-bridge / pds / test / diagnose-fronts.test.js

27 lines · javascript ref:
// diagnose() must RETURN the per-front state it builds (firehoseLen/rpcConnected/live).
// It previously built the `fronts` array but omitted it from the return, so operators couldn't see
// per-front freshness — which is exactly what made the 2026-07-11 stale-front bug slow to diagnose.
import test from 'brittle'
import { mkDidRouter } from './mk-did-router.js'

test('diagnose() returns per-front state (fronts array)', (t) => {
  const fakeSwarm = { on () {}, off () {}, join () { return { flushed: async () => {} } }, flush: async () => {}, connections: new Set() }
  const router = mkDidRouter(fakeSwarm, {}, { fronted: [], refreshMs: 0 })

  router._fronts.set('did:plc:abc', new Map([['k1', {
    handle: 'a.7rnx.net',
    _repoKey: null,
    seq: { core: { length: 7 } },
    rpc: { closed: false }
  }]]))

  const d = router.diagnose()
  t.ok(Array.isArray(d.fronts), 'diagnose returns a fronts array')
  t.is(d.fronts.length, 1, 'one fronted peer reported')
  const f = d.fronts[0]
  t.is(f.did, 'did:plc:abc', 'did reported')
  t.is(f.firehoseKey, 'k1', 'firehoseKey reported')
  t.is(f.firehoseLen, 7, 'firehoseLen (served head length) reported')
  t.is(f.rpcConnected, true, 'rpcConnected reported')
})