Repository navigation
fix(jest-config): remove the registry mock storage after the run - #13340
Conversation
The `with-registry` jest preset builds a verdaccio-shaped storage into a
fresh `mkdtemp` directory on every run, but `globalTeardown` only killed
the server — the directory was never removed. Every run of every
registry-backed suite therefore leaked one, permanently.
The sizes vary with how much a suite proxies: a small suite leaves
~2 MB, while suites that pull real packages through the proxy cache
leave up to ~2 GB. On a machine where `/tmp` is a tmpfs they accumulate
until it fills, and the suite then fails with
ERR_PNPM_LOCKFILE_WRITE_FILE
╰─▶ Failed to write lockfile content: No space left on device (os error 28)
which reads as flakiness rather than a full disk: a different arbitrary
test fails on each run, each one passes in isolation, and a fresh
checkout passes because nothing has accumulated yet. I had 78 of these
directories before noticing.
`globalSetup` now hands the path it created to `globalTeardown` through
`global`, the same way it already hands over `killServer`, so teardown
removes only that run's directory and never one supplied from outside.
Removal happens after the server is killed, since pnpr writes
proxy-cache entries into the storage as it serves. A failure to remove
warns instead of throwing: a leaked temp directory should not turn an
otherwise-green run red.
Verified by running `pnpm --filter=@pnpm/cache.commands test` with and
without the change: two directories left behind before, none after.
No changeset — `@pnpm/jest-config` is private. No pacquet counterpart:
its fixture storage is content-fingerprinted under `target/` and reused
across runs rather than created per run, so it does not leak.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Warning Review limit reached
Next review available in: 3 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughTemporary registry storage is assigned to global state during setup. Jest teardown now awaits server shutdown, removes the recorded storage directory recursively, handles shutdown and removal errors, and skips cleanup when no path exists. Tests and Jest package configuration cover this behavior. ChangesRegistry storage cleanup
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested labels: Suggested reviewers: ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
PR Summary by QodoFix Jest with-registry teardown to delete temporary Verdaccio storage
AI Description
Diagram
High-Level Assessment
Files changed (2)
|
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@pnpm11/__utils__/jest-config/with-registry/globalTeardown.js`:
- Around line 7-12: Update the teardown flow around global.killServer and
registryMockStorage so rm always runs even when server shutdown rejects or times
out. Place storage cleanup in a finally block, while preserving and propagating
the original shutdown error after cleanup completes.
- Around line 3-18: Add a checked-in regression test for the global teardown
function in globalTeardown.js that exercises setup and teardown, then asserts
the registry mock storage directory no longer exists afterward. Use the existing
global.killServer and global.registryMockStorage integration points, and keep
the test targeted to cleanup of leftover registry storage directories.
- Around line 11-18: Update the cleanup try/catch around rm in globalTeardown so
only expected missing-path failures such as ENOENT are ignored; rethrow
permission, I/O, and other unexpected failures instead of downgrading them to
warnings. Inspect the caught error using its native error code/property rather
than instanceof Error, while preserving the existing warning for handled cleanup
failures.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 6a3752f6-fddd-4f04-890d-f940b0cd7521
📒 Files selected for processing (2)
pnpm11/__utils__/jest-config/with-registry/globalSetup.jspnpm11/__utils__/jest-config/with-registry/globalTeardown.js
Code Review by Qodo
Context used✅ Compliance rules (platform):
18 rules 1.
|
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
Confidence Score: 3/5The PR is not yet safe to merge because a failed or timed-out shutdown can trigger deletion while the registry process remains alive. The shutdown helper can reject before process closure is confirmed, while teardown catches that rejection and unconditionally removes the server’s storage, preserving the previously reported live-writer deletion race. Files Needing Attention: pnpm11/utils/jest-config/with-registry/globalSetup.js, pnpm11/utils/jest-config/with-registry/globalTeardown.js, pnpm11/utils/jest-config/test/globalTeardown.test.js Reviews (3): Last reviewed commit: "fix(jest-config): run the new tests in C..." | Re-trigger Greptile |
…test it Follow-up to the review of #13340. `killServer` can reject — it throws on a `treeKill` failure and after a 10-second wait for pnpr to exit — and awaiting it before the removal meant a failed shutdown skipped cleanup entirely, leaving behind the directory this teardown exists to remove. The shutdown error is now captured, cleanup runs regardless, and the error is rethrown afterwards. When both fail they are reported together as an `AggregateError`, since a server still holding the directory is the likeliest reason a removal fails and letting the second error hide the first would be misleading. A failed removal now propagates instead of warning. `force` already ignores a directory that isn't there, so anything left is unexpected, and downgrading it to a warning is how a leak comes back unnoticed — the repo convention is to catch the specific expected condition rather than swallow everything. `maxRetries` covers the transient case where the just-killed server has not released its handles yet, which Windows is prone to. The package had no test setup, so this adds one: a jest preset reference, a `test` script, and three cases covering removal, removal after a rejected shutdown, and a run that never recorded a path. The second was confirmed to fail against the previous `await global.killServer?.()` ordering. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Code review by qodo was updated up to the latest commit 091cae4 |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pnpm11/__utils__/jest-config/test/globalTeardown.test.js (1)
21-45: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd coverage for cleanup failures and
AggregateError.The implementation adds two observable branches that are currently untested: unexpected removal failures must propagate, and simultaneous shutdown/removal failures must produce an
AggregateErrorcontaining both errors. Add focused tests for these cases; the current suite only covers successful removal, shutdown-only failure, and a missing path.As per path instructions, changed Jest infrastructure should include targeted regression cases that fail without the fix and verify the real behavior.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pnpm11/__utils__/jest-config/test/globalTeardown.test.js` around lines 21 - 45, Extend the globalTeardown tests with focused cases where storage removal fails unexpectedly and where both killServer and storage removal fail together. Assert that removal-only failures propagate, and simultaneous failures reject with an AggregateError containing both original errors, using the existing globalTeardown, killServer, and storage setup patterns.Source: Path instructions
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@pnpm11/__utils__/jest-config/test/globalTeardown.test.js`:
- Around line 21-45: Extend the globalTeardown tests with focused cases where
storage removal fails unexpectedly and where both killServer and storage removal
fail together. Assert that removal-only failures propagate, and simultaneous
failures reject with an AggregateError containing both original errors, using
the existing globalTeardown, killServer, and storage setup patterns.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 75645336-64fb-4018-b004-901f0dde5140
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml,!pnpm-lock.yaml
📒 Files selected for processing (3)
pnpm11/__utils__/jest-config/package.jsonpnpm11/__utils__/jest-config/test/globalTeardown.test.jspnpm11/__utils__/jest-config/with-registry/globalTeardown.js
…lete Follow-up to the review of #13340. The test script was the important one: CI runs `pn --filter=... --if-present .test`, and the package only declared `test`, so the regression tests added in the previous commit would never have run there. A test that does not run is not a regression test. The package now follows the convention the other ~120 packages use — a hidden `.test` carrying the jest invocation, with `test` delegating to it — which also stops the script from clobbering a caller's `NODE_OPTIONS` instead of extending it. `removeStorage` refuses a path whose basename is not shaped like the one `globalSetup` creates. It is a recursive force-delete driven by a mutable global, so it should not act on a value that did not come from that setup; the prefix now lives in one module both sides import. The tests no longer leak the directories they create. They exist because of a directory leak, so leaving one behind when an assertion fails ahead of the removal would be its own small version of the bug. Comments reworded to state the current contract rather than narrate what used to happen, per the comment conventions in AGENTS.md. Verified: `pnpm test` in the package runs all four cases, a real registry suite still leaves nothing behind in /tmp, and `pnpm run lint` passes including `meta-updater --test`. (`pnpm .test` cannot be invoked directly — hidden scripts are callable only from other scripts — and the locally pinned pnpm v12 alpha rejects the recursive form too, for existing `.test` packages as well as this one.) Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
All four addressed in Nonstandard jest test script — you were right, and the consequence was worse than style. CI runs Temp dir cleanup not guaranteed (in the tests) — correct, and a bit pointed given what the tests are about. They now track what they create and remove it in Unvalidated recursive delete target — accepted. Historical phrasing in comments — fixed; they state the current contract rather than narrate what used to happen, per the comment conventions in Verification: One note on Written by an agent (Claude Code, claude-opus-5[1m]). |
|
Code review by qodo was updated up to the latest commit cee6559 |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
…m#13340) The `with-registry` jest preset built its verdaccio-shaped storage into a fresh mkdtemp directory on every run, but globalTeardown only killed the server — the directory was never removed, so every run of every registry-backed suite leaked one permanently (~2 MB for a small suite, up to ~2 GB for suites that proxy real packages). On a tmpfs /tmp they accumulate until it fills, and the suite then fails with ENOSPC in whichever test happens to write next — which reads as flakiness, since a different test fails each run and each passes in isolation. globalSetup now hands the path it created to globalTeardown through `global`, the same way it already hands over killServer, so teardown removes only that run's directory. Removal happens after the server is killed, since pnpr writes proxy-cache entries into the storage while serving. A failed removal warns rather than throwing. Related to pnpm#13328.
Summary
The
with-registryjest preset never removed the storage it built, so every run of every registry-backed suite leaked a temp directory permanently.globalSetupcreates one withmkdtempand builds verdaccio-shaped storage into it;globalTeardownonly killed the server. Sizes vary with how much a suite proxies — a small suite leaves ~2 MB, suites that pull real packages through the proxy cache leave up to ~2 GB.Where
/tmpis a tmpfs these accumulate until it fills, at which point the suite starts failing with:That reads as flakiness rather than a full disk — a different arbitrary test fails on each run, each passes in isolation, and a fresh checkout passes because nothing has accumulated yet. I chased it as a code bug for a while before reading the stderr. I had 78 of these directories by the time I noticed. Context in #13328.
Approach
globalSetuphands the path it created toglobalTeardownthroughglobal, the same channel it already uses forkillServer. Teardown removes only that directory, so a storage path supplied from outside could never be deleted by it.Two details:
/tmp.Verification
Ran
pnpm --filter=@pnpm/cache.commands testwith and without the change, diffing/tmparound it:pnpm run lintpasses.Existing leftovers are not swept — deleting
pnpm-registry-mock-storage-*wholesale would race with any concurrently running suite. Clean them once by hand withrm -rf /tmp/pnpm-registry-mock-storage-*while no tests are running; after this change nothing new accumulates.Squash Commit Body
Checklist
pnpm/port, or the description notes what still needs porting.(No pacquet counterpart: its fixture storage is content-fingerprinted under
target/and reused across runs rather than created per run, so it does notleak.)
pnpm changeset) if this PR changes any publishedpackage. (
@pnpm/jest-configis private — no changeset.)/tmparound a real suite run, with and without the change.)
Written by an agent (Claude Code, claude-opus-5[1m]).
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Summary by CodeRabbit