Skip to content

Commit 5c95109

Browse files
bolenscursoragent
andcommitted
fix(test): stop PATH editors leaking into Get-EditorInfo
Honor availability overrides without gating on test-mode env, and stop Clear-TestCachedCommandCache from wiping sibling override/cache entries when marking many editors unavailable. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 8a61f1f commit 5c95109

5 files changed

Lines changed: 63 additions & 32 deletions

File tree

profile.d/bootstrap/CommandCache.ps1

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,23 @@ function global:Test-CachedCommand {
5454

5555
# Test harness overrides win over assumed commands / real lookups so
5656
# Mark-TestCommandsUnavailable still works after bootstrap redefines this function.
57-
if ($env:PS_PROFILE_TEST_MODE -eq '1') {
58-
$overrideTable = Get-Variable -Name 'TestCommandAvailabilityOverrides' -Scope Global -ErrorAction SilentlyContinue
59-
if ($null -ne $overrideTable -and $null -ne $overrideTable.Value) {
60-
$overrides = $overrideTable.Value
61-
if ($overrides.ContainsKey($normalizedName)) {
62-
return [bool]$overrides[$normalizedName]
63-
}
64-
if ($overrides.ContainsKey($cacheKey)) {
65-
return [bool]$overrides[$cacheKey]
66-
}
57+
# Honor whenever the override table is present (tests only); do not gate on
58+
# PS_PROFILE_TEST_MODE — some shards clear or change that env mid-run.
59+
$overrideTable = Get-Variable -Name 'TestCommandAvailabilityOverrides' -Scope Global -ErrorAction SilentlyContinue
60+
if ($null -ne $overrideTable -and $null -ne $overrideTable.Value) {
61+
$overrides = $overrideTable.Value
62+
if ($overrides.ContainsKey($normalizedName)) {
63+
return [bool]$overrides[$normalizedName]
64+
}
65+
if ($overrides.ContainsKey($cacheKey)) {
66+
return [bool]$overrides[$cacheKey]
6767
}
6868
}
6969

7070
# Check assumed commands first (bypasses actual command lookup for optional tools)
71-
if ($global:AssumedAvailableCommands -and $global:AssumedAvailableCommands.ContainsKey($normalizedName)) {
72-
$assumed = $global:AssumedAvailableCommands[$normalizedName]
71+
$assumedTable = Get-Variable -Name 'AssumedAvailableCommands' -Scope Global -ErrorAction SilentlyContinue
72+
if ($null -ne $assumedTable -and $null -ne $assumedTable.Value -and $assumedTable.Value.ContainsKey($normalizedName)) {
73+
$assumed = $assumedTable.Value[$normalizedName]
7374
if ($assumed -is [bool]) {
7475
return $assumed
7576
}
@@ -79,8 +80,9 @@ function global:Test-CachedCommand {
7980
$now = Get-Date
8081

8182
# Check cache for existing entry that hasn't expired (if caching enabled)
82-
if ($CacheTTLMinutes -gt 0 -and $global:TestCachedCommandCache.ContainsKey($cacheKey)) {
83-
$entry = [pscustomobject]$global:TestCachedCommandCache[$cacheKey]
83+
$cacheTable = Get-Variable -Name 'TestCachedCommandCache' -Scope Global -ErrorAction SilentlyContinue
84+
if ($CacheTTLMinutes -gt 0 -and $null -ne $cacheTable -and $null -ne $cacheTable.Value -and $cacheTable.Value.ContainsKey($cacheKey)) {
85+
$entry = [pscustomobject]$cacheTable.Value[$cacheKey]
8486
if ($entry -and $entry.Expires -gt $now) {
8587
return [bool]$entry.Result
8688
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ function Get-PesterCiShardDefinitions {
141141
'unit-profile-conversion' = @{ Kind = 'Pester'; Suite = 'Unit'; Paths = @('tests/unit/profile/conversion') }
142142
'unit-profile-core' = @{ Kind = 'Pester'; Suite = 'Unit'; Paths = $unitProfileCore; MaxParallelThreads = 1 }
143143
'unit-profile-infra' = @{ Kind = 'Pester'; Suite = 'Unit'; Paths = $unitProfileInfra }
144-
'unit-profile-misc-a' = @{ Kind = 'Pester'; Suite = 'Unit'; Paths = $miscA }
145-
'unit-profile-misc-b' = @{ Kind = 'Pester'; Suite = 'Unit'; Paths = $miscB }
144+
'unit-profile-misc-a' = @{ Kind = 'Pester'; Suite = 'Unit'; Paths = $miscA; MaxParallelThreads = 1 }
145+
'unit-profile-misc-b' = @{ Kind = 'Pester'; Suite = 'Unit'; Paths = $miscB; MaxParallelThreads = 1 }
146146
'integration-tools' = @{ Kind = 'ToolsBatch' }
147147
'integration-core' = @{ Kind = 'Pester'; Suite = 'Integration'; Paths = $integrationCore }
148148
'conversion-document' = @{ Kind = 'ConversionBatch'; Paths = @('document') }

tests/TestSupport/TestCommandAvailability.ps1

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,18 @@ function Register-TestCommandAvailabilityStub {
4545
$actualName = $args[0]
4646
}
4747

48-
if (-not [string]::IsNullOrWhiteSpace($actualName) -and $global:TestCommandAvailabilityOverrides) {
49-
$trimmed = $actualName.Trim()
50-
$lower = $trimmed.ToLowerInvariant()
51-
if ($global:TestCommandAvailabilityOverrides.ContainsKey($trimmed)) {
52-
return [bool]$global:TestCommandAvailabilityOverrides[$trimmed]
53-
}
54-
if ($global:TestCommandAvailabilityOverrides.ContainsKey($lower)) {
55-
return [bool]$global:TestCommandAvailabilityOverrides[$lower]
48+
if (-not [string]::IsNullOrWhiteSpace($actualName)) {
49+
$overrideTable = Get-Variable -Name 'TestCommandAvailabilityOverrides' -Scope Global -ErrorAction SilentlyContinue
50+
if ($null -ne $overrideTable -and $null -ne $overrideTable.Value) {
51+
$trimmed = $actualName.Trim()
52+
$lower = $trimmed.ToLowerInvariant()
53+
$overrides = $overrideTable.Value
54+
if ($overrides.ContainsKey($trimmed)) {
55+
return [bool]$overrides[$trimmed]
56+
}
57+
if ($overrides.ContainsKey($lower)) {
58+
return [bool]$overrides[$lower]
59+
}
5660
}
5761
}
5862

@@ -155,10 +159,6 @@ function Set-TestCommandAvailabilityState {
155159
[void]$global:TestRegisteredMockCommands.Remove($normalized)
156160
}
157161

158-
if (Get-Command Clear-TestCachedCommandCache -ErrorAction SilentlyContinue) {
159-
Clear-TestCachedCommandCache | Out-Null
160-
}
161-
162162
$null = $global:TestCachedCommandCache.TryRemove($cacheKey, [ref]$removed)
163163
$null = $global:TestCachedCommandCache.TryRemove($normalized, [ref]$removed)
164164

tests/unit/profile/editors/profile-editors-other.tests.ps1

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ function global:Reset-TestEditorCommandAvailability {
1111
'lighttable', 'theia-ide', 'nano'
1212
)
1313

14-
Clear-TestCachedCommandCache | Out-Null
14+
if (Get-Command Register-TestCommandAvailabilityStub -ErrorAction SilentlyContinue) {
15+
Register-TestCommandAvailabilityStub
16+
}
1517

1618
foreach ($command in $managedEditorCommands) {
1719
if (Get-Command Set-TestCommandAvailabilityState -ErrorAction SilentlyContinue) {
@@ -22,12 +24,22 @@ function global:Reset-TestEditorCommandAvailability {
2224
Remove-Item -Path "Function:\$command" -Force -ErrorAction SilentlyContinue
2325
Remove-Item -Path "Function:\global:$command" -Force -ErrorAction SilentlyContinue
2426

27+
if (-not (Get-Variable -Name 'TestCommandAvailabilityOverrides' -Scope Global -ErrorAction SilentlyContinue)) {
28+
$global:TestCommandAvailabilityOverrides = [System.Collections.Concurrent.ConcurrentDictionary[string, bool]]::new([System.StringComparer]::OrdinalIgnoreCase)
29+
}
30+
$cacheKey = $command.ToLowerInvariant()
31+
$global:TestCommandAvailabilityOverrides[$command] = $false
32+
$global:TestCommandAvailabilityOverrides[$cacheKey] = $false
33+
2534
if ($global:AssumedAvailableCommands) {
2635
$removed = $null
2736
$null = $global:AssumedAvailableCommands.TryRemove($command, [ref]$removed)
37+
$null = $global:AssumedAvailableCommands.TryRemove($cacheKey, [ref]$removed)
2838
}
2939

30-
$cacheKey = $command.ToLowerInvariant()
40+
if (-not (Get-Variable -Name 'TestCachedCommandCache' -Scope Global -ErrorAction SilentlyContinue)) {
41+
$global:TestCachedCommandCache = [System.Collections.Concurrent.ConcurrentDictionary[string, object]]::new([System.StringComparer]::OrdinalIgnoreCase)
42+
}
3143
$global:TestCachedCommandCache[$cacheKey] = [pscustomobject]@{
3244
Result = $false
3345
Expires = (Get-Date).AddHours(24)

tests/unit/profile/editors/profile-editors-vscode.tests.ps1

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,35 @@ function global:Reset-TestEditorCommandAvailability {
1111
'lighttable', 'theia-ide', 'nano'
1212
)
1313

14-
Clear-TestCachedCommandCache | Out-Null
14+
if (Get-Command Register-TestCommandAvailabilityStub -ErrorAction SilentlyContinue) {
15+
Register-TestCommandAvailabilityStub
16+
}
1517

1618
foreach ($command in $managedEditorCommands) {
19+
if (Get-Command Set-TestCommandAvailabilityState -ErrorAction SilentlyContinue) {
20+
Set-TestCommandAvailabilityState -CommandName $command -Available $false
21+
continue
22+
}
23+
1724
Remove-Item -Path "Function:\$command" -Force -ErrorAction SilentlyContinue
1825
Remove-Item -Path "Function:\global:$command" -Force -ErrorAction SilentlyContinue
1926

27+
if (-not (Get-Variable -Name 'TestCommandAvailabilityOverrides' -Scope Global -ErrorAction SilentlyContinue)) {
28+
$global:TestCommandAvailabilityOverrides = [System.Collections.Concurrent.ConcurrentDictionary[string, bool]]::new([System.StringComparer]::OrdinalIgnoreCase)
29+
}
30+
$cacheKey = $command.ToLowerInvariant()
31+
$global:TestCommandAvailabilityOverrides[$command] = $false
32+
$global:TestCommandAvailabilityOverrides[$cacheKey] = $false
33+
2034
if ($global:AssumedAvailableCommands) {
2135
$removed = $null
2236
$null = $global:AssumedAvailableCommands.TryRemove($command, [ref]$removed)
37+
$null = $global:AssumedAvailableCommands.TryRemove($cacheKey, [ref]$removed)
2338
}
2439

25-
$cacheKey = $command.ToLowerInvariant()
40+
if (-not (Get-Variable -Name 'TestCachedCommandCache' -Scope Global -ErrorAction SilentlyContinue)) {
41+
$global:TestCachedCommandCache = [System.Collections.Concurrent.ConcurrentDictionary[string, object]]::new([System.StringComparer]::OrdinalIgnoreCase)
42+
}
2643
$global:TestCachedCommandCache[$cacheKey] = [pscustomobject]@{
2744
Result = $false
2845
Expires = (Get-Date).AddHours(24)

0 commit comments

Comments
 (0)