Skip to content

refactor(agent): share docker CLI command and error helpers - #1508

Merged
skevetter merged 1 commit into
mainfrom
refactor/agent-delivery-docker-cli
Oct 16, 2026
Merged

skevetter merged 1 commit into
mainfrom
refactor/agent-delivery-docker-cli

Conversation

@skevetter

@skevetter skevetter commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Why

LocalDockerDelivery and RemoteDockerDelivery each carry a byte-identical cmd builder (exec.CommandContext plus environment append) and a dockerCommand resolver, and pkg/agent/delivery repeats the same captured-output error wrap (fmt.Errorf("%s: %w", capturedOutput(result), err)) at seven plain call sites. This PR moves the builder and the wrap into capture.go so the docker CLI invocation rules live in one place. It is the best next target in this package because it removes real duplication without touching any logic that differs between the two delivery types.

What changed

  • capture.go: added dockerCLI(ctx, command, env, args...), which holds the single copy of the builder body, and runDockerCLI(ctx, cmd), which runs runCaptured and wraps the error with captured output.
  • local_docker.go and remote_docker.go: cmd is now a one-line call to dockerCLI. The methods stay, so call sites and tests are unchanged. dockerCommand is untouched.
  • Seven plain-wrap sites (createVolume, populateVolumeWithHelper, removeVolume, copyBinaryFromSource, chmodBinary, ensureDir, copyDirIntoVolume) now return runDockerCLI(...).

Left unchanged on purpose:

  • volumeMountpoint and listManagedVolumes read result.Stdout after the error check, so they keep runCaptured.
  • The detect* helpers in local_docker.go either return the raw error or log it, so they do not use the wrap.
  • The podman unshare write failed: site (populateVolumeViaUnshare) and the workspace_seed.go inspect site use different message prefixes and must stay byte-identical.

Behaviour

No behaviour change. Error strings are unchanged, runCaptured semantics are unchanged, and dockerCommand resolution is unchanged. A nil Environment still leaves cmd.Env nil, and a non-nil one is still appended to os.Environ(). No exported API changed.

Validation

  • mkdir -p dist && task cli:format: pass (format touched only the four files in this PR).
  • task cli:lint:ci: pass (0 issues.).
  • go test ./pkg/agent/...: pass (pkg/agent, pkg/agent/delivery, pkg/agent/snapshot, pkg/agent/tunnelserver all ok).
  • Smoke (throwaway go test, deleted before commit): default docker command resolves to docker; DockerCommand override is used as Args[0]; Environment is appended for local and remote deliveries; nil env leaves cmd.Env nil; runDockerCLI error contains captured stderr and exit status; success returns nil.
  • Local CodeRabbit CLI (coderabbit review --agent --committed --base-commit <merge-base>): completed, 0 findings across the four reviewed files.

CodeRabbit CLI

Completed with 0 findings.

Auto-merge

Eligible: yes. Behaviour-preserving, 4 files, +31/-47, no tests touched, no lint disables, no go.mod, workflow, or secret-handling changes.

Summary by CodeRabbit

  • Bug Fixes
    • Docker and Podman delivery operations now include captured command output in error messages, making failures easier to diagnose.
    • Improved error reporting applies to local and remote delivery, including volume setup and workspace preparation.

Route LocalDockerDelivery and RemoteDockerDelivery command construction through dockerCLI, and replace the repeated captured-output error wrap with runDockerCLI at plain-wrap sites. Error strings and dockerCommand resolution are unchanged.
@skevetter skevetter added the auto-refactor Automated refactor PR label Oct 16, 2026
@netlify

netlify Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for devsydev canceled.

Name Link
🔨 Latest commit 0f74c74
🔍 Latest deploy log https://app.netlify.com/projects/devsydev/deploys/6ad26ae742620ae7ec31e70b

@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3b674b8e-b7d5-4aab-96a9-d2d218145843
📥 Commits

Reviewing files that changed from the base of the PR and between 6c75999 and 0f74c74.

📒 Files selected for processing: 4
  • pkg/agent/delivery/capture.go
  • pkg/agent/delivery/local_docker.go
  • pkg/agent/delivery/remote_docker.go
  • pkg/agent/delivery/workspace_seed.go

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

📝 Walkthrough

The change adds shared helpers for constructing and running Docker CLI commands. Local Docker, remote Docker, and workspace-seed operations now use these helpers for command execution and error handling.

Changes: Docker delivery command execution

Layer / File(s) Summary
Shared Docker command helpers
pkg/agent/delivery/capture.go
dockerCLI constructs context-bound commands and appends configured environment entries. runDockerCLI runs commands through runCaptured and wraps failures with captured diagnostic output.
Delivery path adoption
pkg/agent/delivery/local_docker.go, pkg/agent/delivery/remote_docker.go, pkg/agent/delivery/workspace_seed.go
Local and remote Docker operations and workspace volume copying now use the shared helpers for command construction and execution. Error handling delegates to runDockerCLI.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Merge Risk: ⚪ Minimal · up to 0f74c

No actionable merge-blocking issue is established; the change appears ready to merge after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: centralizing Docker CLI command construction and error-handling helpers.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
✨ Simplify code
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@netlify

netlify Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for images-devsy-sh canceled.

Name Link
🔨 Latest commit 0f74c74
🔍 Latest deploy log https://app.netlify.com/projects/images-devsy-sh/deploys/6ad26ae761a6558fed0c8b08

@skevetter
skevetter marked this pull request as ready for review October 16, 2026 19:08
@mergify

mergify Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

@skevetter
skevetter merged commit 2a9f58e into main Oct 16, 2026
111 checks passed
@skevetter
skevetter deleted the refactor/agent-delivery-docker-cli branch October 16, 2026 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-refactor Automated refactor PR size/m

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant