Skip to content

Commit 1e14409

Browse files
TMHSDigitalclaude
andcommitted
fix(diff): count names left unchecked by an interrupt as unverified (#151)
When -diff re-verification was interrupted, Verify left the names it never dispatched out of its result, and emitRemoved read the missing key as the zero Outcome, OutcomeFound, reporting them as still resolving. Verify now records OutcomeCanceled for undispatched names, and emitRemoved treats an absent entry as unverified. Fixes #151 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LpkeXSPwrzd7ZCuX3no7gD
1 parent b79b6cd commit 1e14409

3 files changed

Lines changed: 50 additions & 6 deletions

File tree

‎internal/scan/verify.go‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,27 @@ func Verify(ctx context.Context, cfg Config, names []string) (map[string]dns.Out
7373
}
7474
})
7575
}
76-
feed:
77-
for _, name := range names {
76+
var undispatched []string
77+
for i, name := range names {
7878
if sc.excluded(name) {
7979
continue
8080
}
8181
select {
8282
case work <- name:
83+
continue
8384
case <-ctx.Done():
84-
break feed
8585
}
86+
undispatched = names[i:]
87+
break
8688
}
8789
close(work)
8890
wg.Wait()
91+
// Names never handed to a worker were cancelled too; without an entry a
92+
// caller would read the zero value, OutcomeFound (#151).
93+
for _, name := range undispatched {
94+
if !sc.excluded(name) {
95+
out[name] = dns.OutcomeCanceled
96+
}
97+
}
8998
return out, sent.Load()
9099
}

‎internal/scan/verify_test.go‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package scan
22

33
import (
44
"context"
5+
"fmt"
56
"testing"
67

78
"github.com/TMHSDigital/subenum/internal/dns"
@@ -42,3 +43,34 @@ func TestVerify(t *testing.T) {
4243
}
4344
}
4445
}
46+
47+
// TestVerifyCancelledMidwayReportsEveryName covers #151: names never handed
48+
// to a worker are reported cancelled, not left out (which reads as found).
49+
func TestVerifyCancelledMidwayReportsEveryName(t *testing.T) {
50+
ctx, cancel := context.WithCancel(context.Background())
51+
defer cancel()
52+
cfg := Config{
53+
Concurrency: 1,
54+
Exclude: []string{"skip.example.com"},
55+
resolveHook: func(context.Context, string) ([]dns.Record, dns.Outcome) {
56+
cancel()
57+
return nil, dns.OutcomeNXDomain
58+
},
59+
}
60+
names := []string{"skip.example.com"}
61+
for i := range 50 {
62+
names = append(names, fmt.Sprintf("n%d.example.com", i))
63+
}
64+
got, _ := Verify(ctx, cfg, names)
65+
if len(got) != len(names)-1 {
66+
t.Fatalf("got %d outcomes, want %d (every name but the excluded one)", len(got), len(names)-1)
67+
}
68+
if _, ok := got["skip.example.com"]; ok {
69+
t.Error("the excluded name has an outcome")
70+
}
71+
for name, o := range got {
72+
if o == dns.OutcomeFound {
73+
t.Errorf("%s reported found after cancellation", name)
74+
}
75+
}
76+
}

‎main_diff.go‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,14 @@ func emitRemoved(ctx context.Context, d *differ, targets []string, f cliFlags, m
151151
cfg.Pool = nil // the trusted resolver decides
152152
outcomes, sent := scan.Verify(ctx, cfg, missing)
153153
for _, name := range missing {
154-
switch outcomes[name] {
155-
case dns.OutcomeNXDomain:
154+
outcome, checked := outcomes[name]
155+
switch {
156+
case !checked:
157+
diffSummary.Unverified++ // never looked up; not a found name (#151)
158+
case outcome == dns.OutcomeNXDomain:
156159
d.removed++
157160
out.Emit(output.Result{Subdomain: name, Records: []dns.Record{}, Change: "removed"})
158-
case dns.OutcomeFound:
161+
case outcome == dns.OutcomeFound:
159162
diffSummary.StillResolving++
160163
default:
161164
diffSummary.Unverified++

0 commit comments

Comments
 (0)