-
Notifications
You must be signed in to change notification settings - Fork 476
Refactor interactive/audit CLI large functions into focused helpers #49799
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
pelikhan
merged 8 commits into
main
from
copilot/lint-monster-fix-function-lengths-again
Aug 2, 2026
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b2c35b5
Initial plan
Copilot 4e05105
refactor: split large interactive and audit helper flows
Copilot f2ae54a
docs(adr): add draft ADR-49799 for CLI largefunc decomposition
github-actions[bot] 1993c9c
Merge branch 'main' into copilot/lint-monster-fix-function-lengths-again
github-actions[bot] 673988e
fix: preserve engine priority fall-through and propagate fatal form e…
Copilot 4ce6dc3
fix: remove always-nil error from processSquidAccessLogLine; clarify …
Copilot f9896b7
docs(adr): finalize ADR-49799 status from Draft to Accepted
Copilot 58b01fd
Merge remote-tracking branch 'origin/main' into copilot/lint-monster-…
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| # ADR-49799: Decompose Oversized CLI Functions into Focused Helper Functions | ||
|
|
||
| **Date**: 2026-08-02 | ||
| **Status**: Accepted | ||
| **Deciders**: pelikhan, app/copilot-swe-agent | ||
|
|
||
| --- | ||
|
|
||
| ### Context | ||
|
|
||
| The codebase enforces a custom `largefunc` linter rule capping functions at 60 lines (`make golangci-lint`). Several CLI entry-point and flow-control functions in `pkg/cli/` exceeded this limit: `RunAddInteractive` (126 lines), `createWorkflowPRAndConfigureSecret` (171 lines), `computeFirewallDiff` (144 lines), `parseSquidAccessLog` (80 lines), `buildAction` (83 lines), and `selectAIEngineAndKey` (118 lines). These functions mixed multiple sequential phases — host auto-detection, preflight checks, PR merge orchestration, secret configuration, and domain diff classification — into single units, making them difficult to test in isolation and harder to reason about under review. | ||
|
|
||
| ### Decision | ||
|
|
||
| We will decompose each oversized CLI function into focused, single-responsibility helper functions co-located in the same file and package. Each extracted helper covers exactly one logical phase (e.g., host detection, PR merge loop, domain diff entry construction) and is tested independently where behavior is non-trivial. The `mergeAction` type and its constants, previously function-local, are promoted to package scope to allow multiple helpers to reference them without re-declaration. | ||
|
|
||
| ### Alternatives Considered | ||
|
|
||
| #### Alternative 1: Raise the `largefunc` lint threshold | ||
|
|
||
| Increase the per-function line limit (or add per-file lint suppressions) to accommodate the current oversized functions without refactoring. This avoids code churn but leaves the underlying mixed-responsibility problem in place, degrades long-term readability, and weakens the lint rule for the rest of the codebase. | ||
|
|
||
| #### Alternative 2: Extract logic into separate packages or interface types | ||
|
|
||
| Move the orchestration phases into new dedicated packages or types rather than inline helper functions in the same file. This would provide module-level separation of concerns but would introduce new packages, potential import complexity, and substantial structural churn for what is fundamentally a sequential orchestration flow with no reuse across packages. | ||
|
|
||
| ### Consequences | ||
|
|
||
| #### Positive | ||
| - All affected functions pass the 60-line `largefunc` lint check, unblocking CI. | ||
| - Extracted helpers are individually testable; focused unit tests were added for `prioritizeEngineOption` and `buildMergeOptions`. | ||
| - Orchestrator functions (`RunAddInteractive`, `createWorkflowPRAndConfigureSecret`) now read as a sequence of high-level named steps, improving code review clarity. | ||
|
|
||
| #### Negative | ||
| - Some extracted helpers carry high parameter counts (e.g., `processSquidAccessLogLine` takes five parameters) because context is passed down rather than captured in a receiver or struct — trading function-length compliance for increased parameter coupling. | ||
| - The call graph is deeper; understanding the full flow now requires tracing through more helper function boundaries. | ||
|
|
||
| #### Neutral | ||
| - Command behavior and semantics are fully preserved; existing tests continue to pass unmodified. | ||
| - The `mergeAction` type and constants are now package-level rather than closure-local; this widens their scope but does not expose them outside the package. | ||
|
|
||
| --- | ||
|
|
||
| *ADR created by [adr-writer agent]. Status: Accepted.* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[/tdd]
determineDefaultEngineimplements a non-trivial 4-level priority chain (flag → secret → workflow frontmatter → env var) but has no unit tests. A wrong ordering silently selects the wrong model for every new user. Consider adding table-driven tests covering each priority level, similar to theTestPrioritizeEngineOptionpattern already used in this PR.@copilot please address this.