Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Define everything Refresh-Environment calls before the PSModulePath test runs it (#11194)

Daniel Handc151ddd44d2
diff --git a/tests/studio/test_psmodulepath_normalization.ps1 b/tests/studio/test_psmodulepath_normalization.ps1
index a5ff619ed46..1b6225d879a 100644
--- a/tests/studio/test_psmodulepath_normalization.ps1
+++ b/tests/studio/test_psmodulepath_normalization.ps1
@@ -58,13 +58,42 @@ Check "exactly one Refresh-Environment" ($fn.Count -eq 1)
$fnText = $fn[0].Extent.Text
Check "it skips PSModulePath as well as Path" ($fnText -match "\`$key -eq 'PSModulePath'")
-# Behavioural: the registry reload must not clobber a value already normalized.
-# On non-Windows GetEnvironmentVariables('Machine') is empty, so this leg only
-# proves the function is callable there; the AST check above is what holds the
-# line cross-platform.
+# Everything Refresh-Environment calls, computed rather than listed. Off Windows the body returns
+# before reaching Test-ActiveCondaEnvironment, so a missing definition only shows on the one host
+# this leg does anything on, and a listed closure would go stale unnoticed.
+$setupFunctions = @{}
+foreach ($f in $setupAst.FindAll({ param($n)
+ $n -is [System.Management.Automation.Language.FunctionDefinitionAst] }, $true)) {
+ $setupFunctions[$f.Name] = $f.Extent.Text
+}
+$needed = [ordered]@{}
+$pending = [System.Collections.Generic.Queue[string]]::new()
+$pending.Enqueue("Refresh-Environment")
+$seen = @{ "Refresh-Environment" = $true }
+while ($pending.Count -gt 0) {
+ $current = $pending.Dequeue()
+ $body = $setupFunctions[$current]
+ if (-not $body) { continue }
+ # Comments dropped: a function named in prose is not a call.
+ $code = ($body -split "`r?`n" | Where-Object { -not ($_.TrimStart().StartsWith("#")) }) -join "`n"
+ foreach ($name in $setupFunctions.Keys) {
+ if ($seen[$name]) { continue }
+ if ($code -match ("(?<![\w-])" + [regex]::Escape($name) + "(?![\w-])")) {
+ $seen[$name] = $true
+ $needed[$name] = $true
+ $pending.Enqueue($name)
+ }
+ }
+}
+Check "the closure found Refresh-Environment's own helpers (bites)" ($needed.Count -ge 1)
+
+# The registry reload must not clobber a value already normalized. Off Windows the machine
+# environment block is empty, so this leg only proves the function is callable; the AST check
+# above is what holds the line cross-platform.
$savedPath = $env:Path
$savedModulePath = $env:PSModulePath
try {
+ foreach ($name in $needed.Keys) { Invoke-Expression $setupFunctions[$name] }
Invoke-Expression $fnText
$sentinel = "C:\__unsloth_sentinel__;C:\Windows\System32\WindowsPowerShell\v1.0\Modules"
$env:PSModulePath = $sentinel