Skip to content

Test fs-packlist against npm-packlist on a generated corpus, and route every file selector through one API #223

Closed
pnpm/pnpm
#17415

Description

@zkochan

Found by a defect-hotspot pass over the 90 days to 2026-10-26.

Property

For the same package directory, every pnpm path that selects a package's files returns the file and link set npm-packlist returns. Those paths are pack/publish, git and directory deps, patch-commit, deploy and the injected-copy writers.

Fixes in the loop

Almost every file-selection fix came from a user who compared the output with npm or pnpm 11.

Design flaw

  • A hand port with a late oracle. pnpm/crates/fs-packlist ports ignore-walk, minimatch and npm-packlist by hand, while v11 wraps npm-packlist. The parity test arrived with fix(fs-packlist): unify package selection rules pnpm#17135, after about ten fixes. Its limits:
    • it uses one fixed file tree with few nested ignore files;
    • it has no swap or AppleDouble files, no deep trees and no case variation;
    • its oracle is the v11 wrapper, not npm pack.
  • Several deciders of the file and link set.
    • v12 has its own symlink rules in each of: packlist_with_sources, the git-fetcher re-export (used by the directory fetcher and patching/src/commit.rs), walk_all_files under deployAllFiles, the injected-deps-syncer dir_patcher, and the deps-restorer importer's SymlinkTargets.
    • v11 has the same spread across its packlist subclass, directory-fetcher, indexed-pkg-importer, cafs and DirPatcher.
  • Known divergences live in code comments, not in a list the tests can check. Examples are the named-file depth rule from fix(fs-packlist): honor nested ignore files when files is set pnpm#16920 and exact-case entry points from fix(fs-packlist): re-include the directories main, browser, and bin point into pnpm#16918.

Proposed change (medium, mostly test-side)

  • Generate the corpus. Use a grammar over paths (depth, dotfiles, case, swap and AppleDouble names, symlinks), ignore files at random depths, and files/main/browser/bin values from a glob grammar. Run each fixture through both packlists, and through npm pack --dry-run --json in a nightly job.
  • Keep the deliberate divergences as a named allowlist.
  • Route every consumer through one API that returns the files plus the admitted links. Importers and syncers then apply only the placement policy.

Tests that would have caught the loop

Fixes the change would have made unnecessary

The generated differential would have caught every v12-versus-npm divergence fixed in pnpm/pnpm#16761, pnpm/pnpm#16892, pnpm/pnpm#16920, pnpm/pnpm#16918, pnpm/pnpm#16971 and pnpm/pnpm#17146. Escape-path symlink fuzzing would have caught pnpm/pnpm#16619.


Written by an agent (Claude Code, claude-opus-5-5).

Activity

  1. self-assigned this
    on Oct 26, 2026
  2. zkochan commented on Oct 27, 2026

    @zkochan
    MemberAuthor

    Opened pnpm/pnpm#17415 to implement this task:

    1. Unified file selector & internal symlink placement API:
      • Added SelectedPackageFiles, select_package_files, select_dir_package_files, and packlist_dir in pnpm-fs-packlist returning the selected files plus admitted internal symlinks (AdmittedSymlink).
      • Extracted pnpm_fs::internal_symlink (SymlinkTargets, SymlinkTargetKind, AdmittedSymlink, SymlinkPlacementContext, SymlinkPlacement, admit_internal_symlink, resolve_symlink_placement, recreate_internal_symlink, selected_paths_and_ancestors, relative_link_target, symlink_file_or_copy) and routed pnpm-fs-packlist, pnpm-pack, pnpm-git-fetcher, pnpm-directory-fetcher, pnpm-patching (patch-commit), pnpm-deps-restorer (import_indexed_dir / deploy), and pnpm-injected-deps-syncer (syncInjectedDepsAfterScripts, DirPatcher, publish_edits) through it.
    2. Generated corpus & oracles:
      • Added DELIBERATE_DIVERGENCES with dedicated witness tests (deliberate_divergences_have_witnesses).
      • Added generated_trees_match_npm_packlist (proptest with shrinking over path depth, dotfiles, case, swap/AppleDouble names, symlinks, nested .npmignore/.gitignore, and files/main/browser/bin glob grammars) checking pnpm-fs-packlist against both npm-packlist and @pnpm/fs.packlist.
      • Added pack_matches_npm_pack_dry_run comparing pnpm-fs-packlist against npm pack --dry-run --json (including a corpus of real npm tarballs) and wired it into the nightly cargo-equivalence.yml workflow.
      • Added every_file_selector_agrees_with_pack in pnpm-cli, running the same fixture through pack, GitFetcher, DirectoryFetcher, patch-commit, deploy, and the injected-dependency sync paths (import_indexed_dir, syncInjectedDepsAfterScripts, DirPatcher, and publish_edits).
    3. Bugs caught and fixed:
      • generated_trees_match_npm_packlist caught and shrunk a bug in @pnpm/fs.packlist (pnpm11/fs/packlist/src/index.ts) where an unnormalized manifest with a string bin field ("bin": "lib/index.js") was left as a string instead of converted to an object, causing npm-packlist (for (const key in bin)) to iterate over character indices (0..n).
      • every_file_selector_agrees_with_pack caught a bug in pnpm-deps-restorer (import_indexed_dir) where importing an internal symlink to an unselected file as a regular file (SymlinkPlacement::ImportFile) under PackageImportMethod::Auto / Hardlink passed the symlink path to fs::hard_link, creating a hardlink to the symlink inode (a broken symlink in node_modules) instead of hardlinking the canonical target file.

    Generated by Antigravity (Claude Opus 4.6)

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions