diff --git a/lib/windows/AutoOS.ClaudeAutostart.psm1 b/lib/windows/AutoOS.ClaudeAutostart.psm1 index 98c4a9f..551ad66 100644 --- a/lib/windows/AutoOS.ClaudeAutostart.psm1 +++ b/lib/windows/AutoOS.ClaudeAutostart.psm1 @@ -43,7 +43,7 @@ function Get-AutoOSClaudeDefaults { foreach ($p in $block.PSObject.Properties) { $table[$p.Name] = $p.Value } if ($table.Count -gt 0) { return $table } } - } catch { } + } catch { Write-Verbose $_.Exception.Message } } @{ enabled = $true; snapshot_interval_mins = 5; liveness_window_mins = 240 @@ -272,7 +272,7 @@ function Get-AutoOSClaudeState { sessions = @($doc.sessions) } } - } catch { } + } catch { Write-Verbose $_.Exception.Message } } [pscustomobject]@{ version = $script:StateVersion; captured_at = 0; captured_at_iso = $null; sessions = @() } } diff --git a/lib/windows/AutoOS.Detect.psm1 b/lib/windows/AutoOS.Detect.psm1 index b1934ec..a6dccd8 100644 --- a/lib/windows/AutoOS.Detect.psm1 +++ b/lib/windows/AutoOS.Detect.psm1 @@ -40,20 +40,24 @@ function Get-AutoOSShimDirectory { not necessarily written itself there, and a per-user shim directory is only on PATH for the user who ran the installer. #> - $home_ = $env:USERPROFILE + $home_ = if ($env:USERPROFILE) { $env:USERPROFILE } else { $env:HOME } + $progData = if ($env:ProgramData) { $env:ProgramData } else { 'C:\ProgramData' } + $localApp = if ($env:LOCALAPPDATA) { $env:LOCALAPPDATA } else { $(Join-Path $home_ 'AppData\Local') } + $progFiles = if ($env:ProgramFiles) { $env:ProgramFiles } else { 'C:\Program Files' } + $appData = if ($env:APPDATA) { $env:APPDATA } else { $(Join-Path $home_ 'AppData\Roaming') } @( # Scoop: user-scope by default, global when SCOOP_GLOBAL is set. (Join-Path $home_ 'scoop\shims'), $(if ($env:SCOOP) { Join-Path $env:SCOOP 'shims' }), $(if ($env:SCOOP_GLOBAL) { Join-Path $env:SCOOP_GLOBAL 'shims' }), - (Join-Path $env:ProgramData 'scoop\shims'), + (Join-Path $progData 'scoop\shims'), # Chocolatey. - (Join-Path $env:ProgramData 'chocolatey\bin'), + (Join-Path $progData 'chocolatey\bin'), # winget's own shim directory for portable packages. - (Join-Path $env:LOCALAPPDATA 'Microsoft\WinGet\Links'), - (Join-Path $env:ProgramFiles 'WinGet\Links'), + (Join-Path $localApp 'Microsoft\WinGet\Links'), + (Join-Path $progFiles 'WinGet\Links'), # npm -g, pipx/uv and cargo all install here and all rely on PATH. - (Join-Path $env:APPDATA 'npm'), + (Join-Path $appData 'npm'), (Join-Path $home_ '.local\bin'), (Join-Path $home_ '.cargo\bin'), (Join-Path $home_ 'bin') @@ -122,7 +126,7 @@ function Get-AutoOSWingetPackageProcess { $process = [Diagnostics.Process]::Start($psi) # Close stdin so a prompt that slipped past --disable-interactivity reads # EOF and gives up, instead of sitting there until the timeout. - try { $process.StandardInput.Close() } catch { } + try { $process.StandardInput.Close() } catch { Write-Verbose $_.Exception.Message } $process } catch { $null } } @@ -144,7 +148,7 @@ function Get-AutoOSWingetPackageResult { $Process.Kill() } } catch { $packages = @() } - finally { try { $Process.Dispose() } catch { } } + finally { try { $Process.Dispose() } catch { Write-Verbose $_.Exception.Message } } $packages } diff --git a/lib/windows/AutoOS.Serve.psm1 b/lib/windows/AutoOS.Serve.psm1 index f732bf6..6c7420e 100644 --- a/lib/windows/AutoOS.Serve.psm1 +++ b/lib/windows/AutoOS.Serve.psm1 @@ -266,7 +266,7 @@ function Get-AutoOSExampleBlock { try { $block = (Get-Content -LiteralPath $path -Raw -Encoding UTF8 | ConvertFrom-Json).$Name if ($block) { return $block } - } catch { } + } catch { Write-Verbose $_.Exception.Message } @{} } @@ -286,7 +286,7 @@ function Get-AutoOSDetectedAnswers { try { $value = (& git config --global $pair.Setting 2>$null | Select-Object -First 1) if ($value) { $answers[$pair.Key] = [string]$value } - } catch { } + } catch { Write-Verbose $_.Exception.Message } } $answers } diff --git a/tests/run-tests.ps1 b/tests/run-tests.ps1 index fab45f6..114a3e3 100644 --- a/tests/run-tests.ps1 +++ b/tests/run-tests.ps1 @@ -303,13 +303,25 @@ Test-Case 'a different product sharing a prefix is never matched' { } Test-Case 'the shim directories package managers use are probed even when PATH is stale' { - $dirs = @(Get-AutoOSShimDirectory) - foreach ($want in @('scoop\shims', 'chocolatey\bin', 'Microsoft\WinGet\Links')) { - if (-not @($dirs | Where-Object { $_ -like "*$want*" })) { - throw "no probe directory for $want in: $($dirs -join '; ')" + $env_USERPROFILE_backup = $env:USERPROFILE + $env_ProgramData_backup = $env:ProgramData + $env_LOCALAPPDATA_backup = $env:LOCALAPPDATA + $env:USERPROFILE = if ($env:USERPROFILE) { $env:USERPROFILE } else { 'C:\Users\runneradmin' } + $env:ProgramData = if ($env:ProgramData) { $env:ProgramData } else { 'C:\ProgramData' } + $env:LOCALAPPDATA = if ($env:LOCALAPPDATA) { $env:LOCALAPPDATA } else { 'C:\Users\runneradmin\AppData\Local' } + try { + $dirs = @(Get-AutoOSShimDirectory) + foreach ($want in @('scoop\shims', 'chocolatey\bin', 'Microsoft\WinGet\Links')) { + if (-not @($dirs | Where-Object { $_ -like "*$want*" })) { + throw "no probe directory for $want in: $($dirs -join '; ')" + } } + Pass + } finally { + $env:USERPROFILE = $env_USERPROFILE_backup + $env:ProgramData = $env_ProgramData_backup + $env:LOCALAPPDATA = $env_LOCALAPPDATA_backup } - Pass } Test-Case 'a shim directory off the persistent PATH still resolves a verify command' { diff --git a/tests/run-tests.sh b/tests/run-tests.sh index 7e759a8..f3fbb70 100644 --- a/tests/run-tests.sh +++ b/tests/run-tests.sh @@ -905,6 +905,50 @@ if it "the payload carries the platform list"; then grep -q "component_platforms" lib/linux/serve.py && pass || fail "serve.py does not compute platforms" fi +if it "component_platforms computes cross-platform availability correctly"; then + if python3 - <<'PY' +import sys, os, pathlib, json, tempfile +sys.path.insert(0, './lib/linux') + +with tempfile.TemporaryDirectory() as tmpdir: + import serve + serve.ROOT = pathlib.Path(tmpdir) + cat_dir = serve.ROOT / "catalog" + cat_dir.mkdir() + + # Create fake catalogs + windows = {"categories": [{"components": [{"id": "c1"}, {"id": "c2"}]}]} + linux = {"categories": [{"components": [{"id": "c2"}, {"id": "c3"}]}]} + macos = {"categories": [{"components": [{"id": "c1"}, {"id": "c3"}]}]} + + (cat_dir / "windows.json").write_text(json.dumps(windows), encoding="utf-8") + (cat_dir / "linux.json").write_text(json.dumps(linux), encoding="utf-8") + (cat_dir / "macos.json").write_text(json.dumps(macos), encoding="utf-8") + + sys.argv = ["serve.py"] + + serve._PLATFORMS_CACHE = None + res = serve.component_platforms() + + if sorted(res.keys()) != ["c1", "c2", "c3"]: + print("keys wrong:", res, file=sys.stderr) + sys.exit(1) + + if sorted(res["c1"]) != sorted(["macos", "windows"]): + print("c1 wrong:", res["c1"], file=sys.stderr) + sys.exit(1) + + if sorted(res["c2"]) != sorted(["linux", "windows"]): + print("c2 wrong:", res["c2"], file=sys.stderr) + sys.exit(1) + + if sorted(res["c3"]) != sorted(["linux", "macos"]): + print("c3 wrong:", res["c3"], file=sys.stderr) + sys.exit(1) +PY + then pass; else fail "component_platforms returned incorrect mappings"; fi +fi + if it "Handy is offered on every platform"; then n="$(grep -l '"id": "handy"' catalog/*.json | wc -l)" assert_eq "$n" "3"