fix(lint): resolve all cyclop findings - #875
Conversation
cyclop is on by default once enabled (max-complexity: 8 already set) -- no separate opt-in setting, same as funcorder. Fixes all 10 pre-existing violations by extracting a cohesive sub-step out of each over-complex function into a well-named helper: - cmd/internal/agentcontainer/setup.go: syncMounts -> restoreSnapshotMounts - cmd/provider/configure_shared.go: initProvider -> providerConfigEntry - cmd/provider/list.go: runAvailable -> availableProviderNames - cmd/provider/set_source.go: Run -> activateProvider - cmd/workspace/import.go: importWorkspace -> extractWorkspaceData, applySnapshotSource - cmd/workspace/up/up.go: Run -> setUpTask - cmd/workspace/up/up_client.go: prepareClient -> checkProviderUpdate - pkg/agent/delivery/factory.go: NewAgentDelivery split into namedDriverDelivery (exact-match dispatch) plus appleDelivery and microsandboxDelivery helpers - pkg/provider/parse.go: validateAgentDriver's chained driver-name comparison replaced with a validAgentDrivers set lookup - pkg/ssh/forward.go: portForwarding -> watchTransportClosed All extractions are behavior-preserving; verified against existing test coverage (pkg/agent/delivery/factory_test.go exercises every branch of the driver dispatch). No logic changes.
✅ Deploy Preview for devsydev canceled.
|
📝 WalkthroughWalkthroughThe pull request extracts inline logic into focused helpers across workspace lifecycle, provider commands, agent delivery, driver validation, and SSH transport monitoring. Existing restoration, validation, dispatch, error, and cancellation behavior remains in place. ChangesWorkspace lifecycle helpers
Provider command helpers
Agent delivery and driver validation
SSH transport monitoring
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
✅ Deploy Preview for images-devsy-sh canceled.
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pkg/ssh/forward.go (1)
189-201: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winAvoid leaking
client.Wait()when forwarding exits with an open SSH client.
watchTransportClosedstarts a goroutine that waits onclient.Wait()until transport close, while only the second goroutine listens fordone.portForwardingreturns on context cancellation and can leak this waiter if callers leave thessh.Clientopen. Cancelclient.Wait()directly on thedone/context path, or centralize transport monitoring in a shared watcher owned by the client/session.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pkg/ssh/forward.go` around lines 189 - 201, Update watchTransportClosed so the goroutine waiting in client.Wait() is unblocked when done is signaled or forwarding exits through context cancellation. Coordinate the done and transportClosed paths so an open SSH client cannot leave the Wait watcher running, while preserving onClosed() behavior for transport-initiated closure.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@pkg/ssh/forward.go`:
- Around line 189-201: Update watchTransportClosed so the goroutine waiting in
client.Wait() is unblocked when done is signaled or forwarding exits through
context cancellation. Coordinate the done and transportClosed paths so an open
SSH client cannot leave the Wait watcher running, while preserving onClosed()
behavior for transport-initiated closure.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 053095fb-9597-43e3-af63-f368c27a56b2
📒 Files selected for processing (10)
cmd/internal/agentcontainer/setup.gocmd/provider/configure_shared.gocmd/provider/list.gocmd/provider/set_source.gocmd/workspace/import.gocmd/workspace/up/up.gocmd/workspace/up/up_client.gopkg/agent/delivery/factory.gopkg/provider/parse.gopkg/ssh/forward.go
|
Investigated the CodeRabbit nitpick on Verified: pre-existing behavior, not introduced by this PR. The Verified: Why closing the client here would introduce a real bug: Actual bound: the goroutine lives exactly as long as the Conclusion: no code change. A real fix would require restructuring client ownership (e.g., one client per forward, or a caller-side context that ties into |
Summary
Like
funcorder,cyclopis already fully active once enabled (max-complexity: 8is already set in.golangci.yaml) -- no separate opt-in setting exists, so all 10 pre-existing findings are fixed here in one PR.Each fix extracts a cohesive sub-step out of the over-complex function into a well-named helper:
cmd/internal/agentcontainer/setup.go:syncMounts->restoreSnapshotMountscmd/provider/configure_shared.go:initProvider->providerConfigEntrycmd/provider/list.go:runAvailable->availableProviderNamescmd/provider/set_source.go:Run->activateProvidercmd/workspace/import.go:importWorkspace->extractWorkspaceData,applySnapshotSourcecmd/workspace/up/up.go:Run->setUpTaskcmd/workspace/up/up_client.go:prepareClient->checkProviderUpdatepkg/agent/delivery/factory.go:NewAgentDeliverysplit intonamedDriverDelivery(exact-match dispatch) plusappleDelivery/microsandboxDeliveryhelpers -- verified behavior-identical againstfactory_test.go, which exercises every branch of the driver dispatchpkg/provider/parse.go:validateAgentDriver's chained driver-name comparison replaced with avalidAgentDriversset lookup (same boolean result, De Morgan-equivalent)pkg/ssh/forward.go:portForwarding->watchTransportClosedNo behavior changes. A few pre-existing
argument-limitfindings remain on unrelated, untouched lines incmd/internal/agentcontainer/setup.goandpkg/ssh/forward.go-- out of scope for this PR, will be picked up when that rule is worked.Summary by CodeRabbit
Bug Fixes
Refactor