Skip to content

Scan options are built three times (CLI, TUI, pkg) and have drifted #262

Closed

Description

@TMHSDigital

Summary

Scan options are built by three separate hand-written literals (CLI, TUI and library). Some range checks sit outside the shared validator, the resolver pool is built three times, and defaults are duplicated. The front ends have already drifted: the TUI never sets AutoRate, RetryInconclusive, Deadline or TakeoverProviders, and nothing records whether that is intentional.

Where

  • Three scan.Options{...} builders: main.go:645-680 (scanOptions), internal/tui/form.go:486-506 (options), pkg/subenum/subenum.go:563-677 (Config.options)
  • Checks outside Options.Validate (internal/scan/options.go:50-73):
    • rate-per-resolver < 0: main.go:350, internal/tui/form.go:425, pkg/subenum/subenum.go:578
    • MaxDuration: main.go:346, pkg/subenum/subenum.go:582
  • Pool construction: main.go:378-403, internal/tui/model.go:180-197, pkg/subenum/subenum.go:658-671
  • Defaults: main.go:221-243; internal/tui/form.go:83-105 and :414; pkg/subenum/subenum.go:39-43
  • Stats copies: pkg/subenum/subenum.go:780-810 (stats), main_resume.go:291-321 (mergeStats)

Why it hurts now

Adding a scan setting means editing scan.Options, Options.Config, three builders, possibly three validators, and three copies of the defaults. Nothing fails if one is missed. -auto-rate already missed the TUI.

Plan (each step leaves the code green)

  1. Tests first:
    • a reflection test per front end that sets every input and asserts each scan.Options field is populated or listed in a per-front-end unmapped allowlist with a reason (pattern: pkg/subenum/stats_test.go:39-60);
    • table tests that pin today's error messages for a negative rate-per-resolver and max-duration.
  2. Add RatePerResolver to scan.Options, move both range checks into Validate with {token} messages, and delete the ad-hoc checks.
  3. Add one pool constructor (dns.NewPoolFromLines(lines, timeout, perRes)) and call it from all three sites.
  4. Add scan.DefaultConcurrency, DefaultTimeoutMs and DefaultHitRate. Have the CLI flag defaults, the TUI def: strings and the pkg Default* constants refer to them.
  5. Decide whether the TUI should expose AutoRate and RetryInconclusive (see the TUI parity issue), or record the gap in the allowlist.

Getting started

  • Relevant files: listed above
  • How to run tests: go test ./...
  • Related docs: docs/ARCHITECTURE.md

Related: #80, #160


Filed by repo-audit/full-audit at 3f671b2. Severity: medium. Effort: M. audit-key: tech-debt|internal/scan/options.go|Options-builders

Activity

  1. added
    help wanted
    tech-debt
    severity: medium
    on Nov 14, 2026
  2. TMHSDigital commented on Nov 14, 2026

    @TMHSDigital
    OwnerAuthor

    Fixed in 4b22c95, following the plan:

    1. Drift guards: TestScanOptionsSetsEveryField (CLI), TestOptionsSetsEveryField in internal/tui and in pkg/subenum. Each fails when a scan.Options field is left unset without a listed reason. Message pins: TestRangeErrorsNameFlags (CLI), TestRangeErrorsNameConfigFields (pkg), and the TUI's TestResolverPoolField.
    2. scan.Options has RatePerResolver and MaxDuration. Validate checks both, with a new {rate_per_resolver} setting, and the three ad-hoc checks are gone.
    3. dns.NewPoolFromLines(lines, timeout, perSecond) builds the pool at all three sites.
    4. scan.DefaultConcurrency, DefaultTimeoutMs and DefaultHitRate feed the CLI flags and the TUI form. pkg/subenum keeps its literal Default* constants, so godoc shows plain values like DefaultResolver, and TestDefaultsMatchTheCLI pins them to scan's.
    5. The TUI's unmapped list records AutoRate, RetryInconclusive, MaxDuration/Deadline as "no form field yet (TUI form lacks sources, max duration, auto rate, retry inconclusive, permute #274)", and the other gaps with their reasons.

    Verified with go test ./..., golangci-lint v2.15.0 and gofmt. The stats copies (stats, mergeStats) listed under Where weren't part of the plan and are unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedseverity: mediumtech-debt

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions