Skip to content

Commit 7f16512

Browse files
bolenscursoragent
andcommitted
fix(test): make Arch CI isolation and platform assertions pass
Use read mocks when running as root (chmod 000 is ineffective), stop short-circuiting Get-TestRepoRoot via GITHUB_WORKSPACE, accept pacman in install-hint fallbacks, and tolerate empty PATH as null on Unix. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 2795fa4 commit 7f16512

5 files changed

Lines changed: 31 additions & 13 deletions

File tree

profile.d/utilities-modules/system/utilities-env.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,9 @@ function Remove-Path {
303303
Set-EnvVar -Name 'PATH' -Value $newPath -Global
304304
}
305305
else {
306-
$env:PATH = $newPath
306+
# Prefer empty string over $null so consumers comparing to '' stay consistent;
307+
# on Unix, assigning '' may still clear the process env entry.
308+
$env:PATH = if ($null -eq $newPath) { '' } else { $newPath }
307309
}
308310
}
309311

tests/TestSupport/TestPaths.ps1

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@
77
.SYNOPSIS
88
Locates the repository root directory for the tests.
99
.DESCRIPTION
10-
Prefers GITHUB_WORKSPACE / PS_PROFILE_REPO_ROOT when they point at this repo,
11-
then walks up from the supplied start path until it finds a .git entry or the
12-
profile markers (archive checkouts without .git).
10+
Prefers an explicit PS_PROFILE_REPO_ROOT when set, then walks up from the
11+
supplied start path until it finds a .git entry or the profile markers
12+
(archive checkouts without .git).
1313
1414
Marker logic is inlined so this function stays self-contained after promotion
1515
to Function:\global:Get-TestRepoRoot (Pester containers).
16+
17+
GITHUB_WORKSPACE is intentionally not used as a short-circuit: CI always sets
18+
it, which would make isolation tests that start outside the repo succeed
19+
incorrectly.
1620
.PARAMETER StartPath
1721
The path to begin searching from; defaults to the calling script root.
1822
.OUTPUTS
@@ -40,11 +44,9 @@ function Get-TestRepoRoot {
4044
return (Test-Path -LiteralPath $profileScript) -and (Test-Path -LiteralPath $profileDir)
4145
}
4246

43-
foreach ($envName in @('PS_PROFILE_REPO_ROOT', 'GITHUB_WORKSPACE')) {
44-
$candidate = [Environment]::GetEnvironmentVariable($envName)
45-
if ($candidate -and (Test-RepoRootMarkerLocal -Path $candidate)) {
46-
return ([System.IO.Path]::GetFullPath($candidate))
47-
}
47+
$explicitRoot = [Environment]::GetEnvironmentVariable('PS_PROFILE_REPO_ROOT')
48+
if ($explicitRoot -and (Test-RepoRootMarkerLocal -Path $explicitRoot)) {
49+
return ([System.IO.Path]::GetFullPath($explicitRoot))
4850
}
4951

5052
$current = Get-Item -LiteralPath $StartPath

tests/integration/bootstrap/preference-aware-install-hints-fallback.tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ Describe 'Preference-Aware Install Hints - Integration Tests (Fallback Chains)'
151151
$result = Get-PreferenceAwareInstallHint -ToolName 'generic-tool-xyz' -ToolType 'generic'
152152
$result | Should -Not -BeNullOrEmpty
153153
# Should suggest system package manager
154-
$result | Should -Match 'scoop|brew|apt|winget|choco'
154+
$result | Should -Match 'scoop|brew|apt|winget|choco|pacman|yum|dnf'
155155
}
156156

157157
It 'Falls back from tool-specific to language-specific to system' {

tests/integration/system/environment-variables.tests.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ Describe 'Environment Variables Integration Tests' {
9595
$originalPath = $env:PATH
9696
$env:PATH = 'C:\SinglePath'
9797
Remove-Path -Path 'C:\SinglePath'
98-
$env:PATH | Should -Be ''
98+
# Unix PowerShell clears the variable when assigned ''; Windows keeps ''.
99+
($null -eq $env:PATH -or $env:PATH -eq '') | Should -Be $true
99100
}
100101
finally {
101102
$env:PATH = $originalPath

tests/unit/library/fragment/library-fragment-loading-extended.tests.ps1

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,32 @@ function script:Get-FragmentTierResult {
4141
function script:Simulate-UnreadableFragmentFile {
4242
<#
4343
.SYNOPSIS
44-
Make a fragment unreadable for parse-failure tests (chmod on Unix; module Mock on Windows).
44+
Make a fragment unreadable for parse-failure tests (chmod on Unix; module Mock on Windows/root).
4545
#>
4646
param(
4747
[Parameter(Mandatory)]
4848
[string]$Path
4949
)
5050

51+
$runningAsRoot = $false
5152
if ($IsLinux -or $IsMacOS) {
53+
try {
54+
$uid = & id -u 2>$null
55+
$runningAsRoot = ($uid -eq '0')
56+
}
57+
catch {
58+
$runningAsRoot = $false
59+
}
60+
}
61+
62+
# Non-root Unix: chmod 000 blocks reads. Root (e.g. Arch CI containers) can still
63+
# read mode-000 files, so fall through to the same mocks Windows uses.
64+
if (($IsLinux -or $IsMacOS) -and -not $runningAsRoot) {
5265
chmod 000 $Path
5366
return 'chmod'
5467
}
5568

56-
# Windows cannot chmod away readability; force the module read path to fail.
69+
# Windows / root Unix: force the module read path to fail.
5770
# Ensure Read-FileContent is resolvable before Mock — FileContent may not be loaded
5871
# in every shard ordering, and Pester 5 cannot mock a missing command.
5972
if (-not (Get-Command Read-FileContent -ErrorAction SilentlyContinue)) {

0 commit comments

Comments
 (0)