Repository navigation
test: stop leaking temp dirs from three test fixtures - #13342
Conversation
`TempDir::keep()` disables cleanup, and three of the four sites using it did not need to: the `'static` requirement was on the value being leaked (`StoreDir`, `Config`), never on the directory. A full run left ~45 directories in the system temp dir; it now leaves ~10. - `overrides::tests::manifest_from_value` wrote a `package.json` only to read it straight back, for a path its own doc calls a stub. It builds the manifest with `PackageManifest::from_value` instead, which touches no filesystem at all — one leak per call across ~25 callers, gone, and the helper drops to one line. The `needless_pass_by_value` expectation goes with it: `from_value` consumes the value. - `env_installer::tests::harness` leaked the store directory alongside the `&'static StoreDir` pointing at it. The `TempDir` moves into `Harness`, which already exists to hold per-test handles, so it drops with the harness. `build_resolver` in the same file already did it this way. - `install_package_from_registry::tests::create_config` leaked a cache dir while every caller was separately creating one of its own and passing it to the resolver. It takes the caller's, so the config and the resolver now share a cache the way they do in practice, and the caller's `TempDir` does the cleaning. Two callers that had no cache dir gained one. `cli/tests/pnpr_install.rs` keeps its `keep()`: the detached server thread outlives both the function and the test, so there is no point at which the storage can be removed without a shutdown handle for that thread. Add `just sweep-test-temp` for the rest. A killed test process cannot run `Drop`, so a fail-fast or interrupted run always abandons whole fixture trees — for the mocked-registry tests that includes a per-test store, which is how a machine ends up with hundreds of megabytes of them. The sweep skips anything under an hour old so it cannot disturb a concurrent run. Redirecting `TMPDIR` at the whole suite looked like the stronger fix and does not work: tests assert on stderr containing paths under the temp dir, so `custom_resolvers::failing_should_refresh_resolution_aborts_the_install` fails, and a `TMPDIR` under `target/` additionally breaks `frozen_lockfile_applies_overrides_to_manifest_before_freshness_check`, because the walk for `pnpm-workspace.yaml` then finds this repo's own. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Warning Review limit reached
Next review available in: 13 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 (3)
📝 WalkthroughWalkthroughThe changes add stale test-artifact cleanup, make test temporary-directory ownership explicit, pass cache directories into registry-install test configuration, and construct override manifests directly from in-memory JSON. ChangesTest temporary-resource cleanup
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
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 QodoTests: stop leaking temp dirs from three fixtures (and add temp sweep task)
AI Description
Diagram
High-Level Assessment
Files changed (4)
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
pnpm/crates/env-installer/src/tests.rs (1)
81-84: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse a regular comment for this private implementation detail.
_store_rootis private, and this text explains ownership rationale rather than a public API contract. Per the Rust documentation guideline, use//instead of///.Proposed change
- /// Owns the directory `store_dir` points at. Only the [`StoreDir`] value - /// has to be `'static`, so the directory itself is dropped with the - /// harness rather than left behind for the run's temp dir to accumulate. + // Owns the directory `store_dir` points at. Only the `StoreDir` value + // has to be `'static`, so the directory itself is dropped with the + // harness rather than left behind for the run's temp dir to accumulate.As per coding guidelines, use rustdoc comments for public API contracts and regular comments for implementation rationale.
🤖 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 `@pnpm/crates/env-installer/src/tests.rs` around lines 81 - 84, Replace the rustdoc comment above the private `_store_root` field with a regular `//` comment, preserving the existing ownership rationale without documenting it as a public API contract.Source: Coding guidelines
🤖 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 `@justfile`:
- Around line 61-63: Harden the sweep-test-temp recipe by constraining and
validating the TMPDIR root before searching, adding -mindepth 1 so the root
itself cannot match, and narrowing both find patterns to test-owned prefixes or
markers. Ensure every rm -rf target is produced only from this constrained root
and ownership-specific matching, preserving the existing age threshold.
---
Nitpick comments:
In `@pnpm/crates/env-installer/src/tests.rs`:
- Around line 81-84: Replace the rustdoc comment above the private `_store_root`
field with a regular `//` comment, preserving the existing ownership rationale
without documenting it as a public API contract.
🪄 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: 8abee3bf-f38c-4cf4-8cdf-2b50c7553b7f
📒 Files selected for processing (4)
justfilepnpm/crates/env-installer/src/tests.rspnpm/crates/package-manager/src/install_package_from_registry/tests.rspnpm/crates/package-manager/src/overrides/tests.rs
Micro-Benchmark ResultsLinux |
Code Review by Qodo
Context used✅ Compliance rules (platform):
24 rules 1. Silent sweep failures
|
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Reviews (2): Last reviewed commit: "test: sweep only fixture trees this suit..." | Re-trigger Greptile |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main pnpm/pnpm#13342 +/- ##
=======================================
Coverage 87.04% 87.04%
=======================================
Files 534 535 +1
Lines 91806 91827 +21
=======================================
+ Hits 79911 79934 +23
+ Misses 11895 11893 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The sweep matched `.tmp*`, which is `tempfile`'s default prefix and so belongs to every crate that uses it — age is not ownership, and the recipe would have deleted unrelated programs' temp data. It could also match its own starting directory, making a `TMPDIR` named `.tmp*` or `pnpm-e2e-*` the target of `rm -rf`. Give `CommandTempCwd` a `pacquet-test-` prefix instead and sweep only that. One site covers the trees that matter: they hold a per-test store for the mocked-registry tests and are the bulk of what an interrupted run abandons. `-mindepth 1` keeps the root out of the match. Verified both directions — a stale `pacquet-test-*` is removed, an unrelated `.tmp*` of the same age is left alone. The longer prefix then exposed a test that was fragile to path length: `deploy_all_files_rejects_symlink_escape` asserted on `"resolves outside"`, which miette had been wrapping across a line break once the path grew. It matches whitespace-collapsed output now, so where miette wraps no longer decides whether it passes. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Both of you were right, and this was the dangerous kind of wrong — fixed in 08c4fe8. Greptile: cleanup deletes unrelated temp data. CodeRabbit: constrain the root and the targets. Also right, and the What it does nowOwnership is established rather than guessed. One site covers what matters — those trees hold a per-test store for the mocked-registry tests and are the bulk of what an interrupted run abandons. Verified both directions: The prefix exposed a real test bug
So it was fragile to temp-path length all along and would break for anyone whose Full workspace suite: 7063 pass, lint and dylint clean. Written by an agent (Claude Code, claude-opus-5). |
|
Code review by qodo was updated up to the latest commit 08c4fe8 |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
`TempDir::keep()` disables cleanup, and three of the four sites using it did not need to: the `'static` requirement was on the value being leaked (`StoreDir`, `Config`), never on the directory. A full run left ~45 directories in the system temp dir; it now leaves ~10. - `overrides::tests::manifest_from_value` wrote a `package.json` only to read it straight back, for a path its own doc calls a stub. It builds the manifest with `PackageManifest::from_value` instead, which touches no filesystem at all — one leak per call across ~25 callers, gone, and the helper drops to one line. - `env_installer::tests::harness` leaked the store directory alongside the `&'static StoreDir` pointing at it. The `TempDir` moves into `Harness`, which already exists to hold per-test handles. - `install_package_from_registry::tests::create_config` leaked a cache dir while every caller was separately creating one of its own and passing it to the resolver. It takes the caller's, so the config and the resolver now share a cache the way they do in practice. `cli/tests/pnpr_install.rs` keeps its `keep()`: the detached server thread outlives both the function and the test. Add `just sweep-test-temp` for the rest. A killed test process cannot run `Drop`, so a fail-fast or interrupted run always abandons whole fixture trees, including a per-test store for the mocked-registry tests. The sweep skips anything under an hour old so it cannot disturb a concurrent run. Redirecting `TMPDIR` at the whole suite does not work: tests assert on stderr containing paths under the temp dir, and a `TMPDIR` under `target/` makes the walk for `pnpm-workspace.yaml` find this repo's own. Related to pnpm/pnpm#12485.
Summary
TempDir::keep()disables cleanup. Four test fixtures used it; three did not need to, because the'staticrequirement was on the value being leaked (StoreDir,Config), never on the directory. Measured on a fullcargo nextest run:Small in bytes (~1 MB), but they accumulate across runs and never get collected.
The three fixes
overrides::tests::manifest_from_value(~25 callers) wrote apackage.jsononly to read it straight back, for a path its own doc comment calls a stub. It now usesPackageManifest::from_value, which touches no filesystem at all — the helper drops to one line. Theneedless_pass_by_valueexpectation goes with it, sincefrom_valueconsumes the value.env_installer::tests::harness(~20 callers) leaked the store directory along with the&'static StoreDirpointing at it. TheTempDirmoves intoHarness, which already exists to hold per-test handles.build_resolverin the same file already did exactly this.install_package_from_registry::tests::create_config(5 callers) leaked a cache dir while every caller was separately creating one of its own and passing it to the resolver. It takes the caller's, so the config and resolver now share one cache the way they do in practice, and the caller'sTempDirdoes the cleaning. Two callers that had no cache dir gained one.The fourth stays
cli/tests/pnpr_install.rskeeps itskeep(), with its existing justification: the detached server thread outlives both the function and the test, so there is no point at which the storage can be removed without giving that thread a shutdown handle. One directory per run.just sweep-test-tempA killed test process cannot run
Dropat all, so a fail-fast or interrupted run always abandons whole fixture trees — and for the mocked-registry tests each tree contains a per-test store, which is how a machine accumulates hundreds of megabytes ofpnpm-e2e-*. No amount ofDropcorrectness fixes that, so this sweeps them. It skips anything under an hour old, so it cannot disturb a concurrent run.What I tried and rejected
Redirecting
TMPDIRfor the whole suite looked like the stronger fix — one per-run directory, wiped up front, bounding everything including killed-process leakage. It does not work:custom_resolvers::failing_should_refresh_resolution_aborts_the_installfails on the changed pnpmfile path.TMPDIRundertarget/additionally breaksfrozen_lockfile_applies_overrides_to_manifest_before_freshness_check, because the upward walk forpnpm-workspace.yamlthen finds this repo's own.Worth recording so the next person does not spend the same time on it.
Verification
Full workspace suite: 7063 tests pass, lint and dylint clean. Leak count measured before and after by counting
/tmp/.tmp*across runs.Tests and one
justfilerecipe only — no published behavior changes, so no changeset.Related to pnpm/tasks#32.
Squash Commit Body
Checklist
pnpm/port, or the description notes what still needs porting.Rust test fixtures only; nothing user-visible to mirror.
pnpm changeset) if this PR changes any publishedpackage. Keep it short and written for pnpm users — it becomes a release note.
Not applicable: tests and a
justfilerecipe, no published behavior.This is a change to test fixtures; the existing suites cover them.
Written by an agent (Claude Code, claude-opus-5).
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Summary by CodeRabbit
Chores
Tests