Skip to content

refactor(pkg/cli): partial decomposition of largefunc linter violations#36006

Closed
Copilot wants to merge 11 commits into
mainfrom
copilot/lint-monster-refactor-long-functions-another-one
Closed

refactor(pkg/cli): partial decomposition of largefunc linter violations#36006
Copilot wants to merge 11 commits into
mainfrom
copilot/lint-monster-refactor-long-functions-another-one

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 30, 2026

The custom largefunc linter flagged ~777 functions in pkg/cli exceeding the 60-line limit. This PR makes a first pass at decomposing the largest and most structurally clear offenders.

Production files refactored

  • codemod_engine_steps.go — split 251-line function into ~10 focused helpers
  • codemod_factory.go — split 153-line function + nested literals into 5 helpers
  • codemod_mcp_network.go — extracted apply, shouldSkipAllowedItem, and related helpers
  • codemod_network_firewall.go — extracted findAgentBlockEnd
  • codemod_github_app.go / codemod_github_repos.go — extracted rename helpers
  • codemod_engine_env_secrets.go / codemod_engine_max_runs.go — extracted apply functions
  • codemod_agent_session.go / codemod_assign_to_agent.go / codemod_bash_single_quoted_args.go — extracted transform helpers
  • compile_orchestrator.go, compile_pipeline.go, compile_stats.go and 7 other compile files — helper extraction

Test files refactored

  • audit_report_test.go, audit_diff_test.go, audit_expanded_test.go, audit_cross_run_test.go, audit_mcp_tool_usage_test.go, audit_report_helpers_test.go — test case tables extracted to *TestCases() helpers
  • actions_test.go, staged_filtering_test.go, firewall_log_test.go — long test functions split

Build fixes

  • add_interactive_schedule.go — missing context import added
  • compile_summary_output_test.go — restored from a broken state (literal newlines inside string literals caused parse failures)

Remaining work

~426 violations remain across ~187 production files (mcp, audit, logs, trial, run, update families). This PR reduces the count from 777 → ~426.

Copilot AI and others added 10 commits May 30, 2026 23:07
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
…od files

Fix all 10 function-length violations (>60 lines) in pkg/cli codemod files:

- codemod_engine_env_secrets.go: extract engineEnvKeyRemover struct + processLine
- codemod_engine_max_runs.go: extract applyEngineMaxRunsMigration, hasInlineEngineMaxRuns, findEngineMaxRunsSuffix, transformEngineMaxRunsLines
- codemod_engine_steps.go: extract findEngineStepsStart, findIndentedBlockEnd, deindentStepsLines, findTopLevelStepsEnd, buildLinesWithoutRange, isEngineBlockEmpty, stripEmptyEngineBlock, removeEngineBlockIfEmpty, mergeEngineStepsToTopLevel, applyEngineStepsTransform
- codemod_factory.go: extract findFieldAndOnBlock, collectMoveFieldLines, buildOnBlockFromField, insertFieldIntoExistingOnBlock, applyMoveTopLevelKeyToOnBlock
- codemod_github_app.go: extract appRenameBlockState struct with updateExit/updateEntry/shouldRenameApp methods
- codemod_github_repos.go: extract renameReposToAllowedRepos helper
- codemod_mcp_network.go: extract collectMCPNetworkDomains, collectExistingNetworkDomains, transformMCPNetworkLines, applyMCPNetworkMigration, mcpFieldRemover struct, shouldSkipAllowedItem
- codemod_network_firewall.go: extract findAgentBlockEnd

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
…nter (≤60 lines)

- logs_cache.go: extract runFolderDate helper; cleanupOldRunFolders 65→~45 lines
- logs_utils.go: extract extractWorkflowNameFromContent + 7 helpers for findAgentLogFile; both functions reduced to ≤46 lines
- logs_command.go: extract logsCommandLong var, addLogsFlags, runLogsCommand, runLogsStdin, resolveLogsWorkflowArg, resolveLogsDateFlags, validateLogsEngine, runLogsDownload
- logs_download.go: extract flattenSingleArtifactDir, removeFlattenedDir, buildWorkflowLogsArgs, validateAndBuildZipPath, copyZipEntry, checkArtifactCache, listAndClassifyArtifacts, performArtifactDownload, downloadSelectiveArtifacts, downloadBulkArtifacts, buildBulkDownloadArgs, handleBulkDownloadError, retryAfterCaseCollision, verboseEnumerateArtifacts
- Fix pre-existing syntax errors: audit.go multi-line string literals, add_interactive_schedule.go missing context import

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
…d files

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
…rs and failing tests

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor functions in pkg/cli exceeding 60 lines refactor(pkg/cli): partial decomposition of largefunc linter violations May 30, 2026
Copilot AI requested a review from gh-aw-bot May 30, 2026 23:50
@pelikhan pelikhan closed this May 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[lint-monster] Refactor long functions in pkg/cli exceeding 60-line limit

3 participants