Skip to content

Commit 222f660

Browse files
Fcursoragent
andcommitted
fix(test): repair color parsing and parallel TestSupport loading
Share CssNamedColors globally, fix selective media init order, load TestSupport in parallel workers, and align scientific missing-file error assertions with validation order. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 0f56d6e commit 222f660

11 files changed

Lines changed: 110 additions & 33 deletions

File tree

profile.d/conversion-modules/media/colors/convert.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ function Initialize-FileConversion-MediaColorsConvert {
124124
$minDistance = [double]::MaxValue
125125
$closestName = 'black'
126126

127-
foreach ($name in $script:CssNamedColors.Keys) {
127+
foreach ($name in $global:CssNamedColors.Keys) {
128128
if ($name -eq 'transparent') { continue }
129-
$namedRgb = $script:CssNamedColors[$name]
129+
$namedRgb = $global:CssNamedColors[$name]
130130
$distance = [Math]::Sqrt(
131131
[Math]::Pow($rgb.r - $namedRgb.r, 2) +
132132
[Math]::Pow($rgb.g - $namedRgb.g, 2) +

profile.d/conversion-modules/media/colors/named.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#>
1616
function Initialize-FileConversion-MediaColorsNamed {
1717
# CSS Named Colors - Complete list from CSS Color Module Level 4 specification
18-
$script:CssNamedColors = @{
18+
$global:CssNamedColors = @{
1919
# Basic 16 colors
2020
'black' = @{ r = 0; g = 0; b = 0 }
2121
'silver' = @{ r = 192; g = 192; b = 192 }

profile.d/conversion-modules/media/colors/parse.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ function Initialize-FileConversion-MediaColorsParse {
2525

2626
# Check for named color
2727
$colorName = $colorString.ToLower()
28-
if ($script:CssNamedColors.ContainsKey($colorName)) {
29-
return $script:CssNamedColors[$colorName].Clone()
28+
if ($null -ne $global:CssNamedColors -and $global:CssNamedColors.ContainsKey($colorName)) {
29+
return $global:CssNamedColors[$colorName].Clone()
3030
}
3131

3232
# Parse HEX (#rgb, #rrggbb, #rrggbbaa)

scripts/utils/code-quality/modules/PesterConfig.psm1

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,11 @@ function New-PesterTestConfiguration {
150150

151151
[string]$RepoRoot,
152152

153-
[string[]]$TestPaths
153+
[string[]]$TestPaths,
154+
155+
[string]$TestSupportPath,
156+
157+
[string]$TestsDir
154158
)
155159

156160
# Convert enums to strings
@@ -202,6 +206,8 @@ function New-PesterTestConfiguration {
202206
Randomize = $Randomize
203207
FailOnWarnings = $FailOnWarnings
204208
SkipRemainingOnFailure = $SkipRemainingOnFailure
209+
TestSupportPath = $TestSupportPath
210+
TestsDir = $TestsDir
205211
}
206212

207213
if ($null -ne $Timeout) {

scripts/utils/code-quality/modules/PesterExecutionConfig.psm1

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ function Set-PesterExecutionOptions {
4444
[switch]$Randomize,
4545
[Nullable[int]]$Timeout,
4646
[switch]$FailOnWarnings,
47-
[switch]$SkipRemainingOnFailure
47+
[switch]$SkipRemainingOnFailure,
48+
[string]$TestSupportPath,
49+
[string]$TestsDir
4850
)
4951

5052
# Configure parallel execution
@@ -55,6 +57,43 @@ function Set-PesterExecutionOptions {
5557
if ($Config.Run.PSObject.Properties.Name -contains 'MaximumThreadCount') {
5658
$Config.Run.MaximumThreadCount = $Parallel
5759
}
60+
61+
# Parallel workers run in isolated runspaces; load TestSupport in each worker.
62+
if ($TestSupportPath -and -not [string]::IsNullOrWhiteSpace($TestSupportPath) -and (Test-Path -LiteralPath $TestSupportPath)) {
63+
$supportPath = $TestSupportPath
64+
$testsDirectory = if ($TestsDir -and -not [string]::IsNullOrWhiteSpace($TestsDir)) {
65+
$TestsDir
66+
}
67+
else {
68+
Split-Path -Parent $TestSupportPath
69+
}
70+
71+
if ($Config.Run.PSObject.Properties.Name -contains 'Initialization') {
72+
$Config.Run.Initialization = {
73+
$ErrorActionPreference = 'Stop'
74+
$ConfirmPreference = 'None'
75+
$global:ConfirmPreference = 'None'
76+
if (-not $global:PSDefaultParameterValues) {
77+
$global:PSDefaultParameterValues = @{}
78+
}
79+
$global:PSDefaultParameterValues['Remove-Item:Confirm'] = $false
80+
$global:PSDefaultParameterValues['Remove-Item:Force'] = $true
81+
$global:PSDefaultParameterValues['Remove-Item:Recurse'] = $true
82+
83+
$env:PS_PROFILE_TEST_SUPPORT_PATH = $using:supportPath
84+
$env:PS_PROFILE_TESTS_DIR = $using:testsDirectory
85+
86+
$originalPSScriptRoot = $PSScriptRoot
87+
$PSScriptRoot = $using:testsDirectory
88+
try {
89+
. $using:supportPath
90+
}
91+
finally {
92+
$PSScriptRoot = $originalPSScriptRoot
93+
}
94+
}
95+
}
96+
}
5897
}
5998

6099
# Randomization is handled at the runner level by shuffling discovered test

scripts/utils/code-quality/run-pester.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,9 @@ try {
796796
$testsDir = Join-Path $repoRoot 'tests'
797797
$profileDir = Join-Path $repoRoot 'profile.d'
798798
$testSupportPath = Join-Path $testsDir 'TestSupport.ps1'
799+
800+
$env:PS_PROFILE_TEST_SUPPORT_PATH = $testSupportPath
801+
$env:PS_PROFILE_TESTS_DIR = $testsDir
799802

800803
# Level 2: Repository paths resolved
801804
if ($debugLevel -ge 2) {
@@ -1015,6 +1018,8 @@ try {
10151018
Verbose = $Verbose
10161019
ProfileDir = $profileDir
10171020
RepoRoot = $repoRoot
1021+
TestSupportPath = $testSupportPath
1022+
TestsDir = $testsDir
10181023
}
10191024

10201025
# Handle parallel execution

tests/TestSupport.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ function Get-TestSupportPath {
9292
[string]$StartPath = $PSScriptRoot
9393
)
9494

95+
if ($env:PS_PROFILE_TEST_SUPPORT_PATH -and -not [string]::IsNullOrWhiteSpace($env:PS_PROFILE_TEST_SUPPORT_PATH) -and (Test-Path -LiteralPath $env:PS_PROFILE_TEST_SUPPORT_PATH)) {
96+
return $env:PS_PROFILE_TEST_SUPPORT_PATH
97+
}
98+
9599
$current = Get-Item -LiteralPath $StartPath
96100

97101
while ($null -ne $current) {

tests/TestSupport/TestModuleLoading.ps1

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,10 @@ function Import-ModuleGroup {
181181
$ModuleConfig
182182
}
183183

184-
# Filter to selective modules if specified
184+
# Filter to selective modules if specified (preserve caller order for dependencies)
185185
if ($SelectiveModules) {
186-
$modules = @($modules | Where-Object { $SelectiveModules -contains $_ })
186+
$selectiveOrder = @($SelectiveModules)
187+
$modules = @($selectiveOrder | Where-Object { $modules -contains $_ })
187188
# Load shared common.ps1 helpers before format-specific modules
188189
$commonFirst = @($modules | Where-Object { $_ -eq 'common.ps1' })
189190
$rest = @($modules | Where-Object { $_ -ne 'common.ps1' })
@@ -1639,11 +1640,17 @@ function Initialize-ConversionIntegration {
16391640
$env:PS_PROFILE_REPO_ROOT = Split-Path -Parent $ProfileDir
16401641
}
16411642

1642-
Initialize-TestProfile `
1643-
-ProfileDir $ProfileDir `
1644-
-LoadBootstrap `
1645-
-LoadConversionModules $ModuleType `
1646-
-SelectiveModules $SelectiveModules
1643+
$profileInitParams = @{
1644+
ProfileDir = $ProfileDir
1645+
LoadBootstrap = $true
1646+
LoadConversionModules = $ModuleType
1647+
SelectiveModules = $SelectiveModules
1648+
}
1649+
if ($EnsureMedia -or $EnsureDocuments) {
1650+
$profileInitParams['LoadFilesFragment'] = $true
1651+
}
1652+
1653+
Initialize-TestProfile @profileInitParams
16471654

16481655
if ($EnsureData) {
16491656
if (-not $SelectiveModules -or @($SelectiveModules).Count -eq 0) {
@@ -1667,12 +1674,13 @@ function Initialize-ConversionIntegration {
16671674
}
16681675

16691676
if ($EnsureMedia) {
1670-
if ($SelectiveModules -and @($SelectiveModules).Count -gt 0) {
1671-
$global:FileConversionMediaInitialized = $true
1672-
}
1673-
elseif (Get-Command Ensure-FileConversion-Media -ErrorAction SilentlyContinue) {
1677+
if (Get-Command Ensure-FileConversion-Media -ErrorAction SilentlyContinue) {
16741678
Ensure-FileConversion-Media
16751679
}
1680+
elseif (Get-Command _Parse-Color -ErrorAction SilentlyContinue) {
1681+
# Selective media module loading registers parsers without files.ps1 Ensure helpers.
1682+
$global:FileConversionMediaInitialized = $true
1683+
}
16761684
}
16771685

16781686
if ($EnsureSpecialized) {

tests/integration/conversion/data/scientific/sas.tests.ps1

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,18 @@ Describe 'SAS Format Conversion Tests' {
153153

154154
if ($error) {
155155
$errorMessage = $error.Exception.Message
156-
$missingDataFrameLib = -not $script:PandasAvailable -and -not $script:PolarsAvailable
157-
if ($missingDataFrameLib -or -not $script:PyreadstatAvailable) {
158-
($errorMessage -match 'pandas|polars|pyreadstat') | Should -Be $true
159-
($errorMessage -match 'uv pip install|pip install') | Should -Be $true
156+
if ($errorMessage -match 'not found|does not exist|cannot find|InputPath|Input file') {
157+
($errorMessage -match 'not found|does not exist|cannot find|InputPath|Input file|missing|\.sas7bdat') | Should -Be $true
160158
}
161159
else {
162-
($errorMessage -match 'not found|does not exist|cannot find|InputPath|missing|\.sas7bdat') | Should -Be $true
160+
$missingDataFrameLib = -not $script:PandasAvailable -and -not $script:PolarsAvailable
161+
if ($missingDataFrameLib -or -not $script:PyreadstatAvailable) {
162+
($errorMessage -match 'pandas|polars|pyreadstat') | Should -Be $true
163+
($errorMessage -match 'uv pip install|pip install') | Should -Be $true
164+
}
165+
else {
166+
($errorMessage -match 'not found|does not exist|cannot find|InputPath|missing|\.sas7bdat') | Should -Be $true
167+
}
163168
}
164169
}
165170
}

tests/integration/conversion/data/scientific/spss.tests.ps1

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,18 @@ Describe 'SPSS Format Conversion Tests' {
8585

8686
if ($error) {
8787
$errorMessage = $error.Exception.Message
88-
$missingDataFrameLib = -not $script:PandasAvailable -and -not $script:PolarsAvailable
89-
if ($missingDataFrameLib -or -not $script:PyreadstatAvailable) {
90-
($errorMessage -match 'pandas|polars|pyreadstat') | Should -Be $true
91-
($errorMessage -match 'uv pip install|pip install') | Should -Be $true
88+
if ($errorMessage -match 'not found|does not exist|cannot find|InputPath|Input file') {
89+
($errorMessage -match 'not found|does not exist|cannot find|InputPath|Input file|missing|\.sav') | Should -Be $true
9290
}
9391
else {
94-
($errorMessage -match 'not found|does not exist|cannot find|InputPath|missing|\.sav') | Should -Be $true
92+
$missingDataFrameLib = -not $script:PandasAvailable -and -not $script:PolarsAvailable
93+
if ($missingDataFrameLib -or -not $script:PyreadstatAvailable) {
94+
($errorMessage -match 'pandas|polars|pyreadstat') | Should -Be $true
95+
($errorMessage -match 'uv pip install|pip install') | Should -Be $true
96+
}
97+
else {
98+
($errorMessage -match 'not found|does not exist|cannot find|InputPath|missing|\.sav') | Should -Be $true
99+
}
95100
}
96101
}
97102
}

0 commit comments

Comments
 (0)