mirror of
https://github.com/coder/coder.git
synced 2026-06-04 13:38:21 +00:00
a8f2a8a44d
## Problem The `prepWorkspaceBuild()` function in `cli/create.go` was unconditionally executing dry-runs for **all** workspace actions. This caused unnecessary delays and "Planning workspace..." messages during `coder start` and `coder restart` commands when they should only happen during `coder create` and `coder update`. ## Root Cause The `prepWorkspaceBuild()` function is shared code called by: - **create command** - passes `WorkspaceCreate` action ✅ dry-run IS desired - **update command** - passes `WorkspaceUpdate` action ✅ dry-run IS desired - **start command** - passes `WorkspaceStart` action (or `WorkspaceUpdate` as fallback) ❌ dry-run NOT desired for `WorkspaceStart` - **restart command** - passes `WorkspaceRestart` action ❌ dry-run NOT desired - **scaletest commands** - pass `WorkspaceCreate` action ✅ dry-run IS desired ## Solution Wrapped the dry-run section (lines 580-627) in a conditional that only executes when `args.Action == WorkspaceCreate || args.Action == WorkspaceUpdate`. This skips dry-run for `WorkspaceStart` and `WorkspaceRestart` actions while preserving it for creation and explicit updates. ## Changes - Added conditional check around the entire dry-run logic block - Added clarifying comment explaining the intent - Changed from unconditional execution to: `if args.Action == WorkspaceCreate || args.Action == WorkspaceUpdate { ... }` ## Impact | Command | Action Type | Dry-run Before | Dry-run After | Status | |---------|-------------|----------------|---------------|--------| | `coder create` | `WorkspaceCreate` | ✅ Yes | ✅ Yes | Unchanged | | `coder update` | `WorkspaceUpdate` | ✅ Yes | ✅ Yes | Unchanged | | `coder start` (normal) | `WorkspaceStart` | ❌ Yes (bug) | ✅ No | **Fixed** | | `coder start` (template changed) | `WorkspaceUpdate` | ✅ Yes | ✅ Yes | Unchanged (correct behavior) | | `coder restart` | `WorkspaceRestart` | ❌ Yes (bug) | ✅ No | **Fixed** | | scaletest | `WorkspaceCreate` | ✅ Yes | ✅ Yes | Unchanged | ## Testing ✅ **Code compiles successfully** ```bash go build -o /dev/null ./cli/... ``` ✅ **All relevant tests pass locally** ```bash cd cli && go test -run "TestCreate|TestStart|TestRestart|TestUpdate" -v PASS ok github.com/coder/coder/v2/cli 3.337s ``` ✅ **All CI checks pass** - test-go-pg (ubuntu, macos, windows) ✅ - test-go-pg-17 ✅ - test-go-race-pg ✅ - test-e2e ✅ - All other checks ✅ ## Behavior Changes **Before:** - Users running `coder start` would see "Planning workspace..." and wait for unnecessary dry-run completion - Users running `coder restart` would experience unnecessary dry-run overhead **After:** - `coder start` (simple start) skips dry-run entirely (faster, more intuitive) - `coder start` (with template update) still shows dry-run (correct - user needs to see what's changing) - `coder restart` skips dry-run entirely (faster, more intuitive) - `coder create` maintains existing dry-run behavior (shows "Planning workspace..." and resource preview) - `coder update` maintains existing dry-run behavior (shows "Planning workspace..." and resource preview) ## Verification Manual testing should verify: 1. `coder create` still shows "Planning workspace..." ✅ 2. `coder update` still shows "Planning workspace..." ✅ 3. `coder start` (simple start) does NOT show "Planning workspace..." ✅ 4. `coder restart` does NOT show "Planning workspace..." ✅