Skip to content

Commit e73ce44

Browse files
authored
refactor: consolidate duplicate provider extraction and remove redundant engine overrides (#28745)
1 parent b6bdb84 commit e73ce44

20 files changed

Lines changed: 196 additions & 97 deletions

pkg/workflow/agentic_engine.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,10 @@ func (e *BaseEngine) GetSecretValidationStep(workflowData *WorkflowData) GitHubA
378378
}
379379

380380
// GetFirewallLogsCollectionStep returns an empty slice by default.
381-
// Engines that need to copy session or firewall state files before secret redaction should override this.
381+
// Firewall logs are written to a known location (/tmp/gh-aw/sandbox/firewall/logs/)
382+
// and do not require a separate collection step. The method is still called from
383+
// compiler_yaml_main_job.go to maintain a consistent interface; engines that need
384+
// to copy session or firewall state files before secret redaction should override it.
382385
func (e *BaseEngine) GetFirewallLogsCollectionStep(workflowData *WorkflowData) []GitHubActionStep {
383386
return []GitHubActionStep{}
384387
}

pkg/workflow/allowed_domains_sanitization_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
"testing"
1111

1212
"github.com/github/gh-aw/pkg/stringutil"
13-
1413
"github.com/github/gh-aw/pkg/testutil"
14+
"github.com/stretchr/testify/require"
1515
)
1616

1717
// extractQuotedCSV returns the comma-separated domain list embedded inside
@@ -492,7 +492,8 @@ func TestComputeAllowedDomainsForSanitization(t *testing.T) {
492492
}
493493

494494
// Call the function
495-
domainsStr := compiler.computeAllowedDomainsForSanitization(data)
495+
domainsStr, err := compiler.computeAllowedDomainsForSanitization(data)
496+
require.NoError(t, err, "computeAllowedDomainsForSanitization should not return an error for valid test data")
496497

497498
// Verify expected domains are present (substring match is fine here since domain names
498499
// in a CSV string that are exact entries won't appear as substrings of other entries

pkg/workflow/claude_engine.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -463,13 +463,6 @@ func (e *ClaudeEngine) GetLogParserScriptId() string {
463463
return "parse_claude_log"
464464
}
465465

466-
// GetFirewallLogsCollectionStep returns the step for collecting firewall logs (before secret redaction)
467-
// No longer needed since we know where the logs are in the sandbox folder structure
468-
func (e *ClaudeEngine) GetFirewallLogsCollectionStep(workflowData *WorkflowData) []GitHubActionStep {
469-
// Collection step removed - firewall logs are now at a known location
470-
return []GitHubActionStep{}
471-
}
472-
473466
// GetSquidLogsSteps returns the steps for uploading and parsing Squid logs (after secret redaction)
474467
func (e *ClaudeEngine) GetSquidLogsSteps(workflowData *WorkflowData) []GitHubActionStep {
475468
return defaultGetSquidLogsSteps(workflowData, claudeLog)

pkg/workflow/codex_engine.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -380,15 +380,6 @@ mkdir -p "$CODEX_HOME/logs"
380380
return steps
381381
}
382382

383-
// GetFirewallLogsCollectionStep returns the step for collecting firewall logs (before secret redaction).
384-
// This method is part of the firewall integration interface. It returns an empty slice because
385-
// firewall logs are written to a known location (/tmp/gh-aw/sandbox/firewall/logs/) and don't need
386-
// a separate collection step. The method is still called from compiler_yaml_main_job.go to maintain
387-
// consistent behavior with other engines that may need log collection steps.
388-
func (e *CodexEngine) GetFirewallLogsCollectionStep(workflowData *WorkflowData) []GitHubActionStep {
389-
return []GitHubActionStep{}
390-
}
391-
392383
// GetSquidLogsSteps returns the steps for uploading and parsing Squid logs (after secret redaction)
393384
func (e *CodexEngine) GetSquidLogsSteps(workflowData *WorkflowData) []GitHubActionStep {
394385
return defaultGetSquidLogsSteps(workflowData, codexEngineLog)

pkg/workflow/compile_config_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,10 @@ func TestSafeOutputsConfigGeneration(t *testing.T) {
198198

199199
// Use the compiler's generateOutputCollectionStep to verify config is not in env vars
200200
var yamlBuilder strings.Builder
201-
compiler.generateOutputCollectionStep(&yamlBuilder, workflowData)
201+
err := compiler.generateOutputCollectionStep(&yamlBuilder, workflowData)
202+
if err != nil {
203+
t.Fatalf("generateOutputCollectionStep returned unexpected error: %v", err)
204+
}
202205
generatedYAML := yamlBuilder.String()
203206

204207
// Config should NOT be in environment variables anymore - it's in a file

pkg/workflow/compiler_activation_job_builder.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,17 @@ func (c *Compiler) addActivationRepositoryAndOutputSteps(ctx *activationJobBuild
238238
ctx.steps = append(ctx.steps, fmt.Sprintf(" uses: %s\n", getCachedActionPin("actions/github-script", data)))
239239
var domainsStr string
240240
if data.SafeOutputs != nil && len(data.SafeOutputs.AllowedDomains) > 0 {
241-
domainsStr = c.computeExpandedAllowedDomainsForSanitization(data)
241+
expanded, err := c.computeExpandedAllowedDomainsForSanitization(data)
242+
if err != nil {
243+
return err
244+
}
245+
domainsStr = expanded
242246
} else {
243-
domainsStr = c.computeAllowedDomainsForSanitization(data)
247+
computed, err := c.computeAllowedDomainsForSanitization(data)
248+
if err != nil {
249+
return err
250+
}
251+
domainsStr = computed
244252
}
245253
var envLines []string
246254
if len(data.Bots) > 0 {

pkg/workflow/compiler_safe_outputs_job.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,10 @@ func (c *Compiler) buildConsolidatedSafeOutputsJob(data *WorkflowData, mainJobNa
201201
// Critical for workflows that create projects and then add issues/PRs to those projects
202202
if hasHandlerManagerTypes {
203203
consolidatedSafeOutputsJobLog.Print("Using handler manager for safe outputs")
204-
handlerManagerSteps := c.buildHandlerManagerStep(data)
204+
handlerManagerSteps, err := c.buildHandlerManagerStep(data)
205+
if err != nil {
206+
return nil, nil, err
207+
}
205208
steps = append(steps, handlerManagerSteps...)
206209
safeOutputStepNames = append(safeOutputStepNames, "process_safe_outputs")
207210

pkg/workflow/compiler_safe_outputs_steps.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func (c *Compiler) buildSharedPRCheckoutSteps(data *WorkflowData) []string {
142142
// buildHandlerManagerStep builds a single step that uses the safe output handler manager
143143
// to dispatch messages to appropriate handlers. This replaces multiple individual steps
144144
// with a single dispatcher step that processes all safe output types.
145-
func (c *Compiler) buildHandlerManagerStep(data *WorkflowData) []string {
145+
func (c *Compiler) buildHandlerManagerStep(data *WorkflowData) ([]string, error) {
146146
consolidatedSafeOutputsStepsLog.Print("Building handler manager step")
147147

148148
var steps []string
@@ -162,9 +162,17 @@ func (c *Compiler) buildHandlerManagerStep(data *WorkflowData) []string {
162162
var domainsStr string
163163
if data.SafeOutputs != nil && len(data.SafeOutputs.AllowedDomains) > 0 {
164164
// allowed-domains: additional domains unioned with engine/network base set; supports ecosystem identifiers
165-
domainsStr = c.computeExpandedAllowedDomainsForSanitization(data)
165+
expanded, err := c.computeExpandedAllowedDomainsForSanitization(data)
166+
if err != nil {
167+
return nil, err
168+
}
169+
domainsStr = expanded
166170
} else {
167-
domainsStr = c.computeAllowedDomainsForSanitization(data)
171+
computed, err := c.computeAllowedDomainsForSanitization(data)
172+
if err != nil {
173+
return nil, err
174+
}
175+
domainsStr = computed
168176
}
169177
if domainsStr != "" {
170178
steps = append(steps, fmt.Sprintf(" GH_AW_ALLOWED_DOMAINS: %q\n", domainsStr))
@@ -332,5 +340,5 @@ func (c *Compiler) buildHandlerManagerStep(data *WorkflowData) []string {
332340
steps = append(steps, " const { main } = require('"+SetupActionDestination+"/safe_output_handler_manager.cjs');\n")
333341
steps = append(steps, " await main();\n")
334342

335-
return steps
343+
return steps, nil
336344
}

pkg/workflow/compiler_safe_outputs_steps_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,8 @@ func TestBuildHandlerManagerStep(t *testing.T) {
479479
ParsedFrontmatter: tt.parsedFrontmatter,
480480
}
481481

482-
steps := compiler.buildHandlerManagerStep(workflowData)
482+
steps, err := compiler.buildHandlerManagerStep(workflowData)
483+
require.NoError(t, err)
483484

484485
require.NotEmpty(t, steps)
485486

pkg/workflow/compiler_yaml.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ func (c *Compiler) generateCreateAwInfo(yaml *strings.Builder, data *WorkflowDat
830830
yaml.WriteString(" await main(core, context);\n")
831831
}
832832

833-
func (c *Compiler) generateOutputCollectionStep(yaml *strings.Builder, data *WorkflowData) {
833+
func (c *Compiler) generateOutputCollectionStep(yaml *strings.Builder, data *WorkflowData) error {
834834
// Copy the raw safe-output NDJSON to a /tmp/gh-aw/ path so it can be included in the
835835
// unified agent artifact together with all other /tmp/gh-aw/ outputs.
836836
yaml.WriteString(" - name: Copy Safe Outputs\n")
@@ -857,10 +857,18 @@ func (c *Compiler) generateOutputCollectionStep(yaml *strings.Builder, data *Wor
857857
var domainsStr string
858858
if data.SafeOutputs != nil && len(data.SafeOutputs.AllowedDomains) > 0 {
859859
// allowed-domains: additional domains unioned with engine/network base set; supports ecosystem identifiers
860-
domainsStr = c.computeExpandedAllowedDomainsForSanitization(data)
860+
expanded, err := c.computeExpandedAllowedDomainsForSanitization(data)
861+
if err != nil {
862+
return err
863+
}
864+
domainsStr = expanded
861865
} else {
862866
// Fall back to computing from network configuration (same as firewall)
863-
domainsStr = c.computeAllowedDomainsForSanitization(data)
867+
computed, err := c.computeAllowedDomainsForSanitization(data)
868+
if err != nil {
869+
return err
870+
}
871+
domainsStr = computed
864872
}
865873
if domainsStr != "" {
866874
fmt.Fprintf(yaml, " GH_AW_ALLOWED_DOMAINS: %q\n", domainsStr)
@@ -892,6 +900,7 @@ func (c *Compiler) generateOutputCollectionStep(yaml *strings.Builder, data *Wor
892900
yaml.WriteString(" const { main } = require('${{ runner.temp }}/gh-aw/actions/collect_ndjson_output.cjs');\n")
893901
yaml.WriteString(" await main();\n")
894902

903+
return nil
895904
}
896905

897906
// processMarkdownBody applies the standard post-processing pipeline to a markdown body:

0 commit comments

Comments
 (0)