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
+40
View File
@@ -5,12 +5,15 @@ import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"net/http/httptest"
"regexp"
"strings"
"testing"
"time"
"gitea.hansenits.com.au/hits/ExploreDNS/internal/config"
"gitea.hansenits.com.au/hits/ExploreDNS/web/api"
)
@@ -264,6 +267,43 @@ func TestStaticSPA_Index(t *testing.T) {
}
}
// TestStaticSPA_TypeOptions asserts the SPA type dropdown offers exactly the
// query types config.ParseQueryType accepts.
func TestStaticSPA_TypeOptions(t *testing.T) {
srv := newTestServer(t)
defer srv.Shutdown(5 * time.Second) //nolint:errcheck
resp, err := http.Get("http://" + srv.Addr() + "/")
if err != nil {
t.Fatal(err)
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatal(err)
}
page := string(body)
re := regexp.MustCompile(`<option>([A-Z]+)</option>`)
var got []string
for _, m := range re.FindAllStringSubmatch(page, -1) {
got = append(got, m[1])
}
want := []string{"A", "AAAA", "NS", "CNAME", "MX", "TXT", "SOA", "PTR", "ANY"}
if len(got) != len(want) {
t.Fatalf("type options = %v, want %v", got, want)
}
for i, typ := range want {
if got[i] != typ {
t.Fatalf("type options = %v, want %v", got, want)
}
if _, err := config.ParseQueryType(typ); err != nil {
t.Fatalf("option %s rejected by ParseQueryType: %v", typ, err)
}
}
}
func TestStaticSPA_FallbackToIndex(t *testing.T) {
srv := newTestServer(t)
defer srv.Shutdown(5 * time.Second) //nolint:errcheck