Skip to content

Windows: show correct Docker Desktop start command#162

Merged
anisaoshafi merged 2 commits intomainfrom
drg-666
Mar 24, 2026
Merged

Windows: show correct Docker Desktop start command#162
anisaoshafi merged 2 commits intomainfrom
drg-666

Conversation

@anisaoshafi
Copy link
Copy Markdown
Contributor

On Windows, lstk now detects if the user is running PowerShell or cmd.exe and suggests the correct command to start Docker Desktop. It used to show the PowerShell command regardless of shell.
We use the PSModulePath environment variable, which PowerShell always sets (cmd.exe does not).

Also took advantage to suppress the verbose Windows Docker error message since it isn't actionable.

@anisaoshafi anisaoshafi marked this pull request as ready for review March 23, 2026 17:16
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 23, 2026

📝 Walkthrough

Walkthrough

EmitUnhealthyError now conditionally suppresses the raw error summary on Windows and uses a new helper windowsDockerStartCommand(getenv, lookPath) to choose a Docker Desktop start instruction (CLI, PowerShell, or CMD) based on docker availability and PSModulePath.

Changes

Cohort / File(s) Summary
Docker error handling
internal/runtime/docker.go
EmitUnhealthyError initializes summary := err.Error() and, on Windows, may clear summary while replacing the suggested action with windowsDockerStartCommand(getenv, lookPath). Added windowsDockerStartCommand(getenv func(string) string, lookPath func(string) (string, error)) string to select between docker desktop start, a PowerShell & '...Docker Desktop.exe' form, or a quoted CMD full-path form depending on lookPath("docker") and PSModulePath.
Unit tests
internal/runtime/docker_test.go
Added three Windows-focused unit tests for windowsDockerStartCommand injecting mocked lookPath and getenv to validate: (1) docker present → docker desktop start; (2) docker absent + PSModulePath set → PowerShell & 'C:\Program Files\Docker\Docker\Docker Desktop.exe' form; (3) docker absent + PSModulePath unset → quoted CMD full-path invocation.
Windows integration tests
test/integration/docker_windows_test.go
Added Windows-only integration tests and helpers (windowsDockerErrorEnv, windowsDockerErrorEnvNoDocker) that set DOCKER_HOST to an invalid address, remove or set PSModulePath and PATH to force fallbacks. Four tests assert that lstk start returns exit code 1, suggests the appropriate start instruction (CLI / PowerShell / CMD), and that verbose Docker daemon text is omitted in the emitted summary on Windows.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Description check ✅ Passed The description clearly explains the Windows shell detection logic using PSModulePath, the resulting command suggestions for PowerShell vs cmd.exe, and the suppression of verbose error messages.
Title check ✅ Passed The title accurately summarizes the main change: detecting and showing the correct Docker Desktop start command on Windows, which is the primary objective of the PR.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch drg-666

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 and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
test/integration/docker_windows_test.go (1)

12-17: Consider documenting why PSModulePath and DOCKER_HOST are both removed first.

The helper removes both PSModulePath and DOCKER_HOST, then re-adds DOCKER_HOST. The removal of PSModulePath is the default state (for CMD detection), but this might not be immediately obvious to future readers.

📝 Suggested documentation improvement
-// windowsDockerErrorEnv returns an Environ with an invalid DOCKER_HOST and no PSModulePath.
+// windowsDockerErrorEnv returns an Environ configured to trigger a Docker connection failure.
+// PSModulePath is removed to default to CMD shell detection; callers can add it back for PowerShell tests.
+// DOCKER_HOST points to an unreachable address to force the "Docker not available" error path.
 func windowsDockerErrorEnv() env.Environ {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/integration/docker_windows_test.go` around lines 12 - 17, The helper
windowsDockerErrorEnv removes PSModulePath and DOCKER_HOST then re-adds
DOCKER_HOST with an invalid value; add a brief inline comment in the
windowsDockerErrorEnv function explaining that PSModulePath is removed to
simulate a non-PowerShell (CMD) environment detection and that DOCKER_HOST is
cleared first to ensure the test only uses the intentionally invalid
"tcp://localhost:1" value—this will make the intent clear to future readers
without changing behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@internal/runtime/docker.go`:
- Around line 104-110: The windowsDockerStartCommand currently returns shell
commands that rely on name resolution ("Docker Desktop"); update it to use
Docker's documented startup methods: detect PowerShell via
getenv("PSModulePath") (as already done) and return either the "docker desktop
start" command for modern Docker (preferred) or the full executable path
"C:\Program Files\Docker\Docker\Docker Desktop.exe" as a fallback (ensuring
proper quoting/escaping), so modify windowsDockerStartCommand to prefer "docker
desktop start" when available and fall back to the full executable path for both
PowerShell and cmd.exe branches instead of the current Start-Process/'start'
strings.

---

Nitpick comments:
In `@test/integration/docker_windows_test.go`:
- Around line 12-17: The helper windowsDockerErrorEnv removes PSModulePath and
DOCKER_HOST then re-adds DOCKER_HOST with an invalid value; add a brief inline
comment in the windowsDockerErrorEnv function explaining that PSModulePath is
removed to simulate a non-PowerShell (CMD) environment detection and that
DOCKER_HOST is cleared first to ensure the test only uses the intentionally
invalid "tcp://localhost:1" value—this will make the intent clear to future
readers without changing behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: c7954954-6350-4197-ab2e-efbddf8f048e

📥 Commits

Reviewing files that changed from the base of the PR and between 87a0335 and a9a198a.

📒 Files selected for processing (3)
  • internal/runtime/docker.go
  • internal/runtime/docker_test.go
  • test/integration/docker_windows_test.go

@anisaoshafi anisaoshafi marked this pull request as draft March 23, 2026 18:13
@anisaoshafi anisaoshafi marked this pull request as ready for review March 23, 2026 18:28
@anisaoshafi anisaoshafi changed the title fix(windows): detect shell and show matching Docker Desktop start command Windows: show correct Docker Desktop start command Mar 23, 2026
Copy link
Copy Markdown
Member

@silv-io silv-io left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@anisaoshafi anisaoshafi merged commit 4405213 into main Mar 24, 2026
14 of 15 checks passed
@anisaoshafi anisaoshafi deleted the drg-666 branch March 24, 2026 10:49
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.

2 participants