Skip to content

Commit 2795fa4

Browse files
bolenscursoragent
andcommitted
fix(test): keep Get-TestRepoRoot self-contained after global promote
Inlining repo-root markers so promoted Function:\global:Get-TestRepoRoot no longer depends on a sibling helper missing from Pester containers. Also mark the Arch workspace as a git safe.directory. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 2993b5b commit 2795fa4

4 files changed

Lines changed: 34 additions & 29 deletions

File tree

.github/workflows/ci-powershell.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ jobs:
6666
pacman -Sy --noconfirm
6767
pacman -S --noconfirm git
6868
- uses: actions/checkout@v7
69+
- name: Trust workspace for git (Arch container)
70+
if: matrix.label == 'arch-latest'
71+
shell: bash
72+
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
6973
- name: Setup Arch Linux
7074
if: matrix.label == 'arch-latest'
7175
uses: ./.github/actions/setup-arch-linux

.github/workflows/test-pester.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ jobs:
101101
pacman -Sy --noconfirm
102102
pacman -S --noconfirm git
103103
- uses: actions/checkout@v7
104+
- name: Trust workspace for git (Arch container)
105+
if: matrix.label == 'arch-latest'
106+
shell: bash
107+
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
104108
- name: Setup Arch Linux
105109
if: matrix.label == 'arch-latest'
106110
uses: ./.github/actions/setup-arch-linux

.github/workflows/validate-profile.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,11 @@ jobs:
201201
- name: Checkout
202202
uses: actions/checkout@v7
203203

204+
- name: Trust workspace for git (Arch container)
205+
if: matrix.label == 'arch-latest'
206+
shell: bash
207+
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
208+
204209
- name: Setup PowerShell (Debian/Ubuntu)
205210
if: matrix.label == 'ubuntu-latest'
206211
run: |

tests/TestSupport/TestPaths.ps1

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,16 @@
33
# Test path resolution and directory utilities
44
# ===============================================
55

6-
<#
7-
.SYNOPSIS
8-
Returns $true when a directory looks like this repository's root.
9-
.DESCRIPTION
10-
Accepts a real Git checkout (.git present) or an archive-style checkout
11-
(profile entrypoint + profile.d), which GitHub Actions uses when git is
12-
missing from the job container PATH at checkout time.
13-
#>
14-
function Test-TestRepoRootMarker {
15-
param(
16-
[Parameter(Mandatory)]
17-
[string]$Path
18-
)
19-
20-
if ([string]::IsNullOrWhiteSpace($Path)) {
21-
return $false
22-
}
23-
24-
if (Test-Path -LiteralPath (Join-Path $Path '.git')) {
25-
return $true
26-
}
27-
28-
$profileScript = Join-Path $Path 'Microsoft.PowerShell_profile.ps1'
29-
$profileDir = Join-Path $Path 'profile.d'
30-
return (Test-Path -LiteralPath $profileScript) -and (Test-Path -LiteralPath $profileDir)
31-
}
32-
336
<#
347
.SYNOPSIS
358
Locates the repository root directory for the tests.
369
.DESCRIPTION
3710
Prefers GITHUB_WORKSPACE / PS_PROFILE_REPO_ROOT when they point at this repo,
3811
then walks up from the supplied start path until it finds a .git entry or the
3912
profile markers (archive checkouts without .git).
13+
14+
Marker logic is inlined so this function stays self-contained after promotion
15+
to Function:\global:Get-TestRepoRoot (Pester containers).
4016
.PARAMETER StartPath
4117
The path to begin searching from; defaults to the calling script root.
4218
.OUTPUTS
@@ -48,16 +24,32 @@ function Get-TestRepoRoot {
4824
[string]$StartPath = $PSScriptRoot
4925
)
5026

27+
function Test-RepoRootMarkerLocal {
28+
param([string]$Path)
29+
30+
if ([string]::IsNullOrWhiteSpace($Path)) {
31+
return $false
32+
}
33+
34+
if (Test-Path -LiteralPath (Join-Path $Path '.git')) {
35+
return $true
36+
}
37+
38+
$profileScript = Join-Path $Path 'Microsoft.PowerShell_profile.ps1'
39+
$profileDir = Join-Path $Path 'profile.d'
40+
return (Test-Path -LiteralPath $profileScript) -and (Test-Path -LiteralPath $profileDir)
41+
}
42+
5143
foreach ($envName in @('PS_PROFILE_REPO_ROOT', 'GITHUB_WORKSPACE')) {
5244
$candidate = [Environment]::GetEnvironmentVariable($envName)
53-
if ($candidate -and (Test-TestRepoRootMarker -Path $candidate)) {
45+
if ($candidate -and (Test-RepoRootMarkerLocal -Path $candidate)) {
5446
return ([System.IO.Path]::GetFullPath($candidate))
5547
}
5648
}
5749

5850
$current = Get-Item -LiteralPath $StartPath
5951
while ($null -ne $current) {
60-
if (Test-TestRepoRootMarker -Path $current.FullName) {
52+
if (Test-RepoRootMarkerLocal -Path $current.FullName) {
6153
return $current.FullName
6254
}
6355
$current = $current.Parent

0 commit comments

Comments
 (0)