Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

remove --preserve-state on a manifest-less hosted npm project silently restores the pin without the documented hosted_state_not_preservable note

未關閉 適合新手
#433 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
82/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
rust
領域
cli

研究方向

從 crates/socket-patch-cli/src/commands/remove.rs 中的 remove_hosted_only(約第 1337 行)開始,然後將其與約第 770 行的基於 manifest 的 hosted 路徑進行比較。在僅 hosted 模式下分別使用和不使用 --json 重現 remove --preserve-state,並將輸出與 CLI_CONTRACT.md 和 rollback --preserve-state 進行比較。當 hosted_state_not_preservable 註記在兩種受支援的輸出模式中都顯示時,即表示完成。

由索引模型根據 Issue 內容生成。

描述

agent:triaged bug bughunt pm:npm priority:p1

[agent] Found by the scheduled npm bug-hunt routine (ledger #302).

Summary

In v5, a project patched by a bare scan (hosted mode) has no .socket/manifest.json. On such a project, socket-patch remove <purl> --preserve-state restores the hosted pin to the upstream registry and deletes the .npmrc. So the patch is gone, even though the user asked to preserve state.

The command never tells the user this. There's no "hosted wiring has no preservable local state" note on stderr, and no warnings[] in --json (the envelope has no warnings key at all). rollback --preserve-state on the same project correctly emits hosted_state_not_preservable.

Severity is low. The behaviour (restoring anyway) is what's documented; only the advisory is missing. But --preserve-state exists so the user can expect to re-apply later, and here it silently doesn't preserve.

Repro (Linux, npm 12.1.0, main 2463257)

A local mock of the patch API serves pkg:npm/[email protected]. SPA="--api-url … --org o --api-token fake --patch-server-url …".

echo '{"name":"t","version":"1.0.0","private":true,"dependencies":{"left-pad":"1.3.0"}}' > package.json
npm install
socket-patch scan $SPA                                    # hosted: package-lock.json + .npmrc rewritten, no .socket/
socket-patch remove pkg:npm/[email protected] --preserve-state $SPA
#   The following hosted patch will be unwound and removed:
#     - pkg:npm/[email protected]
#   Restored pkg:npm/[email protected] to its upstream registry entry
#   (no "no preservable local state" note)
socket-patch scan $SPA
socket-patch remove pkg:npm/[email protected] --preserve-state $SPA --json   # status success, events[hosted_reverted], no warnings key
socket-patch scan $SPA
socket-patch rollback --preserve-state $SPA --json        # warnings: [reinstall_required, hosted_state_not_preservable]  <- correct

It reproduces on 2 of 2 runs.

Expected vs actual

  • Expected: CLI_CONTRACT.md's warning table, row hosted_state_not_preservable, says: "rollback --preserve-state (v5.0): hosted pins were restored to upstream anyway … (remove --preserve-state prints the same note on stderr.)". The --preserve-state (opt-out, both rollback and remove) section says the same: "a preserve run still restores them to upstream — surfaced as the hosted_state_not_preservable warning".
  • Actual: the note is printed only on the manifest-backed remove path. The hosted-only path, which is the default v5 shape, prints nothing.
Project shape remove --preserve-state note
Hosted-only (no manifest), Linux npm 12.1.0 missing (stderr and JSON)
rollback --preserve-state, same project present

Suspect code

crates/socket-patch-cli/src/commands/remove.rs:1337 (remove_hosted_only). Its doc comment says "--preserve-state still unwinds — hosted has no preservable local state". But the Note: hosted wiring has no preservable local state … eprintln only exists in the manifest-backed hosted leg (remove.rs:770).

主要語言
Rust
星號
8
分支
0
平均合併
15 小時 39 分鐘
30 天內合併 PR
104

環境準備

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

SocketDev/socket-patch 的其他 Issue

查看 SocketDev/socket-patch 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。