Repository navigation
feat: add calculateFingerprint pnpmfile hook - #13690
everett1992 wants to merge 2 commits into
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThe PR adds a ChangesPnpmfile fingerprint freshness
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant Pnpmfile
participant CookedHooks
participant InstallDeps
participant WorkspaceState
participant CheckDepsStatus
Pnpmfile->>CookedHooks: provide calculateFingerprint
CookedHooks-->>InstallDeps: return combined fingerprint
InstallDeps->>WorkspaceState: store fingerprint after installation
CheckDepsStatus->>CookedHooks: calculate current fingerprint
CheckDepsStatus->>WorkspaceState: compare with stored fingerprint
CheckDepsStatus-->>InstallDeps: report outdated when fingerprints differ
Possibly related PRs
Suggested labels: Suggested reviewers: ✨ Finishing Touches🧪 Generate unit tests (beta)
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
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. Comment |
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Reviews (3): Last reviewed commit: "fix: invalidate deterministically when t..." | Re-trigger Greptile |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
hooks/pnpmfile/src/requireHooks.ts (1)
223-223: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winRemove the redundant section label.
Line 223 repeats the following code. Remove this comment. The comment at Lines 230-231 already documents the required ordering invariant.
🤖 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 `@hooks/pnpmfile/src/requireHooks.ts` at line 223, Remove the redundant “calculateFingerprint” comment near the fingerprint logic, while preserving the implementation and the existing ordering-invariant documentation later in the section.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 @.changeset/fingerprint-hook.md:
- Around line 9-11: Update the calculateFingerprint release note in the
changeset to replace the historical rationale with a concise statement that this
hook is unavailable in pacquet, while preserving the description of its
TypeScript CLI behavior.
In `@hooks/pnpmfile/src/requireHooks.ts`:
- Around line 229-236: The combined fingerprint produced by
cookedHooks.calculateFingerprint must use an unambiguous structured encoding:
replace newline joining of checksums with JSON.stringify(checksums) in
hooks/pnpmfile/src/requireHooks.ts lines 229-236. Update the expected
fingerprint format in hooks/pnpmfile/test/index.ts lines 119-125 and add
coverage for distinct hook results containing newlines that would collide under
concatenation.
---
Nitpick comments:
In `@hooks/pnpmfile/src/requireHooks.ts`:
- Line 223: Remove the redundant “calculateFingerprint” comment near the
fingerprint logic, while preserving the implementation and the existing
ordering-invariant documentation later in the section.
🪄 Autofix
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: 5163189e-0d8a-4aa1-8ea2-4b07b5c96bef
⛔ Files ignored due to path filters (2)
hooks/pnpmfile/test/__fixtures__/fingerprintA.jsis excluded by!**/__fixtures__/**hooks/pnpmfile/test/__fixtures__/fingerprintB.jsis excluded by!**/__fixtures__/**
📒 Files selected for processing (10)
.changeset/fingerprint-hook.mddeps/status/src/checkDepsStatus.tsdeps/status/test/checkDepsStatus.test.tshooks/pnpmfile/src/Hooks.tshooks/pnpmfile/src/requireHooks.tshooks/pnpmfile/test/index.tsinstalling/commands/src/installDeps.tsworkspace/state/src/createWorkspaceState.tsworkspace/state/src/types.tsworkspace/state/src/updateWorkspaceState.ts
A pnpmfile can now export hooks.calculateFingerprint, returning a fingerprint of external state its behavior depends on (e.g. a custom package source used by a custom resolver). The value is recorded in the workspace state file after installs and compared by checkDepsStatus, so the verify-deps-before-run and optimistic-repeat-install fast paths invalidate when it changes and a full install (including shouldRefreshResolution hooks) runs. The fingerprint is deliberately never written to the lockfile, so it may be machine-specific. Multiple pnpmfiles combine as a JSON array sorted by file path, keeping component boundaries unambiguous. Pacquet is deliberately untouched. It does not run pnpmfiles, and its optimistic-repeat-install fast path is uniformly unaware of hook effects today; guarding only this field would be an inconsistent slice of that pre-existing gap. The schema change is tolerated as-is: serde ignores the unknown fingerprint field on read, and a pacquet rewrite of the state without it makes pnpm invalidate and re-record on its next run - fail-safe toward an extra install, never toward staleness. Closes the gap warned about in pnpm#10995.
5872eda to
1853160
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
pnpm11/hooks/pnpmfile/src/requireHooks.ts (1)
223-223: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueRemove the restating comment.
// calculateFingerprintrepeats the following condition. Remove it because it documents no contract or invariant.🤖 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 `@pnpm11/hooks/pnpmfile/src/requireHooks.ts` at line 223, Remove the redundant `// calculateFingerprint` comment immediately before the repeated condition, leaving the surrounding logic unchanged.Sources: Coding guidelines, 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.
Inline comments:
In `@pnpm11/deps/status/src/checkDepsStatus.ts`:
- Around line 257-267: The fingerprint hook call in
pnpm11/deps/status/src/checkDepsStatus.ts lines 257-267 must catch thrown or
rejected calculateFingerprint failures and return upToDate: false instead of
allowing the broad status-check catch to produce undefined; add a regression
test in pnpm11/deps/status/test/checkDepsStatus.test.ts lines 516-665 with a
rejected hook and assert upToDate is false.
---
Nitpick comments:
In `@pnpm11/hooks/pnpmfile/src/requireHooks.ts`:
- Line 223: Remove the redundant `// calculateFingerprint` comment immediately
before the repeated condition, leaving the surrounding logic unchanged.
🪄 Autofix
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: 85f06daf-e097-43af-b1da-1e6f814c9fd8
⛔ Files ignored due to path filters (2)
pnpm11/hooks/pnpmfile/test/__fixtures__/fingerprintA.jsis excluded by!**/__fixtures__/**pnpm11/hooks/pnpmfile/test/__fixtures__/fingerprintB.jsis excluded by!**/__fixtures__/**
📒 Files selected for processing (10)
.changeset/fingerprint-hook.mdpnpm11/deps/status/src/checkDepsStatus.tspnpm11/deps/status/test/checkDepsStatus.test.tspnpm11/hooks/pnpmfile/src/Hooks.tspnpm11/hooks/pnpmfile/src/requireHooks.tspnpm11/hooks/pnpmfile/test/index.tspnpm11/installing/commands/src/installDeps.tspnpm11/workspace/state/src/createWorkspaceState.tspnpm11/workspace/state/src/types.tspnpm11/workspace/state/src/updateWorkspaceState.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- .changeset/fingerprint-hook.md
…fails A throwing hook previously fell into checkDepsStatus's outer catch, yielding upToDate: undefined - which runDepsStatusCheck can treat as "unknown" and skip the install for. Catch at the call site and return upToDate: false so a broken hook always invalidates.
What
Adds a new pnpmfile hook,
calculateFingerprint, that returns a fingerprint of any external state the pnpmfile's behavior depends on — for example, the state of a custom package source used by a custom resolver. The value is recorded in the workspace state file after installs and compared bycheckDepsStatus, so theverify-deps-before-runandoptimistic-repeat-installfast paths invalidate when it changes and a full install (includingshouldRefreshResolutionhooks) runs.Why
Follow-up to #9516 / #10995. The custom resolver API's
shouldRefreshResolutionhook exists for package sources where content can change behind an unchanged name@version, but both fast paths usecheckDepsStatus, which only examines local files (manifests, lockfile, patches, pnpmfile mtimes). A pnpmfile whose hooks read external state can be logically changed while every local file is unchanged — so under the pnpm 11 defaults (optimisticRepeatInstall: true,verifyDepsBeforeRun: install), resolver-refresh users silently go stale, which #10995 could only warn about. RunningshouldRefreshResolutionper lockfile entry inside the fast path was rejected there as too expensive; this hook is the cheap alternative — one author-controlled value, one comparison.Design notes
verifyDepsBeforeRuniswarn/error/declinedprompt, or when two processes race. The recorded value advances only insideupdateWorkspaceStateafter a successful install, like every other staleness input. The cost is that hooks must be deterministic for unchanged state.pnpmfileChecksum(lockfile-recorded content hash) can't carry it._checkDepsStatus(after the settings/configDependencies checks, before any filesystem work) and only runs when a hook exists or a value was recorded, so projects without the hook pay nothing.Pacquet parity
Deliberately not ported. Pacquet does not run pnpmfiles, and its optimistic-repeat-install fast path is uniformly unaware of hook effects today (the
patchesOrHooksAreModifiedport does not exist yet); guarding only this field would be an inconsistent slice of that pre-existing gap. The schema change is tolerated as-is: serde ignores the unknownfingerprintfield on read, and if a pacquet install rewrites the state without it, pnpm sees the missing fingerprint on its next run, invalidates, and re-records — fail-safe in the extra-install direction, never toward staleness. Fast-path hook awareness for pacquet (this field plus pnpmfiles mtime checks) is proposed as follow-up.Testing
@pnpm/hooks.pnpmfile: hook cooking — absent, single, and multiple pnpmfiles (passed in reverse order to prove the deterministic sort).@pnpm/deps.status: all four comparison edge cases (changed, newly appeared, removed, unchanged-continues-past).pnpm runtriggers the verify-deps install;pnpm-lock.yamlstays untouched throughout.Docs PR: pnpm/pnpm.io#860.
Written by an agent (Kiro, claude-fable-5), directed and reviewed by @everett1992.
Summary by CodeRabbit
New Features
Bug Fixes
Documentation