33# --- Helpers ---------------------------------------------------------------
44
55function Get-RepoRoot {
6- # Prefer PSScriptRoot; fall back to PSCommandPath; finally env var or CWD.
7- $testDir = $PSScriptRoot
8- if (-not $testDir -and $PSCommandPath ) { $testDir = Split-Path - Parent $PSCommandPath }
9- if (-not $testDir ) { $testDir = $PWD }
10- try {
11- return (Resolve-Path - LiteralPath (Join-Path $testDir ' ..\..' )).ProviderPath
12- } catch {
13- # Last resort: assume current workspace from CI
14- if ($env: GITHUB_WORKSPACE ) { return $env: GITHUB_WORKSPACE }
15- return $PWD
6+ # Multiple fallback methods for finding the repository root
7+ $candidates = @ ()
8+
9+ # Method 1: From PSScriptRoot (when running from .github/tests)
10+ if ($PSScriptRoot ) {
11+ $candidates += (Join-Path $PSScriptRoot ' ..\..' )
1612 }
13+
14+ # Method 2: From PSCommandPath
15+ if ($PSCommandPath ) {
16+ $candidates += (Join-Path (Split-Path - Parent $PSCommandPath ) ' ..\..' )
17+ }
18+
19+ # Method 3: From current working directory
20+ $candidates += $PWD
21+
22+ # Method 4: From GitHub Actions workspace
23+ if ($env: GITHUB_WORKSPACE ) {
24+ $candidates += $env: GITHUB_WORKSPACE
25+ }
26+
27+ # Method 5: Look for Scripts directory in current and parent directories
28+ $currentDir = $PWD
29+ for ($i = 0 ; $i -lt 5 ; $i ++ ) {
30+ $candidates += $currentDir
31+ $currentDir = Split-Path - Parent $currentDir
32+ if ([string ]::IsNullOrEmpty($currentDir ) -or $currentDir -eq (Split-Path - Parent $currentDir )) {
33+ break
34+ }
35+ }
36+
37+ # Try each candidate
38+ foreach ($candidate in $candidates ) {
39+ if ($candidate -and (Test-Path $candidate )) {
40+ try {
41+ $resolved = (Resolve-Path - LiteralPath $candidate ).ProviderPath
42+ # Check if this directory contains a Scripts folder
43+ if (Test-Path (Join-Path $resolved ' Scripts' )) {
44+ return $resolved
45+ }
46+ } catch {
47+ # Continue to next candidate
48+ }
49+ }
50+ }
51+
52+ # Last resort: return current working directory
53+ return $PWD
1754}
1855
1956function Find-First ([string []]$candidates ) {
@@ -35,17 +72,45 @@ function Test-Syntax([string]$path) {
3572$RepoRoot = Get-RepoRoot
3673$ScriptsDir = Join-Path $RepoRoot ' Scripts'
3774
75+ # Debug output
76+ Write-Host " === DEBUG PATH RESOLUTION ===" - ForegroundColor Yellow
77+ Write-Host " PSScriptRoot: $PSScriptRoot " - ForegroundColor Cyan
78+ Write-Host " RepoRoot: $RepoRoot " - ForegroundColor Cyan
79+ Write-Host " ScriptsDir: $ScriptsDir " - ForegroundColor Cyan
80+ Write-Host " ScriptsDir exists: $ ( Test-Path $ScriptsDir ) " - ForegroundColor Green
81+
3882# Try specific names first; then a recursive fallback (covers accidental renames)
3983$ValidatePath = Find-First @ (
4084 (Join-Path $ScriptsDir ' VALIDATE.ps1' ),
41- (Get-ChildItem - LiteralPath $ScriptsDir - Filter ' VALIDATE.ps1' - File - Recurse - ErrorAction SilentlyContinue | Select-Object - First 1 | ForEach-Object { $_.FullName })
85+ (Get-ChildItem - LiteralPath $ScriptsDir - Filter ' VALIDATE.ps1' - File - Recurse - ErrorAction SilentlyContinue | Select-Object - First 1 | ForEach-Object { $_.FullName }),
86+ # Fallback: try relative paths from current directory
87+ ' Scripts\VALIDATE.ps1' ,
88+ ' .\Scripts\VALIDATE.ps1'
4289)
4390
4491$MainPath = Find-First @ (
4592 (Join-Path $ScriptsDir ' DeepCleanPro.ps1' ),
46- (Get-ChildItem - LiteralPath $ScriptsDir - Filter ' DeepCleanPro.ps1' - File - Recurse - ErrorAction SilentlyContinue | Select-Object - First 1 | ForEach-Object { $_.FullName })
93+ (Get-ChildItem - LiteralPath $ScriptsDir - Filter ' DeepCleanPro.ps1' - File - Recurse - ErrorAction SilentlyContinue | Select-Object - First 1 | ForEach-Object { $_.FullName }),
94+ # Fallback: try relative paths from current directory
95+ ' Scripts\DeepCleanPro.ps1' ,
96+ ' .\Scripts\DeepCleanPro.ps1'
4797)
4898
99+ Write-Host " ValidatePath: $ValidatePath " - ForegroundColor Cyan
100+ Write-Host " MainPath: $MainPath " - ForegroundColor Cyan
101+ Write-Host " ValidatePath exists: $ ( Test-Path $ValidatePath ) " - ForegroundColor Green
102+ Write-Host " MainPath exists: $ ( Test-Path $MainPath ) " - ForegroundColor Green
103+
104+ # List Scripts directory contents if it exists
105+ if (Test-Path $ScriptsDir ) {
106+ Write-Host " Scripts directory contents:" - ForegroundColor Yellow
107+ Get-ChildItem $ScriptsDir - Name | ForEach-Object { Write-Host " $_ " - ForegroundColor Gray }
108+ } else {
109+ Write-Host " Scripts directory not found!" - ForegroundColor Red
110+ }
111+
112+ Write-Host " === END DEBUG ===" - ForegroundColor Yellow
113+
49114$SkipValidate = -not $ValidatePath
50115$SkipMain = -not $MainPath
51116
0 commit comments