Skip to content

Unify result, stats and event types across scan, output, pkg/subenum and TUI #162

Closed

Description

@TMHSDigital

Summary

Results, stats and events exist in three vocabularies (scan, output, pkg/subenum) plus six TUI message types, connected by hand-written field-by-field translators with no completeness check. Small helpers are also duplicated across packages.

Where

  • internal/scan/runner.go:384-400 (Event), :79-103 (Stats), :356-366 (NoticeKind), :149-166 (snapshot)
  • pkg/subenum/subenum.go:138-304 (Record/Result/Stats/Kind/Notice/Event), :584-657 (translate, stats)
  • internal/output/writer.go:53-64 (output.Result), :151-160 (Result and ResultWithHint beside Emit)
  • internal/tui/scan_view.go:260-275, internal/tui/model.go:354-379 (six message types)
  • main.go:757-779 (scan.Event -> output.Result), main_resume.go:255-276 (mergeStats), internal/report/report.go:80-92
  • Duplicated helpers: internal/scan/runner.go:208 vs internal/dns/resolver.go:458 (record key); internal/scan/scope.go:73-78 vs internal/scan/runner.go:270-273 (parentOf); internal/validate/validate.go:37 vs internal/wordlist/reader.go:16 (label regex)

Details

scan.Stats has 17 fields copied by hand into subenum.Stats, mergeStats, and the report. Takeover (#71), Permutation (#72) and Change (#84) each had to be added in three or four places. A dropped field is silent.

Why it hurts now

Any new per-result datum (TTL, answering resolver) requires editing scan.Event, output.Result, subenum.Result, translate, resultMsg, emitResult and the writers.

Suggested plan (each step leaves the tree green)

  1. Add reflection tests asserting subenum.Stats and scan.Stats share the same exported numeric field set and that mergeStats and translate cover every field (cheap drift guard, no behaviour change).
  2. Define scan.Result{Name, Records, Takeover} inside scan.Event; have output.Result embed it.
  3. Collapse the TUI messages into one eventMsg{scan.Event} and switch on Kind in scanViewModel.Update.
  4. Remove Writer.Result/ResultWithHint in favour of Emit (TUI is the only ResultWithHint caller, model.go:258).
  5. Export dns.RecordKey; use parentOf in isWildcardAnswer; share the label regex.

Tests to have first

  • pkg/subenum/subenum_test.go, internal/tui/scan_view_test.go, internal/output/writer_test.go

Acceptance criteria

  • A test fails when a Stats field is added without updating the copies
  • One result struct flows from engine to writers

Getting started

  • Relevant files: see "Where"
  • How to run tests: go test ./...
  • Related docs: docs/library.md, docs/ARCHITECTURE.md

Filed by repo-audit/full-audit at 3139c44. Severity: medium. Effort: M. audit-key: tech-debt|pkg/subenum/subenum.go|translate

Activity

  1. added
    tech-debt
    severity: medium
    on Nov 9, 2026
  2. TMHSDigital commented on Nov 10, 2026

    @TMHSDigital
    OwnerAuthor

    Fixed in 2131669: one result struct now goes from the engine to the writers, and drift guards cover every scan.Stats copy.

    • scan.Result (subdomain, records, simulated, takeover) is carried as scan.Event.Result and embedded in output.Result, which adds only Change, PreviousRecords and Permutation. Because the embedded fields come first, JSON/JSONL/CSV/SARIF output does not change. A new test pins the JSON field order.
    • The TUI's six event message types are now one eventMsg{scan.Event}, and the scan view switches on Kind.
    • Writer.Result and Writer.ResultWithHint are removed; callers use Emit. dns.RecordKey replaces the duplicated key helper.
    • Reflection tests fail when a scan.Stats field is added without updating pkg/subenum's stats(), mergeStats, or the run-quality report. The mergeStats guard found a real drop: a resumed run lost Expired, so a resume that hit -max-duration reported stopped_by: "queries". mergeStats now merges Expired.

    The public pkg/subenum API is unchanged.

    Deliberately not done:

    Verified with go build, go vet, go test -race -shuffle=on ./... and golangci-lint run (0 issues).

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

    severity: mediumtech-debt

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions