Skip to content

fix: pnpm publish --otp and pnpm publish --batch --otp to send the configured OTP to the registry - #12957

Merged
zkochan merged 3 commits into
pnpm:mainfrom
Andarist:fix/otp-arg
Jul 13, 2026
Merged

zkochan merged 3 commits into
pnpm:mainfrom
Andarist:fix/otp-arg

Conversation

@Andarist

@Andarist Andarist commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

I found this when testing if Changesets correctly handle pnpm 11.

Squash Commit Body

Fixed `pnpm publish --otp` and `pnpm publish --batch --otp` to send the configured OTP to the registry. It was accidentally overridden by the `undefined` coming from the first `operation` call in `withOtpHandling`

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.
  • Updated the documentation if needed.

View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed pnpm publish --otp and pnpm publish --batch --otp to send the configured OTP on the first registry request.
    • Ensured OTP handling no longer passes otp: undefined during initial attempts when an OTP is already available.
  • Tests
    • Added coverage to verify the npm-otp header is correctly included for batch publishing and that OTP is forwarded unchanged for OTP handling.
  • Release
    • Included patch releases for the publishing commands and pnpm.

@welcome

welcome Bot commented Jul 12, 2026

Copy link
Copy Markdown

💖 Thanks for opening this pull request! 💖
Please be patient and we will get back to you as soon as we can.

@coderabbitai

coderabbitai Bot commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@zkochan, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 22 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: fa3eeddb-f5ec-40e6-b4c1-28a9a0757e34

📥 Commits

Reviewing files that changed from the base of the PR and between 832513a and 12acbb8.

📒 Files selected for processing (2)
  • pnpm/crates/publish/src/publish_packed_pkg/tests.rs
  • pnpm11/releasing/commands/src/publish/otp.ts
📝 Walkthrough

Walkthrough

This change preserves configured OTP values in regular and batch publish flows, verifies registry header propagation and first-attempt handling, and adds patch-release metadata.

Changes

Publish OTP propagation

Layer / File(s) Summary
OTP fallback propagation
pnpm11/releasing/commands/src/publish/otp.ts, pnpm11/releasing/commands/src/publish/batchPublish.ts
Publish operations fall back to publishOptions.otp when the OTP callback does not provide a value.
OTP propagation validation and release metadata
pnpm11/releasing/commands/test/publish/batchPublish.test.ts, pnpm11/releasing/commands/test/publish/otp.test.ts, .changeset/preserve-publish-otp.md
Tests verify first-attempt OTP handling and the npm-otp request header; the changeset records patch releases and the publish OTP fix.

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

Possibly related PRs

  • pnpm/pnpm#12299: Adds the batch-publish codepath that these OTP propagation fixes update.

Suggested labels: product: pnpm@11

Suggested reviewers: zkochan, ranm8

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@Andarist
Andarist marked this pull request as ready for review July 13, 2026 09:14
@Andarist
Andarist requested a review from zkochan as a code owner July 13, 2026 09:14
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@greptile-apps

greptile-apps Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

Safe to merge — the change is a targeted one-line fix in two files, backed by new test coverage in both TypeScript and Rust.

The fix correctly uses ?? so the user-supplied OTP is forwarded on the first attempt while a challenge-obtained OTP still takes precedence on retry. The ?? operator (not ||) means even an empty-string OTP from the challenge round-trip is correctly preserved. New tests in both the TS and Rust layers confirm the first-request OTP header is present, and the existing OTP-challenge flow tests still pass unchanged.

No files require special attention.

Reviews (4): Last reviewed commit: "test(publish): cover configured OTP on t..." | Re-trigger Greptile

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Jul 13, 2026
@zkochan zkochan changed the title Fixed pnpm publish --otp and pnpm publish --batch --otp to send the configured OTP to the registry fix: pnpm publish --otp and pnpm publish --batch --otp to send the configured OTP to the registry Jul 13, 2026
@qodo-code-review

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

Copy link
Copy Markdown

Code Review by Qodo

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

Context used
✅ Compliance rules (platform): 18 rules

Grey Divider


Remediation recommended

1. Redundant test doc comment 📘 Rule violation ⚙ Maintainability ⭐ New
Description
The new doc comment narrates the test’s internal mechanics (mock matching, request counts) rather
than only capturing intent/contract, which adds maintenance burden when the test is refactored.
Prefer keeping only the behavioral requirement (configured OTP must be sent on first request) and
letting the assertions express the rest.
Code

pnpm/crates/publish/src/publish_packed_pkg/tests.rs[R336-342]

+/// A statically configured OTP (`pnpm publish --otp`) must ride the first PUT,
+/// not just a post-challenge retry. `publish_with_otp_handling` invokes its
+/// operation with no challenge OTP first, so the configured one has to fall
+/// through; regressing that would make `--otp` a no-op until the registry
+/// challenges. The single `expect(1)` mock matches `npm-otp` on the first
+/// request and returns 200, so a dropped OTP or an extra challenge round-trip
+/// fails the assertion.
Evidence
Compliance rule 713467 requires avoiding redundant comments that restate the code. The added doc
comment explicitly describes how the mock is configured and how the assertion fails, which is
already evident from the test body immediately below.

Rule 713467: Avoid redundant comments that restate the code
pnpm/crates/publish/src/publish_packed_pkg/tests.rs[336-342]

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

## Issue description
A newly added Rust test doc comment is overly detailed and restates implementation mechanics (e.g., mock expectation details) instead of focusing on the behavioral requirement the test enforces.

## Issue Context
Per the repo guidance, comments should add intent/rationale and avoid repeating what the code already makes clear.

## Fix Focus Areas
- pnpm/crates/publish/src/publish_packed_pkg/tests.rs[336-342]

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


2. Comment repeats withOtpHandling JSDoc 📘 Rule violation ⚙ Maintainability
Description
The new inline comment above operation largely restates withOtpHandling’s documented behavior
(first attempt without OTP, then retry with OTP), duplicating existing documentation. This adds
maintenance burden and risks the call-site comment diverging from the canonical behavior
description.
Code

pnpm11/releasing/commands/src/publish/otp.ts[R76-82]

+    // withOtpHandling first calls this with no otp, then retries with the otp
+    // it obtained from an OTP challenge. On the first attempt we fall back to
+    // the configured --otp (publishOptions.otp) so it is actually sent; a retry
+    // otp takes precedence over it. When both are undefined, passing
+    // otp: undefined is safe because libnpmpublish treats undefined the same as
+    // absent (unlike HTTP headers, where undefined gets coerced to the string
+    // "undefined").
Evidence
The added call-site comment restates that withOtpHandling first calls operation without an OTP
and then retries with the OTP from a challenge. That behavior is already explicitly documented in
withOtpHandling’s JSDoc, so the call-site comment duplicates existing documentation.

Rule 713431: Avoid duplicating JSDoc content in call-site comments
pnpm11/releasing/commands/src/publish/otp.ts[76-82]
pnpm11/network/web-auth/src/withOtpHandling.ts[56-64]

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

## Issue description
A call-site comment above `withOtpHandling({ operation: ... })` repeats behavior already documented in `withOtpHandling`’s JSDoc (first call without OTP, retry with OTP). This violates the rule to avoid duplicating JSDoc at call sites.

## Issue Context
Keep the comment focused on what is specific to this call (the `otp: otp ?? publishOptions.otp` fallback and why passing `undefined` is safe), and avoid restating `withOtpHandling`'s general retry flow.

## Fix Focus Areas
- pnpm11/releasing/commands/src/publish/otp.ts[76-82]
- pnpm11/network/web-auth/src/withOtpHandling.ts[56-64]

ⓘ 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 12acbb8

Results up to commit 9418f88


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


Remediation recommended
1. Comment repeats withOtpHandling JSDoc 📘 Rule violation ⚙ Maintainability
Description
The new inline comment above operation largely restates withOtpHandling’s documented behavior
(first attempt without OTP, then retry with OTP), duplicating existing documentation. This adds
maintenance burden and risks the call-site comment diverging from the canonical behavior
description.
Code

pnpm11/releasing/commands/src/publish/otp.ts[R76-82]

+    // withOtpHandling first calls this with no otp, then retries with the otp
+    // it obtained from an OTP challenge. On the first attempt we fall back to
+    // the configured --otp (publishOptions.otp) so it is actually sent; a retry
+    // otp takes precedence over it. When both are undefined, passing
+    // otp: undefined is safe because libnpmpublish treats undefined the same as
+    // absent (unlike HTTP headers, where undefined gets coerced to the string
+    // "undefined").
Evidence
The added call-site comment restates that withOtpHandling first calls operation without an OTP
and then retries with the OTP from a challenge. That behavior is already explicitly documented in
withOtpHandling’s JSDoc, so the call-site comment duplicates existing documentation.

Rule 713431: Avoid duplicating JSDoc content in call-site comments
pnpm11/releasing/commands/src/publish/otp.ts[76-82]
pnpm11/network/web-auth/src/withOtpHandling.ts[56-64]

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

## Issue description
A call-site comment above `withOtpHandling({ operation: ... })` repeats behavior already documented in `withOtpHandling`’s JSDoc (first call without OTP, retry with OTP). This violates the rule to avoid duplicating JSDoc at call sites.

## Issue Context
Keep the comment focused on what is specific to this call (the `otp: otp ?? publishOptions.otp` fallback and why passing `undefined` is safe), and avoid restating `withOtpHandling`'s general retry flow.

## Fix Focus Areas
- pnpm11/releasing/commands/src/publish/otp.ts[76-82]
- pnpm11/network/web-auth/src/withOtpHandling.ts[56-64]

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

Auto-approved notes - no code suggestions found
- 'approve_pr_on_self_review' flag enabled

…ndling

The comment still described the pre-fix `{ ...publishOptions, otp }` behavior
and claimed the spread adds `otp: undefined`. Describe the current contract:
the first call falls back to the configured `--otp`, a retry OTP takes
precedence, and the undefined-is-absent note applies only when both are unset.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 9418f88

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

Auto-approved notes - no code suggestions found
- 'approve_pr_on_self_review' flag enabled

pacquet's `publish_with_otp_handling` already forwards a statically
configured `--otp` on the first PUT (the operation closure falls back to it
when no challenge OTP is present), but no test guarded that: every existing
case passed `otp = None`. Add a regression test that mocks a single PUT
matching `npm-otp` with no challenge, mirroring the TypeScript CLI's
"preserves OTP from publish options on the first publish attempt" test so the
two stacks keep matching coverage.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 12acbb8

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

Auto-approved notes - no code suggestions found
- 'approve_pr_on_self_review' flag enabled

@zkochan
zkochan merged commit 96cf320 into pnpm:main Jul 13, 2026
30 of 32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product: pnpm@11 reviewed: coderabbit CodeRabbit submitted an approving review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants