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
+15
-34
@@ -111,47 +111,28 @@ func TestRootHintsKnownAddress(t *testing.T) {
|
||||
|
||||
func TestResolverFromConfigExplicit(t *testing.T) {
|
||||
cfg := &RootDiscoveryConfig{Resolver: "8.8.8.8:53"}
|
||||
got := resolverFromConfig(cfg)
|
||||
got, err := resolverFromConfig(cfg)
|
||||
if err != nil {
|
||||
t.Fatalf("resolverFromConfig: %v", err)
|
||||
}
|
||||
if got != "8.8.8.8:53" {
|
||||
t.Errorf("resolverFromConfig = %q, want 8.8.8.8:53", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolverFromConfigEmpty(t *testing.T) {
|
||||
cfg := &RootDiscoveryConfig{}
|
||||
got := resolverFromConfig(cfg)
|
||||
// Should return the system resolver; just check it's non-empty and contains a port.
|
||||
if got == "" {
|
||||
t.Error("resolverFromConfig with empty Resolver returned empty string")
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolverFromConfigNil(t *testing.T) {
|
||||
got := resolverFromConfig(nil)
|
||||
if got == "" {
|
||||
t.Error("resolverFromConfig(nil) returned empty string")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSystemResolverNonEmpty(t *testing.T) {
|
||||
got := systemResolver()
|
||||
if got == "" {
|
||||
t.Error("systemResolver() returned empty string")
|
||||
}
|
||||
// Must contain a colon (host:port format).
|
||||
host, port, err := splitHostPort(got)
|
||||
func TestSystemResolverNoHardcodedFallback(t *testing.T) {
|
||||
// Whether or not /etc/resolv.conf exists, systemResolver must never
|
||||
// invent 127.0.0.1:53: it returns a valid host:port from the system
|
||||
// configuration or an error.
|
||||
got, err := systemResolver()
|
||||
if err != nil {
|
||||
t.Errorf("systemResolver() = %q: not a valid host:port: %v", got, err)
|
||||
return
|
||||
}
|
||||
if host == "" {
|
||||
t.Errorf("systemResolver() host is empty in %q", got)
|
||||
host, port, err := net.SplitHostPort(got)
|
||||
if err != nil {
|
||||
t.Fatalf("systemResolver() = %q: not a valid host:port: %v", got, err)
|
||||
}
|
||||
if port == "" {
|
||||
t.Errorf("systemResolver() port is empty in %q", got)
|
||||
if host == "" || port == "" {
|
||||
t.Errorf("systemResolver() returned incomplete address %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
// splitHostPort is a thin wrapper around net.SplitHostPort for test use.
|
||||
func splitHostPort(addr string) (host, port string, err error) {
|
||||
return net.SplitHostPort(addr)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user