Decide: what rollback owes a package when a file of its patch is missing on disk, the state apply --force leaves

未關閉
#2,277 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
5/5
預估耗時
一週以上
新手友好度
25/100
Issue 類型
功能
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
rust
領域
cli

研究方向

Read the --force handling in crates/socket-patch-core/src/patch/apply.rs at L1828-L1832, the rollback paths in crates/socket-patch-core/src/patch/rollback.rs at L200-L209 and L650-L658, and the rollback and --force rows in CLI_CONTRACT.md. Decide which rollback behavior the contract should promise for a missing patch file; define completion by updating the contract and implementing the chosen behavior, with tests covering the supplied fixture and forced apply followed by rollback.

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

描述

agent:needs-human agent:triaged arch-audit bug priority:p3

[agent] Filed by the architecture refactor routine, which found this while checking #1987. Everything below was run with the binary built from main at cfc870f.

What happens

apply --force skips a patch file that is missing on disk and patches the rest (apply.rs L1828-L1832). rollback has no matching rule: one absent file stops the whole package before anything is restored (rollback.rs L200-L209, L650-L658). So no command undoes a forced apply, and a record whose package lacks one of the patch's files can never be rolled back, whether the other files are patched or not.

The fixture is files only: node_modules/left-pad 1.3.0 holding index.js, and a manifest record whose patch lists package/index.js and package/lib/gone.js, with all four blobs in .socket/blobs.

$ socket-patch apply --offline
Error: Failed to patch pkg:npm/[email protected]: Cannot apply patch: package/lib/gone.js - File not found      (exit 1)

$ socket-patch apply --offline --force
Warning: pkg:npm/[email protected]: 1 patch file not found on disk and skipped (--force): package/lib/gone.js
Patched packages:
  pkg:npm/[email protected] (via blob)                                                                         (exit 0)

$ socket-patch rollback --offline --yes
Failed to roll back:
  pkg:npm/[email protected]: Cannot roll back: package/lib/gone.js - File not found
Error: Some patches could not be rolled back.                                    (exit 1; index.js is still patched)

$ socket-patch remove pkg:npm/[email protected] --yes --offline
Error: Failed to roll back pkg:npm/[email protected]: Cannot roll back: package/lib/gone.js - File not found
Error: Rollback failed during patch removal. Use --skip-rollback to remove from manifest without restoring files.
                                                                                                             (exit 1)

What is left to the user:

  • remove --skip-rollback drops the record and leaves index.js patched.
  • Reinstalling the package first does not help. With index.js back at its upstream bytes, so that every file that exists is original, rollback and remove print the same error and exit 1, with nothing left to restore.
  • apply --check on the forced state says Run socket-patch apply to regenerate them. That apply exits 1 with the "File not found" error above; only apply --force reports the package as already patched.
  • vex leaves the package out (file_not_found), which is the documented omission.
Why this is a decision

CLI_CONTRACT.md documents both halves. The --force row says "A file of the patch that is missing on disk is skipped instead of failing the package, and named in a patch_files_skipped warning". The rollback table says file_not_found is a failed event when "the copy's first blocking file … is missing". It does not say what rollback owes a package that apply --force patched in part, and any fix changes rollback's result for that row.

Options
  1. rollback restores every file that holds the patched bytes, treats an absent file as nothing to restore, and names it in a warning, as patch_files_skipped does on the way in. The run succeeds when every file that exists is original afterwards.
  2. rollback writes the before-blob to the absent path. That restores a file a user deleted after patching, and adds a file to an install that never had it.
  3. Keep the refusal and say the way out. The advice printed for a hash mismatch (reinstall, then roll back again) does not work here; the only exit that works today is a reinstall followed by remove --skip-rollback.

Which should it be? The routine opens a PR once this is answered.

Not checked
  • How often a real install lacks a file its patch lists. The fixture is hand-built. A plain apply fails on such an install, and --force is the documented way past it.
  • The pnpm and vlt store-copy fan-out: a store copy's forced skip is dropped on purpose (apply_force_skip_in_a_twin_keeps_an_already_patched_primary), and I did not run a rollback over one.

Generated by Claude Code

主要語言
Rust
星號
9
分支
2
平均合併
1 天 8 小時
30 天內合併 PR
313

環境準備

  • 沒有 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 摘要。