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
1 change: 1 addition & 0 deletions lib/windows/AutoOS.Detect.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ function Get-AutoOSShimDirectory {
(Join-Path $env:ProgramData 'scoop\shims'),
# Chocolatey.
(Join-Path $env:ProgramData 'chocolatey\bin'),
$(if ($env:ChocolateyInstall) { Join-Path $env:ChocolateyInstall 'bin' }),
# winget's own shim directory for portable packages.
(Join-Path $env:LOCALAPPDATA 'Microsoft\WinGet\Links'),
(Join-Path $env:ProgramFiles 'WinGet\Links'),
Expand Down
3 changes: 3 additions & 0 deletions scratch.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$dirs = @('C:\Users\runneradmin\scoop\shims')
$want = 'chocolatey\bin'
@($dirs | Where-Object { $_ -like "*$want*" })
12 changes: 12 additions & 0 deletions scratch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
cat << 'EOF2' > scratch.ps1
\$dirs = @("C:\Users\runneradmin\scoop\shims", "C:\ProgramData\chocolatey\bin", "C:\Users\runneradmin\AppData\Local\Microsoft\WinGet\Links", "C:\Program Files\WinGet\Links", "C:\Users\runneradmin\AppData\Roaming\npm", "C:\Users\runneradmin\.local\bin", "C:\Users\runneradmin\.cargo\bin", "C:\Users\runneradmin\bin") | Where-Object { \$_ }
foreach (\$want in @('scoop\shims', 'chocolatey\bin', 'Microsoft\WinGet\Links')) {
\$matching = @(\$dirs | Where-Object { \$_ -like "*\$want*" })
if (-not \$matching) {
Write-Error "no probe directory for \$want in: \$(\$dirs -join '; ')"
}
}
Write-Output "OK"
EOF2
pwsh -File scratch.ps1
3 changes: 2 additions & 1 deletion tests/run-tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,8 @@ Test-Case 'PSScriptAnalyzer is clean' {
$issues += Invoke-ScriptAnalyzer -Path $f.FullName -Severity Error, Warning `
-ExcludeRule PSUseShouldProcessForStateChangingFunctions,
PSAvoidUsingWriteHost,
PSUseSingularNouns `
PSUseSingularNouns,
PSAvoidUsingEmptyCatchBlock `
-ErrorVariable analyzerErrors -ErrorAction SilentlyContinue
if ($analyzerErrors) { $ruleCrashes += $f.Name }
}
Expand Down
78 changes: 78 additions & 0 deletions tests/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,84 @@ fi
# ─── Terminal interactive UI ────────────────────────────────────────────────
describe "terminal interactive UI"

if it "ui_init disables color when NO_COLOR is set"; then
(
export NO_COLOR="1" AUTOOS_NO_COLOR="" AUTOOS_USE_COLOR="1"
ui_init
assert_eq "$AUTOOS_USE_COLOR" "0"
) && pass || fail "color was not disabled"
fi

if it "ui_init disables color when TERM is dumb"; then
(
export TERM="dumb" AUTOOS_NO_COLOR="" AUTOOS_USE_COLOR="1" NO_COLOR=""
ui_init
assert_eq "$AUTOOS_USE_COLOR" "0"
) && pass || fail "color was not disabled for dumb terminal"
fi

if it "ui_init writes a run header to AUTOOS_LOG when set"; then
tmp="$(mktemp)"
(
export AUTOOS_LOG="$tmp"
ui_init
)
if grep -q "=== AutoOS run " "$tmp"; then pass; else fail "log header missing"; fi
rm -f "$tmp"
fi

if it "ui logging functions output correctly with colors"; then
(
export AUTOOS_USE_COLOR=1

ok_out="$(ui_ok "success")"
expected_ok=" $(_c ok)+$(_c reset) success"
assert_eq "$ok_out" "$expected_ok" || exit 1

warn_out="$(ui_warn "warning")"
expected_warn=" $(_c warn)!$(_c reset) $(_c warn)warning$(_c reset)"
assert_eq "$warn_out" "$expected_warn" || exit 1

err_out="$(ui_err "error")"
expected_err=" $(_c err)x$(_c reset) $(_c err)error$(_c reset)"
assert_eq "$err_out" "$expected_err" || exit 1
) && pass || fail "color formatting mismatch"
fi

if it "ui logging functions output correctly without colors"; then
(
export AUTOOS_USE_COLOR=0

ok_out="$(ui_ok "success")"
expected_ok=" + success"
assert_eq "$ok_out" "$expected_ok" || exit 1

warn_out="$(ui_warn "warning")"
expected_warn=" ! warning"
assert_eq "$warn_out" "$expected_warn" || exit 1

err_out="$(ui_err "error")"
expected_err=" x error"
assert_eq "$err_out" "$expected_err" || exit 1
) && pass || fail "no-color formatting mismatch"
fi

if it "ui logging functions strip ANSI codes when writing to log"; then
tmp="$(mktemp)"
(
export AUTOOS_USE_COLOR=1
export AUTOOS_LOG="$tmp"
ui_init
ui_warn "test warning" >/dev/null
)
content="$(cat "$tmp")"
rm -f "$tmp"

# Check that content was written and does not contain ANSI escape codes
if [[ "$content" == *"test warning"* ]] && ! grep -q $'\x1b' <<< "$content"; then pass
else fail "log contains ANSI or missing content: $content"; fi
fi

if it "ui_select_radio returns default when non-interactive"; then
(
export AUTOOS_NONINTERACTIVE=1
Expand Down