Skip to content

fix(napi): support trustLockfile option - #13489

Merged
zkochan merged 2 commits into
mainfrom
fix/napi-trust-lockfile-default
Jul 29, 2026
Merged

zkochan merged 2 commits into
mainfrom
fix/napi-trust-lockfile-default

Conversation

@zkochan

@zkochan zkochan commented Jul 29, 2026 •

Copy link
Copy Markdown
Member

Expose trustLockfile through the NAPI InstallOptions and config overlay.

This lets embedders such as Bit explicitly trust existing lockfiles while migrating to pnpm v12. The NAPI and pnpm CLI defaults remain unchanged.

Tests:

  • cargo test -p pacquet-napi install::tests
  • repository pre-push checks

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

  • New Features

    • Added an optional trustLockfile install setting.
    • When enabled, lockfile resolutions are trusted without verifying them against current registry metadata.
    • Available via the installation API and updated type definitions.
  • Tests

    • Added coverage to confirm the install option is correctly applied to the resolved configuration, including default behavior when the option is omitted.

Copilot AI review requested due to automatic review settings July 29, 2026 10:47

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 29, 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: 98f39426-36c4-4d28-8e95-d670676bd0c7

📥 Commits

Reviewing files that changed from the base of the PR and between e46f9fa and 4950856.

📒 Files selected for processing (2)
  • .changeset/napi-trust-lockfile.md
  • pnpm/crates/napi/src/install/tests.rs

📝 Walkthrough

Walkthrough

Adds an optional trustLockfile install option to the N-API, forwards it through ConfigOverlay, applies it to engine configuration, updates TypeScript declarations and package metadata, and tests explicit and default behavior.

Changes

Lockfile trust configuration

Layer / File(s) Summary
Engine configuration overlay
pnpm/crates/napi/src/config.rs
ConfigOverlay accepts trust_lockfile and applies it to the resolved configuration when present.
N-API install option wiring and validation
pnpm/crates/napi/src/install.rs, pnpm/crates/napi/src/install/tests.rs, pnpm/npm/napi/index.d.ts
InstallOptions exposes and forwards trust_lockfile; tests cover explicit and unset values, and TypeScript exposes trustLockfile.
Package release metadata
.changeset/napi-trust-lockfile.md
Adds a minor changeset describing the new trustLockfile install option.

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

Possibly related PRs

  • pnpm/pnpm#13017: Adds related trustLockfile handling through the pnpr server request and install path.

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/napi-trust-lockfile-default

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

Expose trustLockfile in NAPI install options and config overlay

🐞 Bug fix 🧪 Tests 🕐 20-40 Minutes

Grey Divider

AI Description

• Add trustLockfile to NAPI install options and propagate it into the Rust config overlay.
• Apply overlayed trust_lockfile to the final pacquet config during config build.
• Extend NAPI install overlay tests to cover mapping and default preservation.
Diagram

graph TD
  A{{"JS embedder"}} --> B["npm/napi index.d.ts"] --> C["InstallOptions (Rust)"] --> D["build_overlay()"] --> E["ConfigOverlay"] --> F["build_config()"] --> G["pacquet Config"]
Loading
High-Level Assessment

The PR’s approach (threading a new option through InstallOptions → ConfigOverlay → Config) is the most straightforward and keeps defaults unchanged by using Option and preserving None when unspecified. Alternatives like adding an env var or changing defaults would be more invasive and contrary to the stated goal.

Files changed (4) +24 / -0

Enhancement (1) +4 / -0
install.rsExpose trust_lockfile on NAPI InstallOptions and map into overlay +4/-0

Expose trust_lockfile on NAPI InstallOptions and map into overlay

• Adds 'trust_lockfile: Option<bool>' to the NAPI 'InstallOptions' struct. Updates 'build_overlay' to forward the value into 'ConfigOverlay' so embedders can opt in without changing defaults.

pnpm/crates/napi/src/install.rs

Bug fix (1) +6 / -0
config.rsAdd trust_lockfile to ConfigOverlay and apply it in config build +6/-0

Add trust_lockfile to ConfigOverlay and apply it in config build

• Introduces an optional 'trust_lockfile' field on 'ConfigOverlay' with docs describing its behavior. When set, 'build_config' now propagates this value into the resulting 'Config'.

pnpm/crates/napi/src/config.rs

Tests (1) +9 / -0
tests.rsTest trust_lockfile mapping and default preservation +9/-0

Test trust_lockfile mapping and default preservation

• Extends overlay mapping tests to assert 'trust_lockfile' is forwarded when provided. Adds a dedicated test ensuring the default remains 'None' when the option is not set, and updates the test options factory accordingly.

pnpm/crates/napi/src/install/tests.rs

Documentation (1) +5 / -0
index.d.tsAdd trustLockfile to TypeScript InstallOptions typings +5/-0

Add trustLockfile to TypeScript InstallOptions typings

• Extends the public TypeScript 'InstallOptions' interface with an optional 'trustLockfile' boolean and documentation explaining that it trusts lockfile resolutions without registry verification.

pnpm/npm/napi/index.d.ts

Comment thread pnpm/npm/napi/index.d.ts Resolved
Comment thread pnpm/crates/napi/src/install/tests.rs Resolved
@greptile-apps

greptile-apps Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 4/5

The implementation appears safe to merge, though the previously requested end-to-end NAPI behavioral coverage remains outstanding.

The release changeset is now present and the option is correctly propagated into the downstream verification gate, but the new test stops at resolved configuration and does not exercise lockfile verification through the NAPI install path.

Files Needing Attention: pnpm/crates/napi/src/install/tests.rs

Reviews (2): Last reviewed commit: "test(napi): cover resolved trust lockfil..." | Re-trigger Greptile

@qodo-code-review

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

Copy link
Copy Markdown

Code Review by Qodo

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

Context used
✅ Compliance rules (platform): 24 rules

Grey Divider


Remediation recommended

1. Flaky trustLockfile default test 🐞 Bug ☼ Reliability
Description
resolved_config_applies_trust_lockfile hard-codes (None, false), but resolve_config() loads
config from .npmrc, global config, and environment, so trust_lockfile can legitimately be true
and make this test fail in non-clean environments. This makes the test environment-dependent and can
cause false failures on developer machines/CI runners with custom pnpm config.
Code

pnpm/crates/napi/src/install/tests.rs[R99-104]

+    for (trust_lockfile, expected) in [(Some(false), false), (Some(true), true), (None, false)] {
+        let mut options = install_options();
+        options.trust_lockfile = trust_lockfile;
+        let overlay = build_overlay(&options).expect("overlay");
+        assert_eq!(resolve_config(dir.path(), &overlay).expect("config").trust_lockfile, expected);
+    }
Relevance

●●● Strong

Making tests hermetic (not dependent on user/global config) is a straightforward reliability fix
likely to be accepted.

PR-#13285

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The test assumes None implies false, but resolve_config() explicitly builds from
Config::current (which reads .npmrc and pnpm-workspace.yaml) and incorporates global/home
config and config-related environment variables, so the base trust_lockfile can vary by
environment.

pnpm/crates/napi/src/install/tests.rs[95-105]
pnpm/crates/napi/src/config.rs[21-24]
pnpm/crates/napi/src/config.rs[155-196]
pnpm/crates/napi/src/config.rs[229-246]

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

### Issue description
`resolved_config_applies_trust_lockfile` asserts `(None, false)` for the unset overlay case, but `resolve_config()` inherits configuration from external sources (home/global config + env). This makes the test non-hermetic.

### Issue Context
The test should verify that `Some(true)` / `Some(false)` override the resolved base config, and that `None` preserves whatever base config is in effect.

### Fix
Compute the baseline resolved `trust_lockfile` once (using the same overlay shape you’re testing), then assert:
- `Some(false)` => `false`
- `Some(true)` => `true`
- `None` => `baseline`

Example sketch:
- Resolve `baseline` with `trust_lockfile = None`.
- In the loop, set `expected = trust_lockfile.unwrap_or(baseline)`.

### Fix Focus Areas
- pnpm/crates/napi/src/install/tests.rs[95-105]

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


2. Missing trustLockfile security caveat 🐞 Bug ⛨ Security
Description
The changeset states that trustLockfile skips registry-metadata verification but omits the
documented warning that this disables supply-chain verification and should only be used when the
lockfile is part of the trusted base. Without that caveat, consumers may enable it without
understanding that a poisoned lockfile can bypass verification policies.
Code

.changeset/napi-trust-lockfile.md[5]

+Added the `trustLockfile` install option to skip verifying lockfile resolutions against current registry metadata.
Relevance

●●● Strong

Repo often accepts tightening changeset wording to accurately describe behavior and caveats;
low-risk doc-only change.

PR-#13403
PR-#11592

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The changeset currently only describes skipping verification, while the core config documentation
explicitly warns that a poisoned/untrusted lockfile can ‘slip through’ when this flag is enabled.

.changeset/napi-trust-lockfile.md[1-5]
pnpm/crates/config/src/lib.rs[1641-1650]

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 changeset documents the new `trustLockfile` option but doesn’t include the existing security warning about the implications of skipping lockfile verification.

### Issue Context
`trust_lockfile` is a deliberate opt-out from lockfile supply-chain verification; the repo already documents that it should only be used when the lockfile is trusted.

### Fix
Update the changeset text to add a short warning, e.g.:
- “Use only when the lockfile is from a trusted source / part of the trusted base; a poisoned lockfile can bypass verification.”

### Fix Focus Areas
- .changeset/napi-trust-lockfile.md[1-5]

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



Informational

3. Changeset missing pnpm entry 📘 Rule violation § Compliance
Description
The new changeset only lists @pnpm/napi and does not include the required pnpm package entry
with a valid bump type. This can break or misrepresent release/versioning automation expectations
for changesets.
Code

.changeset/napi-trust-lockfile.md[R1-3]

+---
+"@pnpm/napi": minor
+---
Relevance

● Weak

Multiple prior PRs rejected adding mandatory pnpm bumps when changeset already scoped to another
package.

PR-#13459
PR-#13347
PR-#13417

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 713436 requires each changeset to explicitly include a pnpm entry with a valid
bump type. The added changeset front-matter contains only @pnpm/napi: minor, with no pnpm
entry present.

Rule 713436: Explicitly declare pnpm package and correct bump type in changesets
.changeset/napi-trust-lockfile.md[1-3]

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 changeset `.changeset/napi-trust-lockfile.md` is missing a required `pnpm` package entry (with bump type `patch`/`minor`/`major`).

## Issue Context
Compliance requires changeset front-matter to explicitly declare `pnpm` and an appropriate bump type.

## Fix Focus Areas
- .changeset/napi-trust-lockfile.md[1-3]

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


Grey Divider

To customize comments, go to the Qodo configuration screen, or learn more in the docs.

Previous review results

Review updated until commit 4950856 ⚖️ Balanced

Results up to commit e46f9fa ⚖️ Balanced


No changes from previous review

Qodo Logo

@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.

🧹 Nitpick comments (1)
pnpm/crates/napi/src/install/tests.rs (1)

95-99: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Test the resolved configuration, not only the overlay.

These tests would still pass if build_config stopped applying trust_lockfile. Add a focused test covering Some(false), Some(true), and None against the resulting Config; this is the security-sensitive behavior of the option.

As per path instructions, “Tests must prove the changed 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 `@pnpm/crates/napi/src/install/tests.rs` around lines 95 - 99, Extend the tests
around build_config to assert the resolved Config.trust_lockfile value for
Some(false), Some(true), and None, rather than only checking build_overlay in
build_overlay_preserves_the_trust_lockfile_default. Configure each input option
explicitly and verify the resulting Config preserves the expected value,
including the default None case.

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 `@pnpm/crates/napi/src/install/tests.rs`:
- Around line 95-99: Extend the tests around build_config to assert the resolved
Config.trust_lockfile value for Some(false), Some(true), and None, rather than
only checking build_overlay in
build_overlay_preserves_the_trust_lockfile_default. Configure each input option
explicitly and verify the resulting Config preserves the expected value,
including the default None case.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: b6e716da-fd55-4247-a001-fc0e7519cef6

📥 Commits

Reviewing files that changed from the base of the PR and between 0ae2001 and e46f9fa.

📒 Files selected for processing (4)
  • pnpm/crates/napi/src/config.rs
  • pnpm/crates/napi/src/install.rs
  • pnpm/crates/napi/src/install/tests.rs
  • pnpm/npm/napi/index.d.ts

@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.

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

github-actions Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Micro-Benchmark Results

Linux

group                                            main                                   pr
-----                                            ----                                   --
lockfile/parse_pnpm_lock                         1.02     11.9±0.44ms    31.5 MB/sec    1.00     11.7±0.20ms    32.1 MB/sec
packument/parse                                  1.02     39.3±0.17µs  1687.4 MB/sec    1.00     38.6±0.19µs  1719.5 MB/sec
tarball/download_dependency                      1.00      2.3±0.11ms  1883.2 KB/sec    1.01      2.3±0.08ms  1860.5 KB/sec
tarball_batch/cold_store_many_medium_tarballs    1.06    194.6±6.89ms 82.2 KElem/sec    1.00    182.8±2.96ms 87.5 KElem/sec

@codecov-commenter

codecov-commenter commented Jul 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.91%. Comparing base (0ae2001) to head (4950856).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #13489      +/-   ##
==========================================
- Coverage   87.92%   87.91%   -0.01%     
==========================================
  Files         549      549              
  Lines       95534    95538       +4     
==========================================
  Hits        83995    83995              
- Misses      11539    11543       +4     

☔ 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 29, 2026 11:08

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.

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 4950856

@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.

@zkochan
zkochan merged commit 44e0ebf into main Jul 29, 2026
35 checks passed
@zkochan
zkochan deleted the fix/napi-trust-lockfile-default branch July 29, 2026 11:20
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.

3 participants