Skip to content

refactor(doctor): introduce RunOptions and extract CheckVariables helpers - #847

Open
marcusburghardt wants to merge 1 commit into
complytime:mainfrom
marcusburghardt:chore/doctor-refactor-runoptions-checkvariables
Open

refactor(doctor): introduce RunOptions and extract CheckVariables helpers#847
marcusburghardt wants to merge 1 commit into
complytime:mainfrom
marcusburghardt:chore/doctor-refactor-runoptions-checkvariables

Conversation

@marcusburghardt

Copy link
Copy Markdown
Member

Summary

Addresses #765 items 2, 3, and 4 (structural tech debt in doctor command).

Item 3: Run() has 8 parameters (Architect MEDIUM)

Replace the 9-parameter Run() signature with a RunOptions struct per
AP-001 (Options struct pattern). The old signature exceeded the 99-character
line limit; the new signature is Run(opts RunOptions) []CheckResult.

Item 2: CheckVariables complexity 38 (Architect MEDIUM)

Extract four focused helpers from CheckVariables (was ~250 lines, CRAP Q4):

Helper Responsibility Lines
resolveEvaluatorTargets() Maps policy refs to evaluator IDs via dependency graph ~65
validateProviderVariables() Validates one provider's vars against config ~75
buildVariableSummary() Constructs pass/fail summary result ~40
buildVariableDetails() Generates verbose per-key status lines ~55

CheckVariables is now a ~35-line orchestrator that delegates to these helpers.

Item 4: printDiagnostics writes to stdout (Architect LOW)

Already addressed by existing printDiagnosticsTo(w io.Writer) at
cmd/complyctl/cli/doctor.go:388. No changes needed.

Changes

  • internal/doctor/doctor.go: RunOptions struct, Run() signature
    change, four extracted helpers from CheckVariables
  • cmd/complyctl/cli/doctor.go: Updated runDoctor caller to construct
    RunOptions struct

Verification

  • make test-unit -- all existing tests pass without modification
    (behavioral equivalence confirmed)
  • make lint -- zero issues

Ref #765

…pers

Replace the 9-parameter Run() signature with a RunOptions struct per
AP-001 (Options struct pattern). This improves readability at the call
site and makes the function extensible without signature changes.

Extract three helpers from CheckVariables (complexity 38, CRAP Q4):

- resolveEvaluatorTargets(): maps policy references to evaluator IDs
  via the dependency graph, collecting resolution failures and
  diagnostic results (~65 lines)

- validateProviderVariables(): validates one provider's global and
  target variables against workspace config, producing a summary
  CheckResult with optional verbose detail (~75 lines)

- buildVariableSummary(): constructs the pass/fail summary result
  for a single provider's variable validation (~40 lines)

- buildVariableDetails(): generates verbose per-key status lines
  for a provider's variables (~55 lines)

CheckVariables is now a ~35-line orchestrator that delegates to these
focused helpers. All existing tests pass without modification,
confirming behavioral equivalence.

Item 4 (printDiagnostics writes to stdout) is already addressed by
existing printDiagnosticsTo(w io.Writer) — no changes needed.

Ref complytime#765

Assisted-by: OpenCode (claude-opus-4-6)
Signed-off-by: Marcus Burghardt <maburgha@redhat.com>
@marcusburghardt
marcusburghardt requested a review from a team as a code owner September 8, 2026 07:36
@marcusburghardt marcusburghardt added the enhancement New feature or request label Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants