Commit a8f2a8a
authored
fix(cli): skip dry-run for workspace start/restart commands (#20754)
## 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..." ✅1 parent 04727c0 commit a8f2a8a
1 file changed
+48
-44
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
577 | 577 | | |
578 | 578 | | |
579 | 579 | | |
580 | | - | |
581 | | - | |
582 | | - | |
583 | | - | |
584 | | - | |
585 | | - | |
586 | | - | |
587 | | - | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
588 | 591 | | |
589 | | - | |
590 | | - | |
591 | | - | |
592 | | - | |
593 | | - | |
594 | | - | |
595 | | - | |
596 | | - | |
597 | | - | |
598 | | - | |
599 | | - | |
600 | | - | |
601 | | - | |
602 | | - | |
603 | | - | |
604 | | - | |
605 | | - | |
606 | | - | |
607 | | - | |
608 | | - | |
609 | | - | |
610 | | - | |
611 | | - | |
612 | | - | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
613 | 616 | | |
614 | | - | |
615 | | - | |
616 | | - | |
617 | | - | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
618 | 621 | | |
619 | | - | |
620 | | - | |
621 | | - | |
622 | | - | |
623 | | - | |
624 | | - | |
625 | | - | |
626 | | - | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
627 | 631 | | |
628 | 632 | | |
629 | 633 | | |
| |||
0 commit comments