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:
co-authored by
Claude Fable 5
parent
af15c9c2d4
commit
d71c7fbef2
+21
-164
@@ -41,28 +41,6 @@ func TestParseQueryTypeInvalid(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseUDPSizeValid(t *testing.T) {
|
||||
cases := []string{"512", "2048", "4096"}
|
||||
for _, s := range cases {
|
||||
if _, err := ParseUDPSize(s); err != nil {
|
||||
t.Errorf("ParseUDPSize(%q) unexpected error: %v", s, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseUDPSizeInvalid(t *testing.T) {
|
||||
cases := []string{"0", "511", "4097", "notanumber"}
|
||||
for _, s := range cases {
|
||||
_, err := ParseUDPSize(s)
|
||||
if err == nil {
|
||||
t.Errorf("ParseUDPSize(%q): expected error", s)
|
||||
}
|
||||
if !errors.Is(err, ErrInvalidUDPSize) {
|
||||
t.Errorf("ParseUDPSize(%q): expected ErrInvalidUDPSize, got %v", s, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateOK(t *testing.T) {
|
||||
cfg := DefaultConfig()
|
||||
if err := cfg.Validate(); err != nil {
|
||||
@@ -138,65 +116,6 @@ func TestGetDomainMissing(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseRootServerEmpty(t *testing.T) {
|
||||
cfg := DefaultConfig()
|
||||
ip, err := cfg.ParseRootServer()
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error for empty root server: %v", err)
|
||||
}
|
||||
if ip != nil {
|
||||
t.Errorf("expected nil IP for empty root server, got %v", ip)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseRootServerValidIPv4(t *testing.T) {
|
||||
cfg := DefaultConfig()
|
||||
cfg.RootServer = "198.41.0.4"
|
||||
ip, err := cfg.ParseRootServer()
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if ip == nil || ip.String() != "198.41.0.4" {
|
||||
t.Errorf("expected 198.41.0.4, got %v", ip)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseRootServerValidIPv6(t *testing.T) {
|
||||
cfg := DefaultConfig()
|
||||
cfg.RootServer = "2001:503:ba3e::2:30"
|
||||
ip, err := cfg.ParseRootServer()
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if ip == nil {
|
||||
t.Error("expected non-nil IP for valid IPv6 address")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseRootServerInvalid(t *testing.T) {
|
||||
cfg := DefaultConfig()
|
||||
cfg.RootServer = "not-an-ip"
|
||||
_, err := cfg.ParseRootServer()
|
||||
if err == nil {
|
||||
t.Fatal("expected error for invalid root server IP")
|
||||
}
|
||||
if !errors.Is(err, ErrInvalidRootServer) {
|
||||
t.Errorf("expected ErrInvalidRootServer, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseRootServerHostname(t *testing.T) {
|
||||
cfg := DefaultConfig()
|
||||
cfg.RootServer = "a.root-servers.net"
|
||||
_, err := cfg.ParseRootServer()
|
||||
if err == nil {
|
||||
t.Fatal("expected error for hostname (not IP) root server")
|
||||
}
|
||||
if !errors.Is(err, ErrInvalidRootServer) {
|
||||
t.Errorf("expected ErrInvalidRootServer, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseDebugLevel(t *testing.T) {
|
||||
cases := []struct {
|
||||
d, dd bool
|
||||
@@ -215,96 +134,34 @@ func TestParseDebugLevel(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseMaxDepthValid(t *testing.T) {
|
||||
cases := []struct {
|
||||
input string
|
||||
want int
|
||||
}{
|
||||
{"1", 1},
|
||||
{"20", 20},
|
||||
{"100", 100},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
got, err := ParseMaxDepth(tc.input)
|
||||
if err != nil {
|
||||
t.Errorf("ParseMaxDepth(%q) unexpected error: %v", tc.input, err)
|
||||
}
|
||||
if got != tc.want {
|
||||
t.Errorf("ParseMaxDepth(%q) = %d, want %d", tc.input, got, tc.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseMaxDepthInvalid(t *testing.T) {
|
||||
cases := []string{"0", "101", "notanumber", "-1"}
|
||||
for _, s := range cases {
|
||||
_, err := ParseMaxDepth(s)
|
||||
if err == nil {
|
||||
t.Errorf("ParseMaxDepth(%q): expected error", s)
|
||||
continue
|
||||
}
|
||||
if !errors.Is(err, ErrInvalidMaxDepth) {
|
||||
t.Errorf("ParseMaxDepth(%q): expected ErrInvalidMaxDepth, got %v", s, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseRetriesValid(t *testing.T) {
|
||||
cases := []struct {
|
||||
input string
|
||||
want int
|
||||
}{
|
||||
{"0", 0},
|
||||
{"2", 2},
|
||||
{"10", 10},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
got, err := ParseRetries(tc.input)
|
||||
if err != nil {
|
||||
t.Errorf("ParseRetries(%q) unexpected error: %v", tc.input, err)
|
||||
}
|
||||
if got != tc.want {
|
||||
t.Errorf("ParseRetries(%q) = %d, want %d", tc.input, got, tc.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseRetriesInvalid(t *testing.T) {
|
||||
cases := []string{"-1", "11", "notanumber"}
|
||||
for _, s := range cases {
|
||||
_, err := ParseRetries(s)
|
||||
if err == nil {
|
||||
t.Errorf("ParseRetries(%q): expected error", s)
|
||||
continue
|
||||
}
|
||||
if !errors.Is(err, ErrInvalidRetries) {
|
||||
t.Errorf("ParseRetries(%q): expected ErrInvalidRetries, got %v", s, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrintUsage(t *testing.T) {
|
||||
// PrintUsage writes to stderr; just ensure it doesn't panic.
|
||||
PrintUsage()
|
||||
}
|
||||
|
||||
func TestValidateBadQueryType(t *testing.T) {
|
||||
cfg := DefaultConfig()
|
||||
cfg.QueryType = "BOGUS"
|
||||
if err := cfg.Validate(); !errors.Is(err, ErrInvalidQueryType) {
|
||||
t.Errorf("expected ErrInvalidQueryType, got %v", err)
|
||||
}
|
||||
cfg := DefaultConfig()
|
||||
cfg.QueryType = "BOGUS"
|
||||
if err := cfg.Validate(); !errors.Is(err, ErrInvalidQueryType) {
|
||||
t.Errorf("expected ErrInvalidQueryType, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDefaultConfigIsValid(t *testing.T) {
|
||||
cfg := DefaultConfig()
|
||||
if cfg.QueryType != "A" {
|
||||
t.Errorf("QueryType = %q, want A", cfg.QueryType)
|
||||
}
|
||||
if cfg.MaxDepth != 20 {
|
||||
t.Errorf("MaxDepth = %d, want 20", cfg.MaxDepth)
|
||||
}
|
||||
if cfg.Retries != 2 {
|
||||
t.Errorf("Retries = %d, want 2", cfg.Retries)
|
||||
}
|
||||
cfg := DefaultConfig()
|
||||
if cfg.QueryType != "a" {
|
||||
t.Errorf("QueryType = %q, want a", cfg.QueryType)
|
||||
}
|
||||
if cfg.ShowResolves || cfg.ShowServers || cfg.ShowAllStats {
|
||||
t.Error("show-resolves/show-servers/show-all-stats must default to false")
|
||||
}
|
||||
if !cfg.ShowProgress || !cfg.ShowVersions || !cfg.ShowResults || !cfg.ShowSummaryResults {
|
||||
t.Error("show-progress/show-versions/show-results/show-summary-results must default to true")
|
||||
}
|
||||
if cfg.MaxDepth != 20 {
|
||||
t.Errorf("MaxDepth = %d, want 20", cfg.MaxDepth)
|
||||
}
|
||||
if cfg.Retries != 2 {
|
||||
t.Errorf("Retries = %d, want 2", cfg.Retries)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user