Skip to content

Commit bf92df3

Browse files
mldangeloclaude
andcommitted
ci: fix Windows npm cache corruption (ECOMPROMISED error)
Fix fundamental issue causing "npm error code ECOMPROMISED" in Windows CI. Root Cause Analysis: -------------------- 1. Environment Variable Timing Issue: - Writing to $env:GITHUB_ENV only affects FUTURE steps, not current step - Previous workflow: Set NPM_CONFIG_CACHE in GITHUB_ENV, then ran "npm cache clean" in SAME step - Result: Cache clean ran against DEFAULT cache, not configured cache 2. Configuration Order Issue: - NPM_CONFIG_PREFIX was set AFTER installing promptfoo globally - npm install used default prefix, then config pointed to different location - Created mismatch between package location and npm expectations - Caused cache lock file integrity errors (ECOMPROMISED) 3. Cache Clean Timing: - Cache was cleaned before configuring where cache should be located - Wrong cache was cleaned, leaving actual cache potentially corrupted The Fix: -------- - Use "npm config set" to configure cache/prefix IMMEDIATELY (not GITHUB_ENV) - Configure cache location FIRST - Configure prefix location SECOND - Clean and verify cache THIRD (now cleans correctly-configured cache) - Only THEN export to GITHUB_ENV for future steps - Consolidated "Add npm global bin to PATH" into single configuration step Changes Applied to Both Jobs: - test: Uses global promptfoo install - test-npx-fallback: Uses npx fallback (no global install) This ensures npm configuration is consistent and cache integrity is maintained across all Windows CI runs. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 4ebee1b commit bf92df3

File tree

1 file changed

+54
-16
lines changed

1 file changed

+54
-16
lines changed

.github/workflows/test.yml

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,31 +79,46 @@ jobs:
7979
with:
8080
node-version: "24"
8181

82-
- name: Configure npm cache on Windows
82+
- name: Configure npm on Windows
8383
if: matrix.os == 'windows-latest'
84+
shell: pwsh
8485
run: |
85-
"NPM_CONFIG_CACHE=$env:RUNNER_TEMP\\npm-cache" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
86-
npm cache clean --force
87-
88-
- name: Install promptfoo globally
89-
run: npm install -g promptfoo@latest
90-
env:
91-
NODE_OPTIONS: --max-old-space-size=4096
92-
93-
- name: Add npm global bin to PATH (Windows)
94-
if: matrix.os == 'windows-latest'
95-
run: |
96-
$globalPrefix = (npm config get prefix).Trim()
97-
if (-not $globalPrefix) {
86+
# Configure cache location (applies immediately to this step)
87+
$cacheDir = Join-Path $env:RUNNER_TEMP "npm-cache"
88+
New-Item -ItemType Directory -Force -Path $cacheDir | Out-Null
89+
npm config set cache $cacheDir --location=user
90+
91+
# Configure prefix location (applies immediately to this step)
92+
$globalPrefix = npm config get prefix
93+
if (-not $globalPrefix -or $globalPrefix -eq "undefined") {
9894
$globalPrefix = Join-Path $env:APPDATA "npm"
9995
}
96+
$globalPrefix = $globalPrefix.Trim()
97+
npm config set prefix $globalPrefix --location=user
98+
99+
# NOW clean and verify cache (cleans the correctly-configured cache)
100+
npm cache clean --force
101+
npm cache verify
102+
103+
# Export settings for future steps
104+
"NPM_CONFIG_CACHE=$cacheDir" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
100105
"NPM_CONFIG_PREFIX=$globalPrefix" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
101106
"npm_config_prefix=$globalPrefix" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
107+
108+
# Add global bin directories to PATH
102109
$binPaths = @($globalPrefix, (Join-Path $globalPrefix "bin")) | Where-Object { Test-Path $_ }
103110
foreach ($binPath in $binPaths) {
104111
$binPath | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
105112
}
106113
114+
Write-Host "npm cache: $cacheDir"
115+
Write-Host "npm prefix: $globalPrefix"
116+
117+
- name: Install promptfoo globally
118+
run: npm install -g promptfoo@latest
119+
env:
120+
NODE_OPTIONS: --max-old-space-size=4096
121+
107122
- uses: astral-sh/setup-uv@v7
108123
with:
109124
enable-cache: true
@@ -138,11 +153,34 @@ jobs:
138153
with:
139154
node-version: "24"
140155

141-
- name: Configure npm cache on Windows
156+
- name: Configure npm on Windows
142157
if: matrix.os == 'windows-latest'
158+
shell: pwsh
143159
run: |
144-
"NPM_CONFIG_CACHE=$env:RUNNER_TEMP\\npm-cache" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
160+
# Configure cache location (applies immediately to this step)
161+
$cacheDir = Join-Path $env:RUNNER_TEMP "npm-cache"
162+
New-Item -ItemType Directory -Force -Path $cacheDir | Out-Null
163+
npm config set cache $cacheDir --location=user
164+
165+
# Configure prefix location (applies immediately to this step)
166+
$globalPrefix = npm config get prefix
167+
if (-not $globalPrefix -or $globalPrefix -eq "undefined") {
168+
$globalPrefix = Join-Path $env:APPDATA "npm"
169+
}
170+
$globalPrefix = $globalPrefix.Trim()
171+
npm config set prefix $globalPrefix --location=user
172+
173+
# NOW clean and verify cache (cleans the correctly-configured cache)
145174
npm cache clean --force
175+
npm cache verify
176+
177+
# Export settings for future steps
178+
"NPM_CONFIG_CACHE=$cacheDir" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
179+
"NPM_CONFIG_PREFIX=$globalPrefix" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
180+
"npm_config_prefix=$globalPrefix" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
181+
182+
Write-Host "npm cache: $cacheDir"
183+
Write-Host "npm prefix: $globalPrefix"
146184
147185
# Intentionally skip installing promptfoo globally
148186
# This tests the npx fallback path

0 commit comments

Comments
 (0)