-
Notifications
You must be signed in to change notification settings - Fork 190
Description
Overview
The file pkg/workflow/compiler_safe_outputs_consolidated.go has grown to 1,368 lines, making it difficult to maintain and test effectively. This file orchestrates the consolidated safe outputs job compilation and contains 30 functions, primarily consisting of step configuration builders for different safe output operations (issues, PRs, discussions, etc.).
Current State
- File:
pkg/workflow/compiler_safe_outputs_consolidated.go - Size: 1,368 lines (71% over the 800-line healthy threshold)
- Functions: 30 total functions
- Test Coverage: No dedicated test file (
compiler_safe_outputs_consolidated_test.godoes not exist) - Related Tests: 18 test files cover various safe outputs aspects (total: ~5,500 LOC)
- Complexity: High - manages 20+ different safe output types with similar patterns
Architecture Analysis
The file follows a clear but repetitive pattern:
- Lines 1-100: Package setup,
SafeOutputStepConfigstruct definition - Lines 38-537:
buildConsolidatedSafeOutputsJob- main orchestrator (499 lines) - Lines 537-669: Core helper functions (132 lines)
- Lines 679-1,368: 25 individual step config builders (689 lines)
Current Groupings Identified
GitHub Issues Operations (5 functions):
buildCreateIssueStepConfigbuildUpdateIssueStepConfigbuildCloseIssueStepConfigbuildLinkSubIssueStepConfig- Related helper functions
Pull Request Operations (6 functions):
buildCreatePullRequestStepConfigbuildUpdatePullRequestStepConfigbuildClosePullRequestStepConfigbuildCreatePRReviewCommentStepConfigbuildPushToPullRequestBranchStepConfigbuildAddReviewerStepConfig
Discussion Operations (3 functions):
buildCreateDiscussionStepConfigbuildUpdateDiscussionStepConfigbuildCloseDiscussionStepConfig
Shared Operations (4 functions):
buildAddCommentStepConfig(works with issues, PRs, discussions)buildAddLabelsStepConfigbuildHideCommentStepConfigbuildUploadAssetsStepConfig
Specialized Operations (7 functions):
buildCreateCodeScanningAlertStepConfigbuildAssignMilestoneStepConfigbuildAssignToAgentStepConfigbuildAssignToUserStepConfigbuildUpdateReleaseStepConfigbuildCreateAgentTaskStepConfigbuildUpdateProjectStepConfig
Refactoring Strategy
Proposed File Splits
Split the monolithic file into 6 focused modules based on functional domains:
1. compiler_safe_outputs_core.go (~200 lines)
Responsibility: Core orchestration and shared utilities
Contents:
SafeOutputStepConfigstruct definitionbuildConsolidatedSafeOutputsJobmain orchestratorbuildConsolidatedSafeOutputStephelperbuildJobLevelSafeOutputEnvVarshelperbuildDetectionSuccessConditionhelper
Rationale: Central coordination logic used by all step builders
2. compiler_safe_outputs_issues.go (~200 lines)
Responsibility: Issue-related safe output operations
Contents:
buildCreateIssueStepConfigbuildUpdateIssueStepConfigbuildCloseIssueStepConfigbuildLinkSubIssueStepConfig- Any issue-specific pre-step builders
Estimated LOC: ~200 lines
3. compiler_safe_outputs_prs.go (~300 lines)
Responsibility: Pull request operations
Contents:
buildCreatePullRequestStepConfigbuildUpdatePullRequestStepConfigbuildClosePullRequestStepConfigbuildCreatePRReviewCommentStepConfigbuildPushToPullRequestBranchStepConfigbuildAddReviewerStepConfigbuildCreatePullRequestPreStepsConsolidatedbuildPushToPullRequestBranchPreStepsConsolidated
Estimated LOC: ~300 lines (includes pre-steps logic)
4. compiler_safe_outputs_discussions.go (~150 lines)
Responsibility: Discussion operations
Contents:
buildCreateDiscussionStepConfigbuildUpdateDiscussionStepConfigbuildCloseDiscussionStepConfig
Estimated LOC: ~150 lines
5. compiler_safe_outputs_shared.go (~200 lines)
Responsibility: Operations that work across multiple entity types
Contents:
buildAddCommentStepConfig(issues, PRs, discussions)buildAddLabelsStepConfigbuildHideCommentStepConfigbuildUploadAssetsStepConfig
Estimated LOC: ~200 lines
6. compiler_safe_outputs_specialized.go (~318 lines)
Responsibility: Specialized/less common operations
Contents:
buildCreateCodeScanningAlertStepConfigbuildAssignMilestoneStepConfigbuildAssignToAgentStepConfigbuildAssignToUserStepConfigbuildUpdateReleaseStepConfigbuildCreateAgentTaskStepConfigbuildUpdateProjectStepConfig
Estimated LOC: ~318 lines
Benefits of This Split
✅ Improved Navigation: Developers can quickly locate issue, PR, or discussion logic
✅ Parallel Development: Multiple developers can work on different entity types simultaneously
✅ Targeted Testing: Each module can have focused test coverage
✅ Reduced Merge Conflicts: Changes to one entity type won't conflict with others
✅ Clearer Dependencies: Explicit imports show which modules depend on core utilities
✅ Better Code Review: Smaller files are easier to review and understand
Test Coverage Plan
Create 6 new test files matching the split structure:
1. compiler_safe_outputs_core_test.go
Test Cases:
- Main orchestrator builds correct job structure
- Script setup step is generated correctly
- Permission aggregation works across all step types
- Condition chaining with threat detection
- Output mapping and dependencies
- Target Coverage: >80%
2. compiler_safe_outputs_issues_test.go
Test Cases:
- Create issue step config generation
- Update issue with title/body/state
- Close issue with comment
- Link sub-issues with dependencies
- Condition handling for each operation
- Target Coverage: >80%
3. compiler_safe_outputs_prs_test.go
Test Cases:
- Create PR with branch setup pre-steps
- Update PR title/body/base
- Close PR with comment
- Review comment creation on specific files/lines
- Push to PR branch with git operations
- Add reviewer assignment
- Target Coverage: >80%
4. compiler_safe_outputs_discussions_test.go
Test Cases:
- Create discussion in category
- Update discussion title/body
- Close discussion with reason
- Target Coverage: >80%
5. compiler_safe_outputs_shared_test.go
Test Cases:
- Add comment to issue/PR/discussion (context detection)
- Add labels with validation
- Hide comment (spam/abuse)
- Upload assets with path handling
- Target Coverage: >80%
6. compiler_safe_outputs_specialized_test.go
Test Cases:
- Code scanning alert creation with SARIF
- Milestone assignment
- Agent task creation
- User assignment
- Release updates
- Project updates
- Target Coverage: >80%
Implementation Guidelines
Phase 1: Preparation (No Code Changes)
- ✅ Review existing test coverage in related test files
- ✅ Document current behavior of all 30 functions
- ✅ Identify shared dependencies between functions
- ✅ Create test plan for each new module
Phase 2: Test-First Approach
- Create test files first with comprehensive test cases
- Import from original file temporarily to validate tests pass
- Run
make test-unitto ensure baseline coverage - Document any gaps in test coverage
Phase 3: Incremental Refactoring
-
Start with smallest module:
compiler_safe_outputs_discussions.go- Extract 3 discussion functions
- Update imports in test files
- Run
make test-unitandmake lint - Commit with message:
refactor: extract discussion safe outputs to dedicated file
-
Continue with each module in order of independence:
- Specialized → Shared → Issues → PRs → Core
- Core should be last since it's imported by all others
-
After each split:
- ✅ All tests pass (
make test-unit) - ✅ Linting succeeds (
make lint) - ✅ Build works (
make build) - ✅ No breaking changes to public API
- ✅ All tests pass (
Phase 4: Cleanup
- Delete original file once all functions are migrated
- Update documentation if needed
- Run full validation:
make agent-finish - Final commit:
refactor: complete safe outputs consolidation split
Acceptance Criteria
- Original 1,368-line file is split into 6 focused files
- Each new file is under 500 lines
- All 30 functions are correctly migrated
- 6 new test files with >80% coverage each
- All tests pass (
make test-unit) - Code passes linting (
make lint) - Build succeeds (
make build) - No breaking changes to public API
- No regression in existing test coverage
- Import paths are correct and minimal
Additional Context
- Repository Guidelines: Follow patterns in
.github/instructions/developer.instructions.md - Code Organization: Prefer many small files grouped by functionality (documented pattern)
- Existing Patterns: Similar organization exists in engine separation (
copilot_engine.go,claude_engine.go, etc.) - Testing Reference: Match patterns in existing
pkg/workflow/*_test.gofiles
Campaign Metrics
Go File Size Reduction Campaign
- Analysis Date: 2025-12-22
- Largest File: 1,368 lines
- Files Over 800 LOC: 20 files
- Reduction Target: Split into 6 files averaging ~228 lines each
Priority: Medium
Effort: Large (estimated 8-12 hours across multiple PRs)
Expected Impact:
- ✅ Significantly improved maintainability
- ✅ Easier onboarding for new contributors
- ✅ Reduced cognitive load during code review
- ✅ Better test isolation and coverage
- ✅ Fewer merge conflicts in active development areas
AI generated by Daily File Diet