Skip to content

[Code Quality] Extract helper functions in compiler_yaml.go to reduce generateCreateAwInfo() complexity #13208

@github-actions

Description

@github-actions

Description

The generateCreateAwInfo() function in pkg/workflow/compiler_yaml.go is 155 lines long, making it difficult to maintain and test. The function builds the aw_info.json structure used in workflows.

Current State

  • File: pkg/workflow/compiler_yaml.go (lines 348-502)
  • Function length: 155 lines
  • Related long function: generatePrompt() at 91 lines (lines 231-322)
  • Test-to-source ratio: 1.89:1 (excellent!)

Suggested Changes

Extract helper functions for distinct concerns within generateCreateAwInfo():

  1. buildEngineInfo() (~50 lines)

    • Extract engine configuration building logic
    • Returns engine metadata and configuration
  2. buildNetworkInfo() (~30 lines)

    • Extract network configuration assembly
    • Returns network permissions and allowed domains
  3. buildRunMetadata() (~40 lines)

    • Extract metadata collection (workflow ID, run ID, actor, etc.)
    • Returns structured metadata map

Also refactor generatePrompt():

  • Extract imported markdown processing logic
  • Extract runtime-import macro creation

Benefits

  • Clearer separation of concerns: Each helper has a single responsibility
  • Easier testing: Test engine config, network config, and metadata independently
  • Better maintainability: Smaller, focused functions
  • Preserved test coverage: Maintain excellent 1.89:1 test-to-source ratio

Files Affected

  • pkg/workflow/compiler_yaml.go (main refactoring)
  • pkg/workflow/compiler_yaml_test.go (add tests for new helpers)

Success Criteria

  • generateCreateAwInfo() reduced to < 80 lines (orchestration only)
  • generatePrompt() reduced to < 60 lines
  • ✅ New helper functions are 30-50 lines each
  • ✅ All existing tests pass (1,113 test lines)
  • ✅ Test coverage maintained at > 1.5:1 ratio
  • ✅ No change in YAML generation output

Source

Extracted from Daily Compiler Code Quality Report - 2026-02-02

Immediate Actions (High Priority)

Issue: generateCreateAwInfo() is 155 lines
Focus areas: Engine configuration (50 lines), Network config (30 lines), Metadata (40 lines)
Estimated effort: 2-3 hours

Priority

High - Marked as "Immediate Action" in the compiler quality report. Reduces complexity in critical YAML generation code.

AI generated by Discussion Task Miner - Code Quality Improvement Agent

  • expires on Feb 16, 2026, 5:32 AM UTC

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions