Skip to content

One table for setting tokens, flag names, config fields and TUI labels #160

Closed

Description

@TMHSDigital

Summary

Adding one engine setting touches about 12 files and 6 hand-maintained name tables (CLI flags, scan.Options, scan.Config, subenum.Config, TUI form fields, saved TUI config, settings tokens, completion metadata). Only one of these drifts is guarded by a test.

Where

  • main.go:117-160 (cliFlags), main.go:174-211 (flag defs), main.go:1067-1093 (scanOptions)
  • internal/scan/options.go:14-38, :69-95 (Options -> Config 20-field copy)
  • internal/scan/settings.go:15-32, :55-67 (Setting consts, FlagName)
  • pkg/subenum/subenum.go:46-136 (Config), :480-500, :564-575 (configFields)
  • internal/tui/form.go:24-44, :60-79, :442-529 (formValues, settingLabel)
  • internal/tui/config.go:11-30, :110-152 (savedConfig, withSettings 17-case switch)
  • main_resume.go:110 (unsavedSettings), main_completion.go:20-33 (fileFlags, valueChoices)

Details

Grep for max-queries|MaxQueries|max_queries in non-test Go hits 10 files. withSettings is a switch on CLI flag strings that duplicates the flag table; FlagName, settingLabel and configFields are three more copies of the same mapping. withSettings silently ignores any flag not in its switch, so a SUBENUM_* default for a new flag never reaches the TUI and no test fails. The last two refactor commits (57d9258, 2edfd89) were exactly this kind of synchronisation.

Why it hurts now

A new engine knob needs roughly 15 edits across three front ends, and most omissions are silent.

Suggested plan (each step leaves the tree green)

  1. Add one table in internal/scan/settings.go: type settingInfo struct{ Setting; Flag, Field, Label string }; derive FlagName, configFields, settingLabel from it and delete the three maps. Test: every Settings entry has all three names.
  2. Make scan.Options.Config() a trivial copy (only TimeoutMs translated) or embed Config to remove the 20-field copy.
  3. Replace the withSettings switch with a loop over the table keyed by Flag, plus a test asserting every flag from parseFlags(nil) not in the output-only set is handled.
  4. Derive fileFlags/valueChoices from flag metadata or assert coverage in main_completion tests.

Tests to have first

  • TestSettingLabelsCoverEverySetting (form_test.go:233), TestCLIBuildsSharedConfig (main_test.go:218), TestFormBuildsSharedConfig (form_test.go:189), TestDefaultsMatchTheCLI (pkg)

Acceptance criteria

  • One source of truth for setting token, flag name, config field and label
  • A test fails when a flag is added without wiring it to the TUI config layer

Getting started

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

Related: #80, #136


Filed by repo-audit/full-audit at 3139c44. Severity: medium. Effort: M. audit-key: tech-debt|internal/scan/settings.go|Setting

Activity

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

    @TMHSDigital
    OwnerAuthor

    Fixed in eb0193f.

    internal/scan/settings.go now has one table that gives each engine setting its flag (which is also the config file key and the SUBENUM_* suffix), its pkg/subenum Config field and its TUI label. FlagName, FieldName, Label and Settings all come from that table. The configFields map, settingsWithoutField and the FlagName switch have been removed. TUI form fields that have a setting take their label and flag from the table. Each field points at its savedConfig slot, so withSettings is now a loop over formFields instead of the 17-case switch.

    New tests:

    • TestSettingTable checks that every setting has a unique flag, field and label.
    • TestSettingNamesAgreeAcrossFrontEnds (main) checks that every CLI flag is either wired into the TUI or listed in tuiOmittedFlags, that every flag the TUI reads exists, and that every setting's flag is real.
    • TestWithSettingsSeedsEveryFlaggedField checks that each flag seeds its own form field and no other.

    Flag names, config keys, messages and TUI labels did not change. The existing docs, config and form-row tests pass without edits.

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

    Not done here: steps 2 (the Options-to-Config copy) and 4 (completion metadata). Neither is part of the acceptance criteria.

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

    area: cliarea: tuiseverity: mediumtech-debt

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions