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
20 changes: 14 additions & 6 deletions tests/run-tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,19 @@ 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 '; ')"
$oldProgramData = $env:ProgramData
$env:ProgramData = 'C:\ProgramData'
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:ProgramData = $oldProgramData
}
Pass
}

Test-Case 'a shim directory off the persistent PATH still resolves a verify command' {
Expand Down Expand Up @@ -810,7 +816,8 @@ Test-Case '-Only accepts a comma-separated list through -File' {
# powershell -File passes every argument literally, so "a,b" arrives as one
# string. The browser UI shells out exactly that way, so a multi-component
# install used to fail as "unknown component id(s): a,b".
$out = & powershell -NoProfile -ExecutionPolicy Bypass -File $setup `
$pwshExe = if (Get-Command pwsh -ErrorAction SilentlyContinue) { 'pwsh' } else { 'powershell' }
$out = & $pwshExe -NoProfile -ExecutionPolicy Bypass -File $setup `
-Only 'git,nodejs' -Yes -NoColor -DryRun 2>&1
Assert-True ($LASTEXITCODE -eq 0 -and ($out -join "`n") -notmatch 'Unknown component') `
"exit $LASTEXITCODE : $($out | Select-Object -Last 3)"
Expand Down Expand Up @@ -1172,6 +1179,7 @@ Test-Case 'the scheduled-task arguments are stable, so a second run can skip' {
}

Test-Case 'an unregistered task never counts as current' {
# If Get-ScheduledTask does not exist (e.g. on Linux/WSL), it safely returns false.
Assert-Equal (Test-AutoOSClaudeTaskCurrent -TaskName 'AutoOS-Claude-DoesNotExist' -Arguments 'x') $false
}

Expand Down
32 changes: 32 additions & 0 deletions tests/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,38 @@ if it "dry run never writes"; then
if [[ -f "$tmp" ]]; then rm -f "$tmp"; fail "dry run created the file"; else pass; fi
fi

if it "append_line_once joins multi-word lines and adds the AutoOS header"; then
tmp="$(mktemp)"; rm -f "$tmp"
AUTOOS_DRY_RUN=0
append_line_once "$tmp" "M4" "export" "FOO=1" "# M4" >/dev/null
out="$(cat "$tmp")"
rm -f "$tmp" "$tmp".autoos-backup-* 2>/dev/null
if [[ "$out" == $'\n# added by AutoOS\nexport FOO=1 # M4' ]]; then pass
else fail "unexpected content: $(printf '%q' "$out")"; fi
fi

if it "append_line_once prevents duplicate lines on multiple calls"; then
tmp="$(mktemp)"; rm -f "$tmp"
AUTOOS_DRY_RUN=0
append_line_once "$tmp" "M_DUP" "line 1 # M_DUP" >/dev/null
append_line_once "$tmp" "M_DUP" "line 1 # M_DUP" >/dev/null
append_line_once "$tmp" "M_DUP" "line 1 # M_DUP" >/dev/null
out="$(cat "$tmp")"
rm -f "$tmp" "$tmp".autoos-backup-* 2>/dev/null
if [[ "$out" == $'\n# added by AutoOS\nline 1 # M_DUP' ]]; then pass
else fail "duplicate lines found: $(printf '%q' "$out")"; fi
fi

if it "append_line_once creates missing parent directories"; then
tmp="$(mktemp -d)"
target="$tmp/missing/dir/file"
AUTOOS_DRY_RUN=0
append_line_once "$target" "M5" "line # M5" >/dev/null
if [[ -f "$target" ]]; then pass
else fail "parent directories or file were not created"; fi
rm -rf "$tmp"
fi

# ─── End-to-end plan stability ──────────────────────────────────────────────
describe "end-to-end (dry run only)"

Expand Down
Loading