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