Skip to content

refactor: decompose 203-line generatePostAgentCollectionAndUpload into focused helpers #29679

@github-actions

Description

@github-actions

Problem

pkg/workflow/compiler_yaml_main_job.go:538–741 contains a single 203-line function generatePostAgentCollectionAndUpload that handles at least 8 distinct responsibilities:

  1. Engine output file collection and cleanup
  2. MCP logs path collection
  3. DIFC proxy log path collection
  4. MCPScripts log path collection
  5. Log parsing for GITHUB_STEP_SUMMARY (multiple engines: main, MCP scripts, MCP gateway)
  6. Firewall log parsing
  7. Token usage summary generation
  8. AWF reflect summary generation
  9. Agent drain output collection
  10. Unified artifact upload

This violates the Single Responsibility Principle and creates maintenance challenges:

  • New post-agent features are appended inline, growing the function further
  • Unit testing individual collection or parsing steps is not possible without invoking the entire function
  • The function signature requires all output paths to be passed in (artifactPaths []string), forcing accumulation across unrelated concerns

Location

pkg/workflow/compiler_yaml_main_job.go, function generatePostAgentCollectionAndUpload, lines 538–741 (203 lines)

Recommended Refactoring

Extract cohesive groups into descriptively named helpers:

// collectArtifactPaths gathers all paths for the unified artifact upload.
func (c *Compiler) collectArtifactPaths(data *WorkflowData, engine CodingAgentEngine) []string

// generateSummarySteps emits all GITHUB_STEP_SUMMARY log-parsing steps.
func (c *Compiler) generateSummarySteps(yaml *strings.Builder, data *WorkflowData, engine CodingAgentEngine)

// generatePostAgentCollectionAndUpload orchestrates the above.
func (c *Compiler) generatePostAgentCollectionAndUpload(...) error {
    artifactPaths = c.collectArtifactPaths(data, engine)
    c.generateSummarySteps(yaml, data, engine)
    c.generateArtifactUpload(yaml, data, artifactPaths, checkoutMgr)
    return nil
}

Impact

  • Severity: Medium (maintainability)
  • Risk: High change frequency — new post-agent features are regularly added here
  • Testing: Current structure makes regression testing difficult; refactoring enables per-helper tests

Validation

  • All existing compilation tests pass after refactoring
  • Golden-file/snapshot tests (if any) updated
  • No behavioral change — refactoring only

Estimated Effort: Medium


Generated by Sergo · Run §25243999835

Generated by Sergo - Serena Go Expert · ● 767.1K ·

  • expires on May 9, 2026, 4:56 AM UTC

Metadata

Metadata

Labels

cookieIssue Monster Loves Cookies!sergo

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions