[REFACT-005] ✅ DONE - Extract Assert-WslDistroExists guard to replace inline distro validation (DRY)
Status: Done (2026-02-24)
Priority: Medium
Component: tools/pslib/wsl/ (7 source files, 7 test files)
Related: REFACT-004 (same pattern — entry-point guard extraction)
Description:
Extracted throwing Assert-WslDistroExists and Assert-WslDistroNotExists guard functions into core.ps1 and replaced 22 inline distro-existence validation patterns (trim + Get-WslDistroList + -notin + throw) across 7 source files. Also absorbed .Trim() into Test-WslDistroExists. Error messages now consistently include the list of installed distributions. Following the Assert-Wsl2Installed pattern from REFACT-004.
Acceptance Criteria:
-
Test-WslDistroExistsabsorbs.Trim()internally - New
Assert-WslDistroExistsfunction with unit tests - New
Assert-WslDistroNotExistsfunction with unit tests - All 22 inline distro-existence checks replaced (including the 2 enhanced-message sites and the inverse check)
- Redundant
$DistroName.Trim()/$Name.Trim()calls removed where they only served the validation -
Test-WslDistroExists(boolean) remains available for non-throwing use - Error message always includes installed distros list:
"Distribution '<name>' does not exist. Installed distributions: <list>" - All tests pass (mock updates only, no behavior change)
- No change in user-facing behavior