Skip to content

Commit 968ea34

Browse files
Add debug logging to workflow pkg files lacking coverage (#23492)
1 parent c583a0a commit 968ea34

5 files changed

Lines changed: 39 additions & 11 deletions

File tree

pkg/workflow/cache_integrity.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ import (
66
"fmt"
77
"sort"
88
"strings"
9+
10+
"github.com/github/gh-aw/pkg/logger"
911
)
1012

13+
var cacheIntegrityLog = logger.New("workflow:cache_integrity")
14+
1115
// integrityLevelOrder defines integrity levels from highest to lowest.
1216
// Used to determine which branches to merge down from when setting up cache.
1317
var integrityLevelOrder = []string{"merged", "approved", "unapproved", "none"}
@@ -27,12 +31,15 @@ const noPolicySentinel = "nopolicy"
2731
// - Workflows without policy → sentinel value "nopolicy" (consistent key format)
2832
func computePolicyHash(github *GitHubToolConfig) string {
2933
if github == nil || github.MinIntegrity == "" {
34+
cacheIntegrityLog.Print("No guard policy configured, using nopolicy sentinel")
3035
return noPolicySentinel
3136
}
3237

3338
canonical := buildCanonicalPolicy(github)
3439
hash := sha256.Sum256([]byte(canonical))
35-
return hex.EncodeToString(hash[:])[:8]
40+
result := hex.EncodeToString(hash[:])[:8]
41+
cacheIntegrityLog.Printf("Computed policy hash: %s (min-integrity=%s)", result, github.MinIntegrity)
42+
return result
3643
}
3744

3845
// buildCanonicalPolicy builds the normalized string representation of the allow-only policy.
@@ -183,16 +190,20 @@ func cacheIntegrityLevel(github *GitHubToolConfig) string {
183190
// memory-unapproved-7e4d9f12-${{ env.GH_AW_WORKFLOW_ID_SANITIZED }}-${{ github.run_id }}
184191
// memory-none-nopolicy-session-${{ env.GH_AW_WORKFLOW_ID_SANITIZED }}-${{ github.run_id }}
185192
func generateIntegrityAwareCacheKey(cacheID, integrityLevel, policyHash string) string {
193+
var key string
186194
if cacheID == "default" || cacheID == "" {
187-
return fmt.Sprintf(
195+
key = fmt.Sprintf(
188196
"memory-%s-%s-${{ env.GH_AW_WORKFLOW_ID_SANITIZED }}-${{ github.run_id }}",
189197
integrityLevel, policyHash,
190198
)
199+
} else {
200+
key = fmt.Sprintf(
201+
"memory-%s-%s-%s-${{ env.GH_AW_WORKFLOW_ID_SANITIZED }}-${{ github.run_id }}",
202+
integrityLevel, policyHash, cacheID,
203+
)
191204
}
192-
return fmt.Sprintf(
193-
"memory-%s-%s-%s-${{ env.GH_AW_WORKFLOW_ID_SANITIZED }}-${{ github.run_id }}",
194-
integrityLevel, policyHash, cacheID,
195-
)
205+
cacheIntegrityLog.Printf("Generated integrity-aware cache key: cacheID=%s, integrityLevel=%s, policyHash=%s", cacheID, integrityLevel, policyHash)
206+
return key
196207
}
197208

198209
// higherIntegrityLevels returns the integrity levels that are higher than the given level,
@@ -206,5 +217,6 @@ func higherIntegrityLevels(level string) []string {
206217
}
207218
result = append(result, l)
208219
}
220+
cacheIntegrityLog.Printf("Higher integrity levels than %q: %v", level, result)
209221
return result
210222
}

pkg/workflow/expression_nodes.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ func (d *DisjunctionNode) Render() string {
9898
return d.RenderMultiline()
9999
}
100100

101+
expressionNodesLog.Printf("Rendering inline disjunction with %d terms", len(d.Terms))
101102
var parts []string
102103
for _, term := range d.Terms {
103104
parts = append(parts, term.Render())

pkg/workflow/mcp_rendering.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ func renderStandardJSONMCPConfig(
118118
// The returned function accepts isLast as a parameter and creates a renderer with engine-specific
119119
// options derived from the provided parameters and workflowData at call time.
120120
func buildMCPRendererFactory(workflowData *WorkflowData, format string, includeCopilotFields, inlineArgs bool) func(bool) *MCPConfigRendererUnified {
121+
mcpRenderingLog.Printf("Building MCP renderer factory: format=%s, copilotFields=%t, inlineArgs=%t", format, includeCopilotFields, inlineArgs)
121122
return func(isLast bool) *MCPConfigRendererUnified {
122123
return NewMCPConfigRenderer(MCPRendererOptions{
123124
IncludeCopilotFields: includeCopilotFields,
@@ -147,6 +148,7 @@ func buildStandardJSONMCPRenderers(
147148
webFetchIncludeTools bool,
148149
renderCustom RenderCustomMCPToolConfigHandler,
149150
) MCPToolRenderers {
151+
mcpRenderingLog.Printf("Building standard JSON MCP renderers: webFetchIncludeTools=%t", webFetchIncludeTools)
150152
return MCPToolRenderers{
151153
RenderGitHub: func(yaml *strings.Builder, githubTool any, isLast bool, workflowData *WorkflowData) {
152154
createRenderer(isLast).RenderGitHubMCP(yaml, githubTool, workflowData)

pkg/workflow/safe_outputs_tools_computation.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
package workflow
22

3+
import "github.com/github/gh-aw/pkg/logger"
4+
5+
var safeOutputsToolsComputationLog = logger.New("workflow:safe_outputs_tools_computation")
6+
37
// computeEnabledToolNames returns the set of predefined tool names that are enabled
48
// by the workflow's SafeOutputsConfig. Dynamic tools (dispatch-workflow, custom jobs,
59
// call-workflow) are excluded because they are generated separately.
610
func computeEnabledToolNames(data *WorkflowData) map[string]bool {
711
enabledTools := make(map[string]bool)
812
if data.SafeOutputs == nil {
13+
safeOutputsToolsComputationLog.Print("No safe outputs configuration, returning empty tool set")
914
return enabledTools
1015
}
1116

@@ -126,5 +131,6 @@ func computeEnabledToolNames(data *WorkflowData) map[string]bool {
126131
enabledTools["push_repo_memory"] = true
127132
}
128133

134+
safeOutputsToolsComputationLog.Printf("Computed %d enabled safe output tool names", len(enabledTools))
129135
return enabledTools
130136
}

pkg/workflow/validation_helpers.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ import (
3333
"github.com/github/gh-aw/pkg/logger"
3434
)
3535

36+
var validationHelpersLog = logger.New("workflow:validation_helpers")
37+
3638
// newValidationLogger creates a standardized logger for a validation domain.
3739
// It follows the naming convention "workflow:<domain>_validation" used across
3840
// all *_validation.go files.
@@ -81,12 +83,15 @@ func validateIntRange(value, min, max int, fieldName string) error {
8183
func validateMountStringFormat(mount string) (source, dest, mode string, err error) {
8284
parts := strings.Split(mount, ":")
8385
if len(parts) != 3 {
86+
validationHelpersLog.Printf("Invalid mount format: %q (expected 3 colon-separated parts, got %d)", mount, len(parts))
8487
return "", "", "", errors.New("must follow 'source:destination:mode' format with exactly 3 colon-separated parts")
8588
}
8689
mode = parts[2]
8790
if mode != "ro" && mode != "rw" {
91+
validationHelpersLog.Printf("Invalid mount mode: %q in %q (must be 'ro' or 'rw')", mode, mount)
8892
return parts[0], parts[1], parts[2], fmt.Errorf("mode must be 'ro' or 'rw', got %q", mode)
8993
}
94+
validationHelpersLog.Printf("Valid mount: source=%s, dest=%s, mode=%s", parts[0], parts[1], mode)
9095
return parts[0], parts[1], parts[2], nil
9196
}
9297

@@ -131,18 +136,20 @@ func validateNoDuplicateIDs[T any](items []T, idFunc func(T) string, onDuplicate
131136
// - []any: "on: [push, <triggerName>]"
132137
// - map[string]any: "on:\n <triggerName>: ..."
133138
func containsTrigger(onSection any, triggerName string) bool {
139+
found := false
134140
switch on := onSection.(type) {
135141
case string:
136-
return on == triggerName
142+
found = on == triggerName
137143
case []any:
138144
for _, trigger := range on {
139145
if triggerStr, ok := trigger.(string); ok && triggerStr == triggerName {
140-
return true
146+
found = true
147+
break
141148
}
142149
}
143150
case map[string]any:
144-
_, ok := on[triggerName]
145-
return ok
151+
_, found = on[triggerName]
146152
}
147-
return false
153+
validationHelpersLog.Printf("containsTrigger: trigger=%s, found=%t", triggerName, found)
154+
return found
148155
}

0 commit comments

Comments
 (0)