Status: Done (2026-05-04)
Priority: Medium
Component: tools/wsl-manager/wsl-manager.ps1, lib/wsl/user.ps1, lib/wsl/proxy.ps1, lib/wsl/docker.ps1, lib/wsl/manager.docker.Integration.Tests.ps1, docs/wsl-manager.md
Summary: As a user, I want wsl-manager to automatically terminate a distribution when required instead of asking me to do it manually, so that actions complete seamlessly without extra manual steps.
Description: Several wsl-manager actions (e.g., setup-docker, setup-podman, setup-user) require a distribution restart to apply wsl.conf changes. Currently some flows print a message telling the user to terminate the distro manually. The tool should handle this automatically; if an action requires a restart, it should terminate and (if needed) re-launch the distribution without user intervention.
The first commit (be944b4) migrated remove/clone/update/configure-wsl/repair-interop/setup-docker/setup-podman/setup-proxy from raw wsl.exe --terminate to the central Stop-WslDistro helper. A post-merge review surfaced gaps that re-open this story:
lib/wsl/user.ps1:151-154 still calls wsl.exe --terminate $DistroName followed by Start-Sleep -Seconds 2. Only the doc comments at :22-23 and :46-47 were updated to claim "automatically terminated". The code therefore bypasses the retry/verification loop that Stop-WslDistro (and SC-012) added, and user.Tests.ps1 has no assertion guarding the auto-terminate behavior. Replace with Stop-WslDistro -Name $DistroName -Confirm:$false | Out-Null and add a unit test mirroring the pattern at commands.Tests.ps1:1107-1117.
The migration added Stop-WslDistro at lib/wsl/proxy.ps1:212 inside the case-0 (success) arm of the exit-code switch. The entire arm sits inside an outer try { … } catch { Write-Error "Proxy configuration failed: $_"; return $false }. Stop-WslDistro throws after 3 retries (core.ps1:608) when termination cannot be verified. When that happens the user sees "Proxy configuration failed: Failed to terminate distribution …" — even though setup-proxy.sh returned 0 and every config target was written successfully. Wrap the Stop-WslDistro call in its own try/catch that emits a non-fatal Write-Warning and still returns $true. The proxy was configured; only the convenience restart failed.
Pre-migration, manager.docker.Integration.Tests.ps1 had four state-validation tests (update / clone / remove / "after stop"). The migration collapsed these into a single auto-terminate test for update. Clone and remove auto-terminate is now only verified by mocked unit tests, which don't catch issues like Stop-WslDistro polling not converging on the real WSL VM. Add two integration tests paralleling the existing update test — one for clone, one for remove — under the existing "Auto-terminate for Operations" Context block.
lib/wsl/docker.ps1:110-114.NOTESstill tells users "the user must restart the distribution for group membership to take effect: wsl.exe --terminate " — stale since the install auto-terminates.docs/wsl-manager.mddoes not mention thatconfigure-wslnow silently shuts down the entire WSL subsystem (Stop-WslSubsystemis invoked at the end). This is a behavior change beyond per-distro auto-termination and warrants a one-line note for users who runconfigure-wsland don't expect their other distros to be terminated.
The "Next steps" blocks at docker.ps1:294-299 and podman.ps1:329-334 are fine as-is — they correctly tell the user how to launch the distribution after the auto-terminate.
Acceptance Criteria:
- No action prompts the user to manually terminate a distribution
- Actions that require a restart automatically terminate (and re-launch if needed) the distribution (remove, clone, update, configure-wsl, repair-interop, setup-docker, setup-podman, setup-proxy, setup-user migrated)
-
lib/wsl/user.ps1New-WslUserusesStop-WslDistroinstead of rawwsl.exe --terminate, andStart-Sleep -Seconds 2is removed -
user.Tests.ps1includes a test assertingStop-WslDistrois invoked after a successful user creation -
Install-WslProxyreturns$trueand emits aWrite-Warning(notWrite-Error) whensetup-proxy.shexits 0 butStop-WslDistrothrows - Pester test in
proxy.Tests.ps1asserts the above behavior - Integration test added: clone auto-terminates the source distribution when running and completes successfully
- Integration test added: remove auto-terminates the distribution when running and completes successfully
-
lib/wsl/docker.ps1.NOTESno longer tells users to manually terminate after install -
docs/wsl-manager.mdnotes theconfigure-wslsubsystem-wide shutdown side effect - All existing tests continue to pass