Skip to content

Commit 5b4c1c4

Browse files
TMHSDigitalclaude
andcommitted
MCP: keep no inconclusive-name list it never reads (#349)
subenum mcp scans through pkg/subenum, which always keeps the list of names without an answer for Stats.Inconclusive, but the MCP report never reads it. scan.WithoutInconclusiveList marks a context; pkg/subenum's Run then turns ListInconclusive off. The marker lives in an internal package, so the library's public API does not change. runMCPScan passes a marked context. TestInconclusiveListOff checks that a library scan lists the names by default and keeps none under the marker. Fixes #349 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 416499e commit 5b4c1c4

4 files changed

Lines changed: 46 additions & 1 deletion

File tree

‎internal/cli/mcp_report.go‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/TMHSDigital/subenum/internal/dns"
1010
"github.com/TMHSDigital/subenum/internal/mcp"
11+
"github.com/TMHSDigital/subenum/internal/scan"
1112
"github.com/TMHSDigital/subenum/pkg/subenum"
1213
)
1314

@@ -62,7 +63,8 @@ type mcpOutcomes struct {
6263
func runMCPScan(ctx context.Context, cfg subenum.Config, offset int) *mcpReport {
6364
report := &mcpReport{Domain: cfg.Domain, Results: []mcpResult{}, MaxQueries: cfg.MaxQueries, Rate: cfg.Rate}
6465
cfg.Logf = func(string, ...any) {} // standard output carries the protocol
65-
events, err := subenum.Run(ctx, cfg)
66+
// The report never lists inconclusive names, so the scan keeps none (#349).
67+
events, err := subenum.Run(scan.WithoutInconclusiveList(ctx), cfg)
6668
if err != nil {
6769
report.Verdict, report.Reason, report.Error = verdictNotRun, "the scan did not start; see error", err.Error()
6870
return report

‎internal/scan/options.go‎

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

33
import (
4+
"context"
45
"fmt"
56
"time"
67

@@ -66,6 +67,23 @@ type Options struct {
6667
Logf dns.Logf
6768
}
6869

70+
type noInconclusiveListKey struct{}
71+
72+
// WithoutInconclusiveList marks ctx for a pkg/subenum scan whose caller
73+
// never reads Stats.Inconclusive (subenum mcp), so the library does not keep
74+
// the list, as the CLI does not without -inconclusive (#300, #349). It is not
75+
// part of the library's API.
76+
func WithoutInconclusiveList(ctx context.Context) context.Context {
77+
return context.WithValue(ctx, noInconclusiveListKey{}, true)
78+
}
79+
80+
// InconclusiveListOff reports whether ctx was marked by
81+
// WithoutInconclusiveList.
82+
func InconclusiveListOff(ctx context.Context) bool {
83+
off, _ := ctx.Value(noInconclusiveListKey{}).(bool)
84+
return off
85+
}
86+
6987
// Validate checks the numeric ranges and the resolver address. Messages name
7088
// each setting as a {token} that the front end renders (#100). The resolver is
7189
// not checked in simulation mode, which sends no DNS traffic.

‎pkg/subenum/subenum.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,9 @@ func Run(ctx context.Context, cfg Config) (<-chan Event, error) {
476476
if err != nil {
477477
return nil, err
478478
}
479+
if scan.InconclusiveListOff(ctx) {
480+
internal.ListInconclusive = false // subenum mcp never reads it (#349)
481+
}
479482
out := make(chan Event, 64)
480483
go func() {
481484
defer close(out)

‎pkg/subenum/subenum_test.go‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"golang.org/x/net/dns/dnsmessage"
1414

1515
"github.com/TMHSDigital/subenum/internal/dnstest"
16+
"github.com/TMHSDigital/subenum/internal/scan"
1617
"github.com/TMHSDigital/subenum/pkg/subenum"
1718
)
1819

@@ -475,6 +476,27 @@ func TestMaxDuration(t *testing.T) {
475476
// TestNoAbortScanSucceedsDespiteFailingLookups covers #149: under NoAbort
476477
// the reliability guard only warns, so a completed Scan returns no error,
477478
// while Run still reports the warning.
479+
// TestInconclusiveListOff covers #349: Stats.Inconclusive lists the names
480+
// without an answer, except for a context subenum mcp marks, which keeps none.
481+
func TestInconclusiveListOff(t *testing.T) {
482+
srv := dnstest.Start(t, func(q dnstest.Query) dnstest.Reply {
483+
if strings.HasPrefix(q.Name, "bad") {
484+
return dnstest.Refused
485+
}
486+
return dnstest.NXDomain
487+
})
488+
cfg := subenum.Config{Domain: "lab.example", Words: []string{"bad1", "ok", "bad2"}, Resolver: srv.Addr,
489+
Timeout: 10 * time.Second, Attempts: 1}
490+
_, stats, err := subenum.Scan(context.Background(), cfg)
491+
if err != nil || len(stats.Inconclusive) != 2 {
492+
t.Fatalf("Scan: err %v, inconclusive %q; want the two refused names", err, stats.Inconclusive)
493+
}
494+
_, stats, err = subenum.Scan(scan.WithoutInconclusiveList(context.Background()), cfg)
495+
if err != nil || stats.Inconclusive != nil || stats.Refused != 2 {
496+
t.Errorf("marked Scan: err %v, inconclusive %q, refused %d; want no list and the two refusals counted", err, stats.Inconclusive, stats.Refused)
497+
}
498+
}
499+
478500
func TestNoAbortScanSucceedsDespiteFailingLookups(t *testing.T) {
479501
srv := dnstest.Start(t, func(q dnstest.Query) dnstest.Reply {
480502
if strings.HasPrefix(q.Name, "bad-") {

0 commit comments

Comments
 (0)