feat: rework engine and CLI for dnstraverse parity

Port the traversal engine to the Ruby dnstraverse model so behaviour and
output match dns.squish.net:

- dns: single RD=0 query path (RD=1 only for upstream root discovery),
  per-run packet cache, EDNS0 512-fallback with warnings, UDP->TCP on
  truncation; fix --retries 0 and --root-server IP-literal handling;
  drop all hardcoded 127.0.0.1:53 resolvers
- traverse: hierarchical per-branch InfoCache, 7-step response
  classification with the full 10-status vocabulary, bailiwick
  partitioning, strictly-deeper lame-referral rule, refid grammar with
  .0 resolve subtrees and childset digits, per-IP branching at 1/n
  weight, cache-based glue resolution with noglue/loop dead ends, CNAME
  restarts from the deepest cached zone, fast-mode memoization,
  probability aggregation with Ruby-identical stats keys (sums to 1.0)
- output: byte-for-byte reference text format pinned by a golden test,
  reference CLI defaults, working --quiet/--show-X=false, TTY-aware
  colour, deduplicated deterministic JSON
- web: adapt API/SPA to the new engine, SSE events carry refid/status,
  fix subscribe/snapshot duplicate-event race and a statusCls TDZ bug,
  align SPA type list with the backend
- delete the old engine and dead code (net -4,350 lines)

Verified against live runs of the reference Ruby engine across five
domains (answers, NXDOMAIN, null MX, CNAME restart, glueless resolve)
with no divergences beyond the documented typo fixes.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Gary Hansen
2026-07-07 21:42:06 +10:00
co-authored by Claude Fable 5
parent af15c9c2d4
commit d71c7fbef2
53 changed files with 6685 additions and 9366 deletions
+77
View File
@@ -0,0 +1,77 @@
package api
import (
"strconv"
"sync"
"testing"
)
// TestSubscribeSnapshot_NoDuplicates regresses the subscribe/snapshot race:
// subscribers arriving while events are being published must never see the
// same event twice (once from the snapshot replay and once from the channel).
// Events are numbered, so any duplicate breaks strict monotonicity. Slow
// subscribers may legitimately drop events (publishLocked is non-blocking),
// so gaps are not an error.
func TestSubscribeSnapshot_NoDuplicates(t *testing.T) {
job := &TraversalJob{Status: statusRunning}
const total = 2000
const subscribers = 8
var pub sync.WaitGroup
pub.Add(1)
go func() {
defer pub.Done()
for i := 0; i < total; i++ {
ev := ProgressEvent{RefID: strconv.Itoa(i)}
job.mu.Lock()
job.Progress = append(job.Progress, ev)
job.publishLocked(ev)
job.mu.Unlock()
}
job.mu.Lock()
job.Status = statusComplete
job.mu.Unlock()
job.closeSubscribers()
}()
var subs sync.WaitGroup
errs := make(chan string, subscribers)
for s := 0; s < subscribers; s++ {
subs.Add(1)
go func() {
defer subs.Done()
sub, past, done := job.subscribeSnapshot()
defer job.unsubscribe(sub)
last := -1
check := func(refid string) {
n, err := strconv.Atoi(refid)
if err != nil {
errs <- "bad refid " + refid
return
}
if n <= last {
errs <- "event " + refid + " out of order or duplicated after " + strconv.Itoa(last)
return
}
last = n
}
for _, ev := range past {
check(ev.RefID)
}
if !done {
for ev := range sub {
check(ev.RefID)
}
}
}()
}
pub.Wait()
subs.Wait()
close(errs)
for msg := range errs {
t.Error(msg)
}
}