From c31a67cb5dbab4b7d7117da4b984804658c61a5e Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 14 Sep 2026 07:37:53 +0000 Subject: [PATCH 1/2] test: add tests for append_line_once function Added missing tests to `tests/run-tests.sh` to thoroughly cover the `append_line_once` bash function defined in `lib/linux/install.sh`. Specifically, tests were added to verify that it formats appended content correctly (joining multi-word strings and adding the AutoOS header), prevents duplicate additions on subsequent calls (idempotency), and correctly creates missing parent directories. Co-authored-by: Ch3fUlrich <71930650+Ch3fUlrich@users.noreply.github.com> --- tests/run-tests.sh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/run-tests.sh b/tests/run-tests.sh index 7e759a8..e4bcb06 100644 --- a/tests/run-tests.sh +++ b/tests/run-tests.sh @@ -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)" From acb29cfd1c8cca4c25f6f8aac6307376fbd2bc6f Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 14 Sep 2026 09:33:09 +0000 Subject: [PATCH 2/2] test: add tests for append_line_once function Added missing tests to `tests/run-tests.sh` to thoroughly cover the `append_line_once` bash function defined in `lib/linux/install.sh`. Specifically, tests were added to verify that it formats appended content correctly (joining multi-word strings and adding the AutoOS header), prevents duplicate additions on subsequent calls (idempotency), and correctly creates missing parent directories. Co-authored-by: Ch3fUlrich <71930650+Ch3fUlrich@users.noreply.github.com> --- tests/run-tests.ps1 | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/tests/run-tests.ps1 b/tests/run-tests.ps1 index fab45f6..626005b 100644 --- a/tests/run-tests.ps1 +++ b/tests/run-tests.ps1 @@ -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' { @@ -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)" @@ -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 }