Skip to content

feat: add npm cache ownership preflight check#462

Open
siwachabhi wants to merge 1 commit intoaws:mainfrom
siwachabhi:feat/npm-cache-ownership-check
Open

feat: add npm cache ownership preflight check#462
siwachabhi wants to merge 1 commit intoaws:mainfrom
siwachabhi:feat/npm-cache-ownership-check

Conversation

@siwachabhi
Copy link
Contributor

Summary

  • Adds a preflight check that detects root-owned ~/.npm cache directories before running npm install
  • A previous sudo npm install leaves root-owned files in the cache, causing cryptic EACCES permission errors on subsequent installs
  • The check runs in both the create (checkCreateDependencies) and deploy (checkDependencyVersions) preflight paths
  • On failure, displays the exact fix command: sudo chown -R $(whoami) ~/.npm
  • Skipped on Windows where file ownership semantics differ

Motivation

Reported by a user running agentcore create who had previously run sudo npm install on their machine. The resulting EACCES error in npm output was difficult to diagnose. This check catches it early with a clear, actionable message.

Changes

  • checks.ts: Added checkNpmCacheOwnership() and formatNpmCacheError(), wired into both checkDependencyVersions() and checkCreateDependencies()
  • index.ts: Exported new function and types
  • checks-extended.test.ts: Added unit tests for the new check and error formatter

Test plan

  • npm run build passes
  • All 64 unit tests pass (vitest run --project unit src/cli/external-requirements/__tests__/)
  • Pre-commit hooks pass (prettier, eslint, typecheck, secretlint)
  • Manual: verify error message displays correctly when ~/.npm is root-owned

@siwachabhi siwachabhi requested a review from a team February 26, 2026 19:14
@github-actions github-actions bot added size/m PR size: M and removed size/m PR size: M labels Feb 26, 2026
@siwachabhi siwachabhi force-pushed the feat/npm-cache-ownership-check branch from 59ae10f to 70ef36e Compare February 26, 2026 19:20
@github-actions github-actions bot added size/m PR size: M and removed size/m PR size: M labels Feb 26, 2026
@siwachabhi siwachabhi force-pushed the feat/npm-cache-ownership-check branch from 70ef36e to 4373779 Compare February 26, 2026 19:25
@github-actions github-actions bot added size/m PR size: M and removed size/m PR size: M labels Feb 26, 2026
Detect root-owned files in ~/.npm before running npm install.
A previous `sudo npm install` leaves root-owned cache files that cause
EACCES permission errors on subsequent installs. The check runs in both
the create and deploy preflight paths, and gives users the exact fix
command (sudo chown -R $(whoami) ~/.npm). Skipped on Windows.

Also fixes rollup high severity vulnerability (GHSA-mw96-cpmx-2vgc).
@siwachabhi siwachabhi force-pushed the feat/npm-cache-ownership-check branch from 4373779 to 336cf3e Compare February 26, 2026 19:27
@github-actions github-actions bot added size/m PR size: M and removed size/m PR size: M labels Feb 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/m PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant