From dd7815c3c0f5736fc131bea46f21c0f203f6b8c4 Mon Sep 17 00:00:00 2001 From: ahmadalguydi Date: Fri, 31 Jul 2026 13:08:14 +0300 Subject: [PATCH] refactor: deduplicate optional variable checks --- internal/doctor/doctor.go | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/internal/doctor/doctor.go b/internal/doctor/doctor.go index 7cf96db40..874ad6eb3 100644 --- a/internal/doctor/doctor.go +++ b/internal/doctor/doctor.go @@ -783,16 +783,8 @@ func CheckVariables(cfg *complytime.WorkspaceConfig, healthData []ProviderHealth } } for _, group := range ph.OptionalTargetVariableGroups { - members := strings.Split(group, "|") targetTotal++ - found := false - for _, m := range members { - if _, ok := target.Variables[m]; ok { - found = true - break - } - } - if found { + if groupSatisfied(group, target.Variables) { targetResolved++ } else { missingTargetVars = append(missingTargetVars, @@ -891,13 +883,9 @@ func CheckVariables(cfg *complytime.WorkspaceConfig, healthData []ProviderHealth }) } for _, group := range ph.OptionalTargetVariableGroups { - members := strings.Split(group, "|") detailStatus := StatusFail - for _, m := range members { - if _, ok := target.Variables[m]; ok { - detailStatus = StatusPass - break - } + if groupSatisfied(group, target.Variables) { + detailStatus = StatusPass } details = append(details, CheckResult{ Name: fmt.Sprintf("variables/%s/detail", ph.EvaluatorID), @@ -1055,6 +1043,15 @@ func countResolved(required []string, vars map[string]string) (resolved, total i return resolved, total } +func groupSatisfied(group string, vars map[string]string) bool { + for _, member := range strings.Split(group, "|") { + if _, ok := vars[member]; ok { + return true + } + } + return false +} + func unmappedReason(resolver PolicyGraphResolver, resolveFailures int) string { if resolver == nil { return "no policy resolver available"