[WIP] Refactor large Go file into smaller files #8358
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Refactoring Plan: Split copilot_engine.go (1235 lines) into 6 focused files
Overview
Refactor the large
copilot_engine.gofile into smaller, focused files while maintaining 100% test coverage and preserving all existing behavior.Proposed File Structure
Phase 1: Core & Lifecycle (copilot_engine_core.go)
NewCopilotEngine(),GetDefaultDetectionModel(),GetDeclaredOutputFiles(),GetCleanupStep()copilot_engine_core_test.goPhase 2: Error Patterns (copilot_engine_errors.go)
GetErrorPatterns()functioncopilot_engine_errors_test.goPhase 3: Installation (copilot_engine_installation.go)
GetInstallationSteps(),generateAWFInstallationStep()copilot_engine_installation_test.goPhase 4: MCP Configuration (copilot_engine_mcp.go)
RenderMCPConfig(),renderCopilotMCPConfig()copilot_engine_mcp_test.goPhase 5: Log Parsing (copilot_engine_logs.go)
ParseLogMetrics(),parseCopilotToolCallsWithSequence(),GetLogParserScriptId(),GetLogFileForParsing(),GetFirewallLogsCollectionStep(),GetSquidLogsSteps(), and helper functionscopilot_engine_logs_test.goPhase 6: Execution (copilot_engine_execution.go)
GetExecutionSteps(),extractAddDirPaths(),computeCopilotToolArguments(),generateCopilotToolArgumentsComment()copilot_engine_execution_test.goPhase 7: Final Validation
copilot_engine.goandcopilot_engine_test.gomake test-unitto ensure all tests passmake fmtandmake lintmake buildmake recompileImplementation Strategy
copilotLoglogger across all filesmake test-unitfor fast feedback between changesOriginal prompt
This section details on the original issue you should resolve
<issue_title>[file-diet] Refactor Large Go File: pkg/workflow/copilot_engine.go</issue_title>
<issue_description>The file
pkg/workflow/copilot_engine.gohas grown to 1,172 lines, making it difficult to maintain despite having excellent test coverage. This task involves refactoring it into smaller, focused files while preserving the strong test suite.Current State
pkg/workflow/copilot_engine.goRefactoring Strategy
Proposed File Splits
Based on semantic analysis of function groupings and responsibilities:
1.
copilot_engine_core.goNewCopilotEngine()GetDefaultDetectionModel()GetDeclaredOutputFiles()GetCleanupStep()2.
copilot_engine_installation.goGetInstallationSteps()generateAWFInstallationStep()3.
copilot_engine_execution.goGetExecutionSteps()extractAddDirPaths()computeCopilotToolArguments()generateCopilotToolArgumentsComment()4.
copilot_engine_mcp.goRenderMCPConfig()renderCopilotMCPConfig()5.
copilot_engine_logs.goParseLogMetrics()parseCopilotToolCallsWithSequence()GetLogParserScriptId()GetLogFileForParsing()GetFirewallLogsCollectionStep()GetSquidLogsSteps()6.
copilot_engine_errors.goGetErrorPatterns()Shared Utilities
No new utility files needed - existing
engine_helpers.go(424 lines) already provides shared functionality across engines.Interface Abstractions
The current
Engineinterface (defined inengine.go) is well-designed and doesn't require changes. All refactored files will maintain the same public API.Test Coverage Plan
The existing test file
copilot_engine_test.go(1,148 lines) is comprehensive and should be similarly refactored:1.
copilot_engine_core_test.go2.
copilot_engine_installation_test.go3.
copilot_engine_execution_test.go4.
copilot_engine_mcp_test.go5.
copilot_engine_logs_test.go6.
copilot_engine_errors_test.goImplementation Guidelines
make test-unitpasses after each splitcopilotLoglogger accessible across all filesAcceptance Criteria
make test-unit)💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.