Skip to content

test(cli): cover skipped optional lockfile reconstruction - #13425

Merged
zkochan merged 2 commits into
mainfrom
fix-13317
Jul 27, 2026
Merged

zkochan merged 2 commits into
mainfrom
fix-13317

Conversation

@zkochan

@zkochan zkochan commented Jul 27, 2026 •

Copy link
Copy Markdown
Member

Summary

Extends the deleted-wanted-lockfile reconstruction test with a platform-incompatible optional dependency and the exact lockfile-only reconstruction sequence from #13317.

The production fix landed on main in #13350 because #13312 had the same root cause. This follow-up verifies that node_modules/.pnpm/lock.yaml retains the skipped optional importer entry and snapshots, and that deleting pnpm-lock.yaml reconstructs it byte-for-byte.

Closes #13317

Squash Commit Body

Exercise deleted wanted-lockfile reconstruction with an optional dependency
that is incompatible on every OS. Assert that the frozen install retains the
complete graph in the current lockfile before deleting pnpm-lock.yaml, then
verify lockfile-only reconstruction reproduces the original file.

The production fix landed with pnpm/pnpm#13350 for the same root cause as
pnpm/pnpm#13312. This test pins its reconstruction consequence.

Closes pnpm/pnpm#13317

Checklist

  • The change is implemented in both the TypeScript CLI and the Rust
    pnpm/ port, or the description notes what still needs porting.
    (Test-only pacquet follow-up; the TypeScript CLI already behaves correctly.)
  • Added or updated tests.

Written by an agent (Codex, GPT-5).


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Summary by CodeRabbit

  • Bug Fixes
    • Improved lockfile regeneration to correctly preserve platform-skipped optional dependencies when re-generating from an existing setup.
    • Added stronger validation that regenerated pnpm-lock.yaml and the resulting “current” lockfile remain consistent, including optional dependency entries and related snapshots.

Copilot AI review requested due to automatic review settings July 27, 2026 11:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: b96cb29e-e800-49d1-bfe8-7a12bff5acf0

📥 Commits

Reviewing files that changed from the base of the PR and between c49245f and 42fecdc.

📒 Files selected for processing (1)
  • pnpm/crates/cli/tests/current_lockfile.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • pnpm/crates/cli/tests/current_lockfile.rs

📝 Walkthrough

Walkthrough

The lockfile regeneration test adds a platform-skipped optional dependency and validates optional metadata retention, exact wanted-lockfile regeneration, and structural current-lockfile equality before and after regeneration.

Changes

Lockfile regeneration regression

Layer / File(s) Summary
Optional dependency lockfile validation
pnpm/crates/cli/tests/current_lockfile.rs
Adds optional-dependency retention assertions, compares parsed wanted and current lockfiles, regenerates with --lockfile-only --prefer-frozen-lockfile, and verifies exact text plus unchanged current-lockfile structure.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

Possibly related PRs

  • pnpm/pnpm#13081 — Related frozen-lockfile validation for optional dependencies.
  • pnpm/pnpm#13141 — Related skipped-optional handling and lockfile preservation.
  • pnpm/pnpm#13152 — Related platform-skipped optional-dependency lockfile coverage.

Suggested labels: product: pacquet

Suggested reviewers: copilot

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-13317

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

test(cli): ensure lockfile-only reconstruction preserves skipped optional deps

🧪 Tests 🕐 20-40 Minutes

Grey Divider

AI Description

• Extend current-lockfile regeneration test with an always-incompatible optional dependency.
• Assert current lockfile retains skipped optional importer data after frozen install.
• Verify deleting pnpm-lock.yaml rebuilds it byte-for-byte from current lockfile.
Diagram

graph TD
  A["Rust CLI test: deleted wanted lockfile"] --> B["pacquet: install --lockfile-only"] --> C[("pnpm-lock.yaml (wanted)")]
  C --> D["pnpm: install --frozen-lockfile"] --> E[("node_modules/.pnpm/lock.yaml (current)")]
  E --> F["delete wanted + workspace state"] --> G["pnpm: install --lockfile-only --prefer-frozen-lockfile"] --> H[("regenerated pnpm-lock.yaml")]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Assert only specific lockfile sections (importers/snapshots)
  • ➕ Less brittle than full-structure equality if unrelated lockfile formatting changes
  • ➕ Focuses the test on the regression surface (skipped optional importer entry)
  • ➖ Weaker guarantee than full lockfile equivalence; may miss subtle graph-loss regressions
  • ➖ More bespoke parsing/selection logic in the test
2. Compare normalized/serialized lockfile output instead of raw bytes
  • ➕ Avoids failures from benign YAML formatting differences
  • ➕ Still validates semantic reconstruction correctness
  • ➖ Does not catch byte-for-byte reconstruction regressions the issue cares about
  • ➖ Requires a stable normalization strategy across implementations

Recommendation: Current approach is appropriate because it pins the exact regression consequence: the current lockfile must retain skipped optional dependency data, and lockfile-only reconstruction must reproduce the original wanted lockfile byte-for-byte. The added full-structure equality check before deletion reduces false positives by ensuring the current lockfile already contains the complete graph.

Files changed (1) +18 / -4

Tests (1) +18 / -4
current_lockfile.rsStrengthen wanted-lockfile reconstruction test for skipped optional deps +18/-4

Strengthen wanted-lockfile reconstruction test for skipped optional deps

• Extends the deleted wanted-lockfile regeneration test to include a platform-incompatible optional dependency and to follow the lockfile-only → frozen install → delete wanted → lockfile-only reconstruction sequence. Adds an assertion that the current lockfile equals the original wanted lockfile structure (ensuring skipped optional importer data is retained) and verifies reconstruction reproduces the original pnpm-lock.yaml exactly while keeping the current lockfile unchanged.

pnpm/crates/cli/tests/current_lockfile.rs

@greptile-apps

greptile-apps Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Reviews (2): Last reviewed commit: "test(cli): assert skipped optional lockf..." | Re-trigger Greptile

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
pnpm/crates/cli/tests/current_lockfile.rs (1)

135-138: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Log lockfile values before asserting equality.

Use dbg! for the parsed Lockfile values and eprintln! for the multi-line YAML text, binding the regenerated values first if necessary. This will make structural and byte-for-byte failures actionable.

As per coding guidelines, complex structures and multi-line strings should be logged before non-scalar assertions. Based on learnings, full multi-line lockfile values should be printed before comparison.

Also applies to: 152-157

🤖 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/cli/tests/current_lockfile.rs` around lines 135 - 138, In the
current_lockfile test, bind the regenerated and expected lockfile values before
the equality assertions, then log both parsed Lockfile structures with dbg! and
their full multi-line YAML representations with eprintln! before asserting.
Apply the same diagnostic logging to the additional assertion around the second
comparison, while preserving the existing equality checks and messages.

Sources: Coding guidelines, Learnings

🤖 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 `@pnpm/crates/cli/tests/current_lockfile.rs`:
- Around line 120-138: The current_lockfile test only compares reconstructed and
original lockfiles without proving the skipped optional dependency exists. In
the test around the package.json setup and lockfile regeneration, add explicit
structural assertions before deletion and after rerunning the frozen install
that `@pnpm.e2e/not-compatible-with-any-os` is present in both the importer
optionalDependencies and the relevant snapshot section, while preserving the
existing equality assertion.

---

Nitpick comments:
In `@pnpm/crates/cli/tests/current_lockfile.rs`:
- Around line 135-138: In the current_lockfile test, bind the regenerated and
expected lockfile values before the equality assertions, then log both parsed
Lockfile structures with dbg! and their full multi-line YAML representations
with eprintln! before asserting. Apply the same diagnostic logging to the
additional assertion around the second comparison, while preserving the existing
equality checks and messages.
🪄 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: 0a8138c9-f83a-4e46-b5f0-0b787257dd3c

📥 Commits

Reviewing files that changed from the base of the PR and between 45224c4 and c49245f.

📒 Files selected for processing (1)
  • pnpm/crates/cli/tests/current_lockfile.rs

@github-actions

github-actions Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Micro-Benchmark Results

Linux

group                          main                                   pr
-----                          ----                                   --
lockfile/parse_pnpm_lock       1.02     11.0±0.18ms    34.1 MB/sec    1.00     10.7±0.13ms    34.9 MB/sec
packument/parse                1.04     39.1±0.61µs  1697.5 MB/sec    1.00     37.4±0.52µs  1772.1 MB/sec
tarball/download_dependency    1.05      3.0±0.26ms  1461.4 KB/sec    1.00      2.8±0.17ms  1535.4 KB/sec

@qodo-code-review

qodo-code-review Bot commented Jul 27, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (1) 📜 Skill insights (0)

Context used
✅ Compliance rules (platform): 24 rules

Grey Divider


Remediation recommended

1. Unconditional dbg!/eprintln! output 📘 Rule violation ⚙ Maintainability ⭐ New
Description
New unconditional dbg!/eprintln! calls in the lockfile regression test dump full lockfile
structures and entire pnpm-lock.yaml contents to stderr even when the test passes, creating noisy
output and avoidable formatting/IO overhead. This debug printing is unrelated to verifying the bug
fix and can bloat CI logs or slow test runs, making failures harder to spot.
Code

pnpm/crates/cli/tests/current_lockfile.rs[R31-33]

+fn assert_skipped_optional_is_retained(lockfile: &pacquet_lockfile::Lockfile) {
+    dbg!(lockfile);
+    assert!(
Relevance

⭐⭐⭐ High

Team previously removed unconditional test debug output as CI noise; similar cleanup merged in PR
#13293.

PR-#13293
PR-#13382

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 2255067 calls for bug-fix changes to avoid unrelated modifications, and the cited
test lines introduce always-on debug output that is not required for the regression assertions.
Specifically, the helper assert_skipped_optional_is_retained() and the test itself contain
unconditional dbg! calls that will execute on the success path and emit full lockfile structures,
and an eprintln! prints both the original and regenerated pnpm-lock.yaml strings
unconditionally; together these citations demonstrate large/noisy stderr output even when assertions
pass, which the repo review guidance discourages unless actionable.

Rule 2255067: Bug fix changes must not include unrelated refactors or reformatting
pnpm/crates/cli/tests/current_lockfile.rs[31-33]
pnpm/crates/cli/tests/current_lockfile.rs[154-154]
pnpm/crates/cli/tests/current_lockfile.rs[174-174]
pnpm/crates/cli/tests/current_lockfile.rs[183-183]
pnpm/crates/cli/tests/current_lockfile.rs[152-154]
pnpm/crates/cli/tests/current_lockfile.rs[179-184]
pnpm/crates/cli/tests/current_lockfile.rs[172-174]
REVIEW_GUIDE.md[198-201]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The lockfile regression test introduces unconditional `dbg!`/`eprintln!` debug printing that outputs full lockfile structures and entire `pnpm-lock.yaml` contents to stderr on every successful run. This creates noisy CI logs and adds avoidable formatting/IO overhead that is unrelated to asserting correctness.

## Issue Context
This PR is intended to add regression coverage, not permanent debug logging. CI runs these tests frequently, and emitting large structured data/YAML unconditionally can slow runs, bloat log volume, and make actionable failures harder to spot; if diagnostics are needed, they should be shown only on failure (e.g., via assertion messages that format only when failing), gated behind an env var, or reduced to targeted excerpts.

## Fix Focus Areas
- pnpm/crates/cli/tests/current_lockfile.rs[31-33]
- pnpm/crates/cli/tests/current_lockfile.rs[152-154]
- pnpm/crates/cli/tests/current_lockfile.rs[154-154]
- pnpm/crates/cli/tests/current_lockfile.rs[172-174]
- pnpm/crates/cli/tests/current_lockfile.rs[174-174]
- pnpm/crates/cli/tests/current_lockfile.rs[179-184]
- pnpm/crates/cli/tests/current_lockfile.rs[183-183]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Test can false-green ✓ Resolved 🐞 Bug ☼ Reliability
Description
a_deleted_wanted_lockfile_is_regenerated_from_the_current_one only asserts `current ==
wanted_lockfile` but never asserts the platform-incompatible optional dependency is actually present
in the lockfile graph. If future behavior drops that optional subtree from both wanted and current
lockfiles, this test will still pass while no longer validating the intended regression surface
(retaining skipped optional importers/snapshots).
Code

pnpm/crates/cli/tests/current_lockfile.rs[R132-138]

+    let current = read_current_lockfile(&workspace);
+    let wanted_lockfile =
+        serde_saphyr::from_str(&wanted).expect("parse the original pnpm-lock.yaml");
+    assert_eq!(
+        current, wanted_lockfile,
+        "the current lockfile must retain the platform-skipped optional dependency",
+    );
Relevance

⭐⭐⭐ High

Team frequently accepts test hardening to prevent false-greens (explicit presence/behavior
assertions). See #13378, #13406.

PR-#13378
PR-#13406

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The changed test only parses the wanted lockfile and asserts structural equality with the current
lockfile, without asserting the optional dependency’s key exists anywhere. Existing tests for the
same fixture pattern explicitly assert that the skipped optional package metadata remains present in
both wanted and current lockfiles, and the current-lockfile filtering code documents that
installability-skipped snapshots stay in the current lockfile, indicating this test should assert
presence to ensure it’s exercising that behavior.

pnpm/crates/cli/tests/current_lockfile.rs[110-158]
pnpm/crates/cli/tests/optional_dependencies.rs[347-390]
pnpm/crates/package-manager/src/current_lockfile.rs[1-15]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
The test compares the full parsed wanted/current lockfiles for equality but does not independently verify that the platform-incompatible optional dependency (and/or its snapshot/metadata) exists in the wanted lockfile. This can make the test pass even if the optional subtree is missing from both lockfiles, turning the new coverage into a false-green for the intended behavior.

### Issue Context
Other optional-dependency tests explicitly assert that platform-skipped optionals remain present in wanted/current lockfiles, and the current-lockfile filter docs state installability skips stay in the file. This test should similarly assert presence before relying on equality.

### Fix Focus Areas
- pnpm/crates/cli/tests/current_lockfile.rs[131-138]

### Suggested change
After parsing `wanted_lockfile`, add an explicit assertion that it contains the skipped optional package key (and ideally its transitive dep) in `packages` and/or `snapshots`, e.g. checking `wanted_lockfile.packages.as_ref().unwrap().keys().any(|k| k.to_string() == "@pnpm.e2e/[email protected]")`, before `assert_eq!(current, wanted_lockfile, ...)`.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Previous review results

Review updated until commit 42fecdc

Results up to commit c49245f ⚖️ Balanced


🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)


Remediation recommended
1. Test can false-green ✓ Resolved 🐞 Bug ☼ Reliability
Description
a_deleted_wanted_lockfile_is_regenerated_from_the_current_one only asserts `current ==
wanted_lockfile` but never asserts the platform-incompatible optional dependency is actually present
in the lockfile graph. If future behavior drops that optional subtree from both wanted and current
lockfiles, this test will still pass while no longer validating the intended regression surface
(retaining skipped optional importers/snapshots).
Code

pnpm/crates/cli/tests/current_lockfile.rs[R132-138]

+    let current = read_current_lockfile(&workspace);
+    let wanted_lockfile =
+        serde_saphyr::from_str(&wanted).expect("parse the original pnpm-lock.yaml");
+    assert_eq!(
+        current, wanted_lockfile,
+        "the current lockfile must retain the platform-skipped optional dependency",
+    );
Relevance

⭐⭐⭐ High

Team frequently accepts test hardening to prevent false-greens (explicit presence/behavior
assertions). See #13378, #13406.

PR-#13378
PR-#13406

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The changed test only parses the wanted lockfile and asserts structural equality with the current
lockfile, without asserting the optional dependency’s key exists anywhere. Existing tests for the
same fixture pattern explicitly assert that the skipped optional package metadata remains present in
both wanted and current lockfiles, and the current-lockfile filtering code documents that
installability-skipped snapshots stay in the current lockfile, indicating this test should assert
presence to ensure it’s exercising that behavior.

pnpm/crates/cli/tests/current_lockfile.rs[110-158]
pnpm/crates/cli/tests/optional_dependencies.rs[347-390]
pnpm/crates/package-manager/src/current_lockfile.rs[1-15]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
The test compares the full parsed wanted/current lockfiles for equality but does not independently verify that the platform-incompatible optional dependency (and/or its snapshot/metadata) exists in the wanted lockfile. This can make the test pass even if the optional subtree is missing from both lockfiles, turning the new coverage into a false-green for the intended behavior.

### Issue Context
Other optional-dependency tests explicitly assert that platform-skipped optionals remain present in wanted/current lockfiles, and the current-lockfile filter docs state installability skips stay in the file. This test should similarly assert presence before relying on equality.

### Fix Focus Areas
- pnpm/crates/cli/tests/current_lockfile.rs[131-138]

### Suggested change
After parsing `wanted_lockfile`, add an explicit assertion that it contains the skipped optional package key (and ideally its transitive dep) in `packages` and/or `snapshots`, e.g. checking `wanted_lockfile.packages.as_ref().unwrap().keys().any(|k| k.to_string() == "@pnpm.e2e/[email protected]")`, before `assert_eq!(current, wanted_lockfile, ...)`.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Qodo Logo

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

@codecov-commenter

codecov-commenter commented Jul 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.60%. Comparing base (45224c4) to head (42fecdc).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #13425   +/-   ##
=======================================
  Coverage   87.60%   87.60%           
=======================================
  Files         545      545           
  Lines       93684    93698   +14     
=======================================
+ Hits        82069    82083   +14     
  Misses      11615    11615           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI review requested due to automatic review settings July 27, 2026 11:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Jul 27, 2026
@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 42fecdc

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product: pacquet reviewed: coderabbit CodeRabbit submitted an approving review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pnpm 12 silently drops platform-skipped optional dependencies when it reconstructs a deleted pnpm-lock.yaml

3 participants