Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/windows/AutoOS.ClaudeAutostart.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = @() }
}
Expand Down
20 changes: 12 additions & 8 deletions lib/windows/AutoOS.Detect.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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 }
}
Expand All @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions lib/windows/AutoOS.Serve.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
@{}
}

Expand All @@ -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
}
Expand Down
22 changes: 17 additions & 5 deletions tests/run-tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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' {
Expand Down
44 changes: 44 additions & 0 deletions tests/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down