Skip to content

fix(pacquet): read legacy license fields - #13446

Merged
zkochan merged 1 commit into
mainfrom
fix-13438-2
Jul 27, 2026
Merged

zkochan merged 1 commit into
mainfrom
fix-13438-2

Conversation

@zkochan

@zkochan zkochan commented Jul 27, 2026 •

Copy link
Copy Markdown
Member

Summary

Aligns the Rust pnpm licenses list license values with TypeScript pnpm by reading both the modern license field and legacy licenses manifest forms. This completes the remaining license-value parity work for #13438.

Adds parser coverage for precedence, object, array, and multi-license forms, plus a CLI integration fixture that verifies a legacy license is reported under MIT.

Squash Commit Body

TypeScript pnpm resolves package licenses from both the modern `license` field and the deprecated `licenses` field. Pacquet only accepted a string `license`, causing packages such as `exit`, `prettysize`, and `seq-queue` to be reported as `Unknown`.

Add a shared package-manifest extractor matching TypeScript precedence and legacy-field handling, and use it in `pnpm licenses list`. Cover the parser directly and verify the CLI result with a registry fixture.

Closes pnpm/pnpm#13438.

Checklist

  • The change is implemented in both the TypeScript CLI and the Rust
    pnpm/ port, or the description notes what still needs porting.
  • Added a changeset (pnpm changeset) if this PR changes any published
    package. Keep it short and written for pnpm users — it becomes a release note.
  • 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
    • Fixed pnpm licenses list so packages using legacy license metadata are recognized correctly.
    • Added support for license declarations in strings, arrays, and structured entries.
    • Multiple distinct licenses are now displayed together using an “OR” format.
    • Packages with invalid or empty modern license fields can fall back to valid legacy metadata.
  • Tests
    • Expanded coverage for legacy license formats and license reporting output.

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

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: cef963a1-aff6-4930-8245-049bbf1ecf43

📥 Commits

Reviewing files that changed from the base of the PR and between 81411d3 and 750037c.

📒 Files selected for processing (6)
  • .changeset/wise-wolves-report.md
  • pnpm/crates/cli/src/cli_args/licenses.rs
  • pnpm/crates/cli/tests/licenses.rs
  • pnpm/crates/package-manifest/src/lib.rs
  • pnpm/crates/package-manifest/src/tests.rs
  • pnpr/.fixtures/packages/@pnpm.e2e/legacy-license/1.0.0/package.json

📝 Walkthrough

Walkthrough

The package manifest crate adds shared license extraction for modern and legacy fields. The licenses CLI uses it, with unit and end-to-end tests covering legacy MIT metadata and reported package paths.

Changes

Legacy license support

Layer / File(s) Summary
License extraction contract and coverage
pnpm/crates/package-manifest/src/lib.rs, pnpm/crates/package-manifest/src/tests.rs
Adds extract_license with support for string, array, and object license values, modern-field priority, legacy-field fallback, and corresponding unit tests.
Licenses CLI integration and fixture validation
pnpm/crates/cli/src/cli_args/licenses.rs, pnpm/crates/cli/tests/licenses.rs, pnpr/.fixtures/packages/..., .changeset/wise-wolves-report.md
Routes CLI license reporting through extract_license and verifies legacy MIT metadata, versions, and existing paths in JSON output.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Assessment against linked issues

Objective Addressed Explanation
Match TypeScript pnpm license values, dependency coverage, and production/development classification [#13438] ❓ The PR covers legacy license-value extraction, but the linked issue’s broader dependency-set and classification parity is not demonstrated by the provided changes.

Possibly related PRs

  • pnpm/pnpm#13090: Updates the licenses CLI extraction logic and is directly related to this shared legacy-license parsing 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-13438-2

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


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

fix(pacquet): read legacy package.json license fields

🐞 Bug fix 🧪 Tests 🕐 20-40 Minutes

Grey Divider

AI Description

• Extract license from both license and deprecated licenses manifest fields.
• Match TypeScript pnpm precedence and normalize multi-license legacy formats.
• Add unit + CLI fixture coverage to prevent Unknown license regressions.
Diagram

graph TD
  CLI["Rust CLI: licenses list"] --> Reader["Read package.json"] --> Extractor["extract_license()"] --> Manifest[("Manifest fields")]
  CLITest["CLI integration test"] --> CLI
  ManifestTests["Manifest unit tests"] --> Extractor
  Fixture["Legacy fixture pkg"] --> Manifest
Loading
High-Level Assessment

The shared extract_license helper in pacquet_package_manifest is the right approach: it centralizes TypeScript-parity rules (precedence + legacy forms) and avoids duplicating parsing logic in each CLI consumer. Alternatives like grouping multi-license arrays into multiple license buckets or introducing SPDX parsing would change output semantics and are better handled as separate, explicit feature work.

Files changed (6) +116 / -16

Bug fix (2) +44 / -5
licenses.rsUse shared license extractor for 'licenses list' output +3/-5

Use shared license extractor for 'licenses list' output

• Replaces direct 'manifest["license"] as str' access with 'extract_license', defaulting to 'Unknown' when no valid license can be derived.

pnpm/crates/cli/src/cli_args/licenses.rs

lib.rsAdd 'extract_license' supporting modern + legacy manifest formats +41/-0

Add 'extract_license' supporting modern + legacy manifest formats

• Introduces 'extract_license' with precedence ('license' first, then 'licenses') and support for string, object ('type'/'name'), array, and multi-license OR formatting, ignoring empty/invalid values.

pnpm/crates/package-manifest/src/lib.rs

Tests (3) +67 / -11
licenses.rsExtend CLI licenses test to cover legacy 'licenses' manifests +18/-10

Extend CLI licenses test to cover legacy 'licenses' manifests

• Adds a legacy-license fixture dependency and asserts both expected packages appear under the 'MIT' group, with valid paths and versions.

pnpm/crates/cli/tests/licenses.rs

tests.rsAdd unit tests for license extraction precedence and legacy forms +40/-1

Add unit tests for license extraction precedence and legacy forms

• Adds coverage for modern vs legacy precedence, object/array parsing, multi-license OR formatting, and fallback behavior when values are invalid/empty.

pnpm/crates/package-manifest/src/tests.rs

package.jsonAdd registry fixture package using legacy 'licenses' field +9/-0

Add registry fixture package using legacy 'licenses' field

• Introduces an e2e fixture package.json that declares 'licenses: [{ "type": "MIT" }]' to validate CLI output grouping.

pnpr/.fixtures/packages/@pnpm.e2e/legacy-license/1.0.0/package.json

Other (1) +5 / -0
wise-wolves-report.mdAdd changeset note for legacy license-field fix +5/-0

Add changeset note for legacy license-field fix

• Adds a patch changeset for 'pacquet' documenting that 'pnpm licenses list' now reads legacy manifest license fields.

.changeset/wise-wolves-report.md

@greptile-apps

greptile-apps Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

The PR appears safe to merge with no actionable correctness or security issues identified.

The new extractor matches the existing TypeScript license-resolution contract, and the CLI continues to group and render the resulting license values through its established output path.

Reviews (1): Last reviewed commit: "fix(pacquet): read legacy license fields" | Re-trigger Greptile

@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

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

Context used
✅ Compliance rules (platform): 32 rules

Grey Divider


Remediation recommended

1. Changeset missing pnpm entry 📘 Rule violation § Compliance
Description
The new changeset only bumps pacquet even though the PR changes user-visible pnpm licenses list
behavior, so the pnpm package release notes/versioning may not reflect this fix.
Code

.changeset/wise-wolves-report.md[R1-3]

+---
+"pacquet": patch
+---
Relevance

⭐⭐⭐ High

Similar changeset-frontmatter fixes (add pnpm bump for user-visible pnpm changes) were accepted
recently.

PR-#13403
PR-#13337

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
Compliance ID 713436 requires each added/modified changeset to include an explicit pnpm entry with
a valid bump type. The added changeset front-matter includes only pacquet and omits pnpm.

Rule 713436: Explicitly declare pnpm package and correct bump type in changesets
.changeset/wise-wolves-report.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 front-matter is missing a `pnpm` entry, which is required to correctly version/release user-visible pnpm changes.

## Issue Context
This PR fixes `pnpm licenses list` behavior; the changeset should include the `pnpm` package with an appropriate bump type (likely `patch`).

## Fix Focus Areas
- .changeset/wise-wolves-report.md[1-3]

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


2. JSON output allows visual spoofing 🐞 Bug ⛨ Security
Description
pnpm licenses list --json serializes attacker-controlled license strings (now including legacy
licenses[].type/name) without any terminal-safety escaping/sanitization, enabling Unicode
formatting/bidi characters to visually spoof license keys/values in terminals/CI logs. The non-JSON
table output uses sanitize_inline, so this discrepancy is specific to the JSON path and is newly
reachable for packages that only provide legacy licenses.
Code

pnpm/crates/cli/src/cli_args/licenses.rs[R215-218]

            let license = manifest
                .as_ref()
-                .and_then(|m| m.get("license"))
-                .and_then(|v| v.as_str())
-                .unwrap_or("Unknown")
-                .to_string();
+                .and_then(extract_license)
+                .unwrap_or_else(|| "Unknown".to_string());
Relevance

⭐⭐ Medium

Team accepts terminal-output sanitization, but JSON sanitization may be seen as breaking
machine-readable output.

PR-#13287
PR-#13202

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The PR changes license extraction to use extract_license, which reads legacy licenses entries;
that extracted string is used as the license group key and stored in LicenseInfo.license. In JSON
mode, the command serializes and prints these raw strings without using the existing
sanitize_inline terminal-safety filter (which is applied only in the table output path). The
repo’s review guide explicitly treats manifests/package metadata as attacker-controlled, making
terminal/log visual-spoofing a plausible exploit path.

pnpm/crates/cli/src/cli_args/licenses.rs[215-218]
pnpm/crates/package-manifest/src/lib.rs[935-957]
pnpm/crates/cli/src/cli_args/licenses.rs[256-267]
pnpm/crates/cli/src/cli_args/licenses.rs[286-303]
pnpm/crates/cli/src/cli_args/sanitize.rs[7-34]
REVIEW_GUIDE.md[30-46]

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

### Issue description
`pnpm licenses list --json` prints store-derived, attacker-controlled strings (license group keys and `LicenseInfo.license`) without applying the terminal-safety hardening used elsewhere in this command. With this PR, legacy `licenses` values are now accepted, so malicious Unicode formatting (e.g. bidi overrides) in legacy `licenses[].type/name` can be emitted into JSON output and visually spoof what a human sees in terminals/CI logs.

### Issue Context
- Table output sanitizes the license string via `sanitize_inline`, but JSON output directly uses `serde_json::to_string_pretty`.
- The new `extract_license` falls back to the legacy `licenses` field, expanding the set of manifests that can influence the emitted license value.

### Fix Focus Areas
- pnpm/crates/cli/src/cli_args/licenses.rs[215-218]
- pnpm/crates/cli/src/cli_args/licenses.rs[256-267]

### Suggested change
Switch JSON serialization to a serializer configuration that **escapes non-ASCII** (or at minimum escapes Unicode formatting characters) so the JSON value remains identical when parsed, but the raw terminal output can’t visually spoof content.

One concrete approach:
- Replace `serde_json::to_string_pretty(&json_output)` with a `serde_json::Serializer` configured with `escape_non_ascii(true)` and a `PrettyFormatter`, serialize into a buffer, then print the UTF-8 string.

This preserves machine-readable JSON semantics while neutralizing terminal spoofing by formatting/bidi characters.

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


Grey Divider

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.

@github-actions

Copy link
Copy Markdown
Contributor

Micro-Benchmark Results

Linux

group                                            main                                   pr
-----                                            ----                                   --
lockfile/parse_pnpm_lock                         1.00     11.2±0.34ms    33.3 MB/sec    1.02     11.5±0.57ms    32.6 MB/sec
packument/parse                                  1.03     40.0±0.89µs  1659.7 MB/sec    1.00     38.8±0.64µs  1708.9 MB/sec
tarball/download_dependency                      1.00      2.3±0.11ms  1852.2 KB/sec    1.00      2.3±0.09ms  1855.6 KB/sec
tarball_batch/cold_store_many_medium_tarballs    1.00    185.6±6.82ms 86.2 KElem/sec    1.02    188.6±4.07ms 84.8 KElem/sec

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.64%. Comparing base (81411d3) to head (750037c).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #13446   +/-   ##
=======================================
  Coverage   87.64%   87.64%           
=======================================
  Files         545      545           
  Lines       93978    94011   +33     
=======================================
+ Hits        82367    82399   +32     
- Misses      11611    11612    +1     

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

@zkochan
zkochan merged commit c59e2a4 into main Jul 27, 2026
33 checks passed
@zkochan
zkochan deleted the fix-13438-2 branch July 27, 2026 21:26
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