Skip to content

Give Corepack a user-writable Layer 3 cache - #9

Merged
brettheap merged 5 commits into
mainfrom
fix/user-corepack-cache
Jul 25, 2026
Merged

Give Corepack a user-writable Layer 3 cache#9
brettheap merged 5 commits into
mainfrom
fix/user-corepack-cache

Conversation

@brettheap

@brettheap brettheap commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Summary

  • override the inherited root-owned Corepack cache in the shared user layer
  • pre-create the cache under each Layer 3 user home
  • verify unprivileged pnpm execution and cache writability in the devBench harness

Validation

  • git diff --check
  • shell syntax checks
  • disposable Layer 3 build with synthetic user corepacktest
  • pnpm --version downloaded pnpm 11.17.0 into /home/corepacktest/.cache/corepack
  • new Corepack harness checks pass
  • full harness baseline comparison confirms the same four unrelated existing failures before and after the patch

Summary by Sourcery

Configure Corepack to use a user-owned cache in the Layer 3 user image and validate unprivileged pnpm/Corepack behavior in the dev container harness.

New Features:

  • Provide a user-writable Corepack cache under the Layer 3 user home for on-demand package-manager downloads.

Enhancements:

  • Bump the Layer 3 user-layer image version label to reflect the Corepack cache change.
  • Pre-create the Corepack cache directory in the user image so pnpm and yarn work immediately in bench sessions.

Documentation:

  • Update devBench devcontainer test README to document the user-writable Corepack cache and pnpm/Corepack validation.

Tests:

  • Extend the devcontainer test harness to exercise pnpm as an unprivileged user and verify the Corepack cache is user-owned and writable.

Copilot AI review requested due to automatic review settings July 25, 2026 10:49
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@sourcery-ai

sourcery-ai Bot commented Jul 25, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Configures Corepack to use a user-owned cache in the Layer 3 user image and extends the devBench harness to validate unprivileged pnpm/Corepack operation and cache writability.

Sequence diagram for user-writable Corepack cache and pnpm validation

sequenceDiagram
    actor DevBenchTest
    participant Shell
    participant pnpm
    participant Corepack
    participant Filesystem

    DevBenchTest->>Shell: run test.sh
    Shell->>Shell: set COREPACK_HOME=/home/$USERNAME/.cache/corepack
    Shell->>Filesystem: mkdir -p COREPACK_HOME
    Shell->>pnpm: pnpm --version
    pnpm->>Corepack: resolve pnpm version via Corepack
    Corepack->>Filesystem: write cache under COREPACK_HOME
    Filesystem-->>Corepack: cache write succeeds (user-owned)
    Corepack-->>pnpm: provide pnpm 11.17.0
    pnpm-->>Shell: print version
    Shell-->>DevBenchTest: report unprivileged pnpm/Corepack operation success
Loading

File-Level Changes

Change Details Files
Configure Corepack to use a user-owned cache directory in the Layer 3 user image.
  • Bumped the user-layer image version label from 1.2.0 to 1.2.1.
  • Set COREPACK_HOME to /home/${USERNAME}/.cache/corepack via ENV so Corepack uses a per-user cache instead of the inherited root-owned cache.
  • Pre-created the Corepack cache directory as the Layer 3 user to ensure correct ownership and immediate availability in interactive and non-interactive sessions.
user-layer/Dockerfile
Extend the devBench devcontainer test harness to document and verify unprivileged pnpm/Corepack behavior and cache writability.
  • Updated README to describe Node.js tooling as including npm, yarn, and a user-writable Corepack cache for pnpm, and to note validation of unprivileged pnpm/Corepack operation.
  • Enhanced test.sh to run pnpm --version under the unprivileged user to confirm pnpm/Corepack work in the devBench harness.
  • Added a test in test.sh to assert COREPACK_HOME matches $HOME/.cache/corepack, exists, and is writable, ensuring the cache is user-owned and usable.
devBenches/devcontainer.test/README.md
devBenches/devcontainer.test/test.sh

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@brettheap

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • Setting COREPACK_HOME globally in the Dockerfile means root processes in the container will also use a cache under the non-root user’s home; consider scoping COREPACK_HOME to the non-root user (e.g., via that user’s shell profile) to avoid unexpected permission behavior when running Corepack as root.
  • The Corepack cache test in devcontainer.test/test.sh assumes HOME is always /home/$USERNAME; if HOME can be overridden in any harness scenario, consider checking directory ownership and writability more directly rather than strict path equality.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Setting COREPACK_HOME globally in the Dockerfile means root processes in the container will also use a cache under the non-root user’s home; consider scoping COREPACK_HOME to the non-root user (e.g., via that user’s shell profile) to avoid unexpected permission behavior when running Corepack as root.
- The Corepack cache test in devcontainer.test/test.sh assumes HOME is always /home/$USERNAME; if HOME can be overridden in any harness scenario, consider checking directory ownership and writability more directly rather than strict path equality.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR configures Corepack to use a user-writable cache location in the Layer 3 user image and extends the devcontainer test harness/docs to validate unprivileged pnpm/Corepack behavior.

Changes:

  • Set COREPACK_HOME in the Layer 3 user image and pre-create the cache directory under the user’s home.
  • Extend the devcontainer test harness to run pnpm --version and assert Corepack cache ownership/writability.
  • Update the devcontainer test README to mention pnpm/Corepack validation and the user-writable cache behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
user-layer/Dockerfile Sets COREPACK_HOME and pre-creates the cache directory in the Layer 3 user image; bumps layer version label.
devBenches/devcontainer.test/test.sh Adds pnpm/Corepack checks to ensure cache location is user-owned/writable under unprivileged execution.
devBenches/devcontainer.test/README.md Updates harness documentation to reflect pnpm/Corepack coverage and cache behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread user-layer/Dockerfile Outdated
Comment on lines +31 to +35
# Corepack downloads package-manager shims and versions on demand. Keep its
# mutable cache in the Layer 3 user's home rather than the root-owned cache
# inherited from a shared base image.
ENV COREPACK_HOME=/home/${USERNAME}/.cache/corepack

Comment thread devBenches/devcontainer.test/test.sh Outdated
Comment on lines +72 to +73
test_tool "Corepack cache is user-owned and writable" \
"test \"\$COREPACK_HOME\" = \"\$HOME/.cache/corepack\" && test -d \"\$COREPACK_HOME\" && test -w \"\$COREPACK_HOME\""
Comment on lines 8 to 10
- Python 3.x with pip and development tools (black, flake8, isort, pylint, pytest, ipython)
- Node.js LTS with npm and yarn
- Node.js LTS with npm, yarn, and a user-writable Corepack cache for pnpm
- Python package managers (uv)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 781193d: Layer 1a now lists only its Node tooling, and a separate paragraph attributes the effective-user Corepack cache to Layer 3.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correction: the documentation fix is commit 1b9311c.

brettheap added 2 commits July 25, 2026 06:53
…x/user-corepack-cache

# Conflicts:
#	devBenches/devcontainer.test/test.sh
Copilot AI review requested due to automatic review settings July 25, 2026 10:54
@brettheap

Copy link
Copy Markdown
Contributor Author

Addressed Sourcery feedback at b837741: Corepack now derives its cache from the effective user at runtime, so root and bench users remain isolated. The harness now checks actual cache ownership and writability rather than strict HOME equality.

@sourcery-ai review

@brettheap

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment on lines +13 to +28
# Respect an explicit caller override. Replace only the shared image default,
# which is root-owned and therefore unusable by Layer 3 runtime users.
case "${COREPACK_HOME:-}" in
""|/opt/corepack)
runtime_home=$(getent passwd "$(id -u)" | cut -d: -f6)
if [ -z "$runtime_home" ]; then
echo "Could not determine the effective user's home directory" >&2
exit 1
fi
COREPACK_HOME="$runtime_home/.cache/corepack"
export COREPACK_HOME
;;
esac

mkdir -p "$COREPACK_HOME"
exec "/usr/bin/$command_name" "$@"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved by the final design at b837741 and current head 1b9311c: Layer 3 no longer sets COREPACK_HOME globally. The wrapper replaces the inherited /opt/corepack value using the effective UID passwd home and already emits a clear error when that home cannot be resolved.

Copilot AI review requested due to automatic review settings July 25, 2026 10:57
@brettheap

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@brettheap
brettheap merged commit 4d4b234 into main Jul 25, 2026
5 checks passed
@brettheap
brettheap deleted the fix/user-corepack-cache branch July 25, 2026 10:59

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment on lines +15 to +25
case "${COREPACK_HOME:-}" in
""|/opt/corepack)
runtime_home=$(getent passwd "$(id -u)" | cut -d: -f6)
if [ -z "$runtime_home" ]; then
echo "Could not determine the effective user's home directory" >&2
exit 1
fi
COREPACK_HOME="$runtime_home/.cache/corepack"
export COREPACK_HOME
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants