fix(lint): resolve 4 targeted golint-custom findings in pkg/cli, cmd/gh-aw, and pkg/linters#47910
Conversation
…ded path, long funcs) Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
|
✅ Test Quality Sentinel completed test quality analysis. |
|
✅ Design Decision Gate 🏗️ completed the design decision gate check. |
|
🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅ |
There was a problem hiding this comment.
Pull request overview
Refactors targeted lint findings while preserving CLI and analyzer behavior.
Changes:
- Splits oversized CLI and linter functions into focused helpers.
- Introduces Docker image options and updates callers/tests.
- Fixes timer cleanup and extracts the Grant container path constant.
Show a summary per file
| File | Description |
|---|---|
cmd/gh-aw/main.go |
Decomposes compile, help, and command setup logic. |
pkg/cli/docker_images.go |
Adds DockerImagesOptions. |
pkg/cli/docker_images_test.go |
Updates options-based tests. |
pkg/cli/mcp_tools_readonly.go |
Migrates the Docker-image caller. |
pkg/cli/mcp_inspect_inspector.go |
Stops timers per iteration. |
pkg/cli/grant.go |
Names the container policy path. |
pkg/linters/stringbytesroundtrip/stringbytesroundtrip.go |
Extracts conversion-pair analysis. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 7/7 changed files
- Comments generated: 0
- Review effort level: Medium
|
✅ PR Code Quality Reviewer completed the code quality review. |
There was a problem hiding this comment.
Review: fix(lint) — 4 golint-custom findings
All changes are clean, mechanical refactors with no behavioural differences:
- defer-in-loop (
mcp_inspect_inspector.go):timer.Stop()correctly moved after theselectblock — each iteration now cleans up immediately instead of deferring to function return. - over-limit param count (
docker_images.go): 9 bool params collapsed intoDockerImagesOptionsstruct; all callers and tests updated consistently. No logic change. - hardcoded temp path (
grant.go): extracted asgrantContainerPolicyPathconstant — straightforward and correct. - long functions (
main.go,stringbytesroundtrip.go): extracted helpers preserve original logic faithfully;parseCompileFlagscorrectly propagates the--gh-aw-refresolution error;unpackConversionPairreturns the same early-exit conditions as the original inline code.
No security, correctness, or reliability issues found.
🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · sonnet46 · 34.5 AIC · ⌖ 4.56 AIC · ⊞ 5K
There was a problem hiding this comment.
Skills-Based Review 🧠
Applied /codebase-design — changes approved with no actionable issues.
📋 Key Themes & Highlights
What was reviewed
This is a targeted lint-compliance refactor across 7 files, resolving 4 golint-custom findings:
mcp_inspect_inspector.go—defer timer.Stop()correctly moved out of the loop to a per-iteration direct call. Fix is semantically correct.docker_images.go— 9-parameter signature collapsed intoDockerImagesOptionsstruct. All callers and test call sites updated. The struct uses exported boolean fields with safe zero-value defaults — idiomatic Go.grant.go— bare/tmp/gh-aw-grant-policy.yamlstring extracted to a named constant. Correct.cmd/gh-aw/main.go— 447-lineinit()decomposed into 10 focused helpers;compileCmd.RunEextracted torunCompileCmdwithcompileFlags/parseCompileFlags/buildCompileConfig. The refactoring is faithful — flag names, mutual-exclusion constraints,--gh-aw-refresolution order, and the--fixpre-pass are all preserved.stringbytesroundtrip.go—unpackConversionPaircorrectly extracted;roundTripTypesstruct cleanly replaces the inline variables. All early-return paths preserved.
Positive Highlights
- ✅
DockerImagesOptionszero-value is a safe default (verified byTestCheckAndPrepareDockerImages_NoToolsRequested) - ✅ Tests updated 1-for-1 with the new struct signature — no coverage regression
- ✅
parseCompileFlags/buildCompileConfigseparation makes the compile path unit-testable without a full Cobra context - ✅ Changes are surgical: no unrelated behaviour changes detected
🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 31.7 AIC · ⌖ 7.48 AIC · ⊞ 6.7K
Comment /matt to run again
…olean function signatures
Design Decision Gate - ADR RequiredThis PR makes significant changes to core business logic (103 new lines in Draft ADR committed: This PR cannot merge until an ADR is linked in the PR body. What to do next
Once an ADR is linked in the PR body, this gate will re-run and verify the implementation matches the decision. Why ADRs MatterADRs create a searchable, permanent record of why the codebase looks the way it does. Future contributors (and your future self) will thank you. Michael Nygard ADR Format ReferenceAn ADR must contain these four sections to be considered complete:
All ADRs are stored in
|
There was a problem hiding this comment.
🧪 Test Quality Sentinel Report
✅ Test Quality Score: N/A — Refactoring Only
No new or modified behavioral tests detected. This PR contains only parameter refactoring updates to existing test calls.
📊 Analysis Details
Test File Analyzed:
pkg/cli/docker_images_test.go(697 lines, 27 total test functions)
Changes:
- Modified test functions: 11 (parameter refactoring only — updated
CheckAndPrepareDockerImages()calls to useDockerImagesOptions{}struct) - New test functions: 0
- Modified assertions: 0
- Lines added to test file: 0
Quality Signals:
| Signal | Result |
|---|---|
| Build tag present | ✅ Yes (//go:build !integration) |
| Forbidden mocking patterns | ✅ None |
| Test inflation | ✅ None (0 lines added) |
| Violations | ✅ None |
Test Functions Updated (parameter refactoring only):
TestCheckAndPrepareDockerImages_NoToolsRequested— DockerImagesOptions{}TestCheckAndPrepareDockerImages_ImageAlreadyDownloading— DockerImagesOptions{Zizmor: true}TestCheckAndPrepareDockerImages_MultipleImages— struct with multiple fieldsTestCheckAndPrepareDockerImages_RetryMessageFormat— DockerImagesOptions{Zizmor: true}TestCheckAndPrepareDockerImages_StartedDownloadingMessage— struct updateTestCheckAndPrepareDockerImages_ImageAlreadyAvailable— struct updateTestCheckAndPrepareDockerImages_DockerUnavailable— struct updateTestCheckAndPrepareDockerImages_DockerUnavailable_MultipleTools— struct with multiple fieldsTestCheckAndPrepareDockerImages_DockerUnavailable_NoTools— DockerImagesOptions{}TestCheckAndPrepareDockerImages_DockerUnavailable_ReturnsTypedError— struct updateTestCheckAndPrepareDockerImages_RunnerGuardImageDownloading— struct with multiple fields
Verdict
✅ passed. Refactoring-only PR with no new behavioral tests. All existing test assertions remain unchanged; no violations detected.
There was a problem hiding this comment.
Two issues require fixes before merge
The refactoring is generally clean and the individual fixes (defer-in-loop, option struct, named constant) are correct. Two problems need attention:
🔴 Blocking findings
-
Linter hot-path performance regression (
pkg/linters/stringbytesroundtrip/stringbytesroundtrip.go): The cheaplen(outer.Args) != 1guard was moved insideunpackConversionPair, placed after the more expensivePositionFor(fileset lock) andShouldSkipFilename(map lookup) calls. Every multi-argumentCallExprin analyzed codebases now pays this unnecessary cost. The guard must be restored before those calls inanalyzeRoundTrip. -
newCmdflag registration inconsistency (cmd/gh-aw/main.go):newCmdflags are registered inline insetupSetupGroupCmds, unlikecompileCmdwhich has a dedicatedregisterCompileFlags()helper. SincenewCmdis a package-level var, any double-invocation of the setup functions (test harnesses, reset-and-reinit patterns) will panic withflag redefined. ExtractregisterNewCmdFlags()to match the established pattern.
🔎 Code quality review by PR Code Quality Reviewer · sonnet46 · 74.4 AIC · ⌖ 5.02 AIC · ⊞ 5.7K
Comment /review to run again
Comments that could not be inline-anchored
pkg/linters/stringbytesroundtrip/stringbytesroundtrip.go:1302
Performance regression in linter hot-path: the cheap arg-count guard was moved behind two more expensive operations, causing unnecessary work on every multi-argument call expression.
<details>
<summary>💡 Details and fix</summary>
In the original analyzeRoundTrip, the first check was:
if len(outer.Args) != 1 || outer.Ellipsis.IsValid() {
return
}That guard fired before pass.Fset.PositionFor (acquires fileset lock) and filecheck.ShouldSkipFilename (map lookup). After …
cmd/gh-aw/main.go:657
newCmd flag registration inside setupSetupGroupCmds is inconsistent with registerCompileFlags() pattern: if setupSetupGroupCmds is called more than once (e.g., in tests), Cobra panics with flag redefined.
<details>
<summary>💡 Details and fix</summary>
The PR correctly extracted registerCompileFlags() as a standalone helper to isolate compileCmd flag registration. But newCmd flags are still registered inline inside setupSetupGroupCmds:
func setupSetupGroupCmds() {…
</details>|
@copilot please run the
|
…terNewCmdFlags/registerRemoveCmdFlags Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Addressed both blocking items in commit
Local validation: |
🤖 PR Triage
Rationale: Fixes 4 targeted lint findings (defer-in-loop, over-limit params, hard-coded temp path, long functions) across Next step: Address CHANGES_REQUESTED, then expedite review.
|
|
@copilot resolve the merge conflicts on this branch. |
…targeted-custom-lint-fixes # Conflicts: # pkg/linters/stringbytesroundtrip/stringbytesroundtrip.go Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
|
@copilot please run the
|
Merge conflicts resolved. |
…targeted-custom-lint-fixes Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Branch is up to date with main (commit |
Resolves all 4 non-shared findings reported by
make golint-custom: a defer-in-loop, an over-limit parameter count, a hard-coded temp path, and several long functions.pkg/cli fixes
mcp_inspect_inspector.go— removeddefer timer.Stop()from inside aforloop; replaced with direct call after theselectblock so cleanup happens per-iteration rather than at function returndocker_images.go— replaced 9-parameterCheckAndPrepareDockerImagessignature with a singleDockerImagesOptionsstruct; all callers updatedgrant.go— extractedgrantContainerPolicyPath = "/tmp/gh-aw-grant-policy.yaml"named constant; replaced bare string literalcmd/gh-aw/main.go long-function splits
compileCmd.RunE(was 129 lines) — extracted to namedrunCompileCmdfunction; flag parsing isolated intocompileFlagsstruct +parseCompileFlags()+buildCompileConfig()SetUsageFuncliteral (was 72 lines) — extractedfixUsagePath()andprintUsageSubCmds()as package-level helpersinit()(was 447 lines) — decomposed into 10 focused helpers:setupRootCmdGroups,setupRootCmdMeta,makeCustomHelpCmd,registerCompileFlags,setupSetupGroupCmds,setupDevelopmentGroupCmds,setupExecutionGroupCmds,setupAnalysisGroupCmds,setupUtilityGroupCmds,fixAllSubCmdHelpFlagspkg/linters/stringbytesroundtrip
analyzeRoundTrip(was 73 lines) — introducedroundTripTypesstruct and extractedunpackConversionPair()helper to reduce the main function below the 60-line limit