Skip to content

refactor(doctor): extract groupSatisfied helper to deduplicate pipe-split logic in CheckVariables #779

Description

@yvonnedevlinrh

Summary

Extract a groupSatisfied helper in internal/doctor/doctor.go to eliminate duplicated pipe-splitting logic in CheckVariables().

Context

PR #778 introduced OptionalTargetVariableGroups support with a pipe-split-and-lookup pattern that appears three times in CheckVariables():

  1. Validation counting (line ~786): splits group on |, iterates members, checks target.Variables[m]
  2. Verbose detail for mapped targets (line ~893): identical split-iterate-check logic
  3. Verbose detail for unmapped targets (line ~871): iterates groups without split (same pattern surface)

The first two are structurally identical.

Proposed Change

Extract a shared helper:

func groupSatisfied(group string, vars map[string]string) bool {
	for _, m := range strings.Split(group, "|") {
		if _, ok := vars[m]; ok {
			return true
		}
	}
	return false
}
Replace the inline loops at all call sites with groupSatisfied(group, target.Variables).
Motivation
- DRY (Constitution I, CS-004): identical logic in multiple locations
- Low risk: pure refactoring within a single function, no signature or behavior changes
- Improves readability and reduces maintenance surface
Files
- internal/doctor/doctor.go
- internal/doctor/doctor_test.go (no changes expected; existing tests cover behavior)
References
- Identified during review of #778

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestllm_assistedFiled or drafted with LLM assistance

    Type

    No type

    Fields

    Priority

    Medium

    Effort

    None yet

    Projects

    Status
    In progress 📋

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions