Skip to content

Fix vendored runs that restore files and say nothing to do (#2471) - #2473

Open
Mikola Lysenko (mikolalysenko) wants to merge 3 commits into
mainfrom
agent/fix-vendored-repair-commit-step
Open

Mikola Lysenko (mikolalysenko) wants to merge 3 commits into
mainfrom
agent/fix-vendored-repair-commit-step

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

LLM Description written by Claude Code:claude-fable-5-2

Fixes #2471

Summary

A project whose gems were vendored by 5.1.0 needs one more commit after
the upgrade: the next vendor / scan --mode vendored run, or repair,
writes .gitignore and .gitattributes into each
.socket/vendor/gem/<uuid>/, and in a fresh clone it downloads a copy
again to restore files git left out. Neither command said so. vendor
ended on "already vendored; nothing to do." and repair on "Repair
complete.", with untracked files in git status and no commit step, so
the commit that makes a clone pass vendor --check was a step to guess.

Now the run that restores files names them and the commit:

$ socket-patch vendor          # uuid dir without its .gitignore / .gitattributes
Note: restored .socket/vendor/gem/<uuid>/.gitignore and .socket/vendor/gem/<uuid>/.gitattributes (one or both were missing or changed): they keep the project's ignore rules and filters off the vendored copy of diff-lcs@1.5.1. Commit them with the rest of .socket/vendor/
1 package is already vendored; restored its files under .socket/vendor/.
Next steps:
  1. Commit .socket/vendor/: the files this run restored there are not in the repository yet.

$ socket-patch vendor          # a file of the copy is missing, as in a clone
Redownloaded pkg:gem/diff-lcs@1.5.1 (.socket/vendor/gem/<uuid>/diff-lcs-1.5.1)
1 package is already vendored; restored its files under .socket/vendor/.
Next steps:
  1. Commit .socket/vendor/: ...

$ socket-patch repair
Note: restored .socket/vendor/gem/<uuid>/.gitignore and ...
...
Repair complete.
Next steps:
  1. Commit .socket/vendor/: ...

A run that restores nothing prints what it printed before, and a dry run
writes nothing and names no commit. No file that was written before is
written differently: only the output changes.

Root cause

Two writes under .socket/vendor/ happen behind a package the run
reports as already_vendored, and neither reached the human output:

  • the gem backend's in-sync path puts back the uuid dir's git metadata
    and dropped the "I wrote it" result;
  • the vendor pre-pass redownloads a copy whose inventory no longer
    matches and recorded only a JSON rebuilt event.

The summary line and "Next steps:" are built from applied / skipped
counts alone, so both runs read as no-ops. repair rewrote the same
metadata with no event at all, and printed no commit step after a
redownload either.

The change

  • core (vendor/gem.rs, vendor/mod.rs): the gem in-sync path
    returns a vendor_git_metadata_written advisory when it wrote either
    file, for a gem's own tree and for platform gems.
  • vendor / scan --mode vendored (commands/vendor.rs): the
    advisory prints as a Note:; the pre-pass redownload prints the
    Redownloaded <purl> (<path>) line repair prints; the tally counts
    the packages whose files were restored, the summary says so in place
    of "nothing to do" (or as a clause of its own on a mixed run), and a
    run that vendored nothing new but restored files ends with a one-step
    "Next steps:" naming the commit. A run that vendored something already
    names .socket/vendor/ in its commit step.
  • repair (commands/repair.rs, vendored_backend/repair.rs):
    records the same advisory when it rewrites the metadata of a healthy
    gem or npm-family artifact (after git is known to commit it), and ends
    with the same commit step after that or after a redownload. Other
    rebuilt events (a stray file swept from a JVM tree, a Bun workspace
    copy) do not trigger it.
  • docs: CLI_CONTRACT.md (the new code, the redownload paragraph)
    and docs/ecosystems.md ("Ruby gems: vendored gems and .gitignore").

The npm, PyPI and gem wrappers pass output through and need no change.

Evidence

Test Covers
e2e_vendor_gem_build::gem_vendor_and_repair_name_the_files_they_restore_and_the_commit (real Bundler, real git) #2471 end to end: vendor and repair, metadata-only and redownload, --json, the in-sync and dry runs that must stay quiet, and a clone of the named commit passing vendor --check. Fails on main at the first vendor re-run ("the vendor re-run names …/.gitignore"); passes here.
vendor::gem unit tests (the_uuid_dir_metadata_is_put_back_by_a_rerun_and_by_restore, a_shipped_gitignore_an_earlier_release_kept_is_reported_once, a_lost_platform_tree_is_rebuilt_by_a_rerun_and_by_restore) the advisory from the in-sync path, own tree and platform gems; none on the next run. Their old expectation was "no warning", which is the bug.
commands::vendor::ui_format_tests (vendor_summary_names_restored_files_instead_of_nothing_to_do, tally_counts_each_package_with_restored_files_once, git_metadata_written_prints_as_a_note) summary wording in each shape, one count per package
commands::repair::tests::restored_vendor_files_reads_rebuilds_and_written_metadata which events trigger repair's commit step

Commands run locally (Ruby 3.3.6, Bundler 4.0.18):

  • cargo test -p socket-patch-cli --test e2e_vendor_gem_build -- --include-ignored: 24 passed.
  • cargo test -p socket-patch-core: all targets pass (9,010 lib tests).
  • cargo test -p socket-patch-cli --lib and the vendor*, in_process_vendor*, scan*, repair, in_process_gem_multi_platform, in_process_remove_repair_lifecycle and in_process_rollback_vendored targets: pass, except two repair tests (repair_cleanup_failure_is_reported_in_json_and_silent_modes, repair_exits_zero_and_stays_quiet_when_lock_file_unremovable) that make a directory read-only and cannot fail a write in a sandbox that runs as root. CI runs them unprivileged.
  • cargo clippy --locked --workspace --all-features -- -D warnings (the CI form): clean. With --all-targets, this toolchain reports lints in test code across the workspace; none is on a line this PR adds.
  • rustfmt on the touched files.

Review

/code-review high ran on the diff. Fixed from it: two stale core test
expectations, the repair commit step firing on rebuilt events that
restore nothing, the summary attaching restored files to the "already
vendored" clause when the package had then failed, the advisory being
recorded before the git-commit check in repair, and a detail that
claimed both files were written when one was.

Not fixed here, on purpose: the same silent metadata restore exists on
the in-sync vendor paths of the npm family and PyPI. Those have had
their metadata for many releases, so no upgrade path hits them now; the
advisory code and the CLI handling are generic, so each is a small
follow-up at its backend.

https://claude.ai/code/session_011f9aeQh6AJCpEkXY9AdWf5


Generated by Claude Code

A vendored run that restores files under .socket/vendor/ reports
nothing to do and names no commit step. Refs #2471.

Assisted-by: Claude Code:claude-fable-5-2
A gem that 5.1.0 vendored has no .gitignore or .gitattributes in its
uuid dir. The next vendor run or repair writes them, and a clone that
lost an ignored file gets the copy downloaded again. Both leave files
to commit, and the run must name them and the commit step instead of
ending on "nothing to do".

The new capstone fails on main at the first vendor re-run. The diff-lcs
project setup moves into a helper the existing clone test shares.

Refs #2471.

Assisted-by: Claude Code:claude-fable-5-2
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011f9aeQh6AJCpEkXY9AdWf5
A vendored run over a gem that is already wired can still write under
.socket/vendor/: the in-sync path puts back the uuid dir's .gitignore
and .gitattributes, and the pre-pass downloads a copy again when files
of it are missing. Neither reached the human output. The package was
counted as already vendored, the run ended on "nothing to do" and
printed no commit step, so the fix for a clone that fails
`vendor --check` was never committed. `repair` wrote the same files
without naming them or the commit.

The gem in-sync path now returns a vendor_git_metadata_written
advisory when it wrote either file, and repair records the same one
for gem and npm-family entries. The vendor summary counts packages
whose files were restored and says so in place of "nothing to do",
the redownload prints the line repair prints, and both commands end
with a next step that names the commit of .socket/vendor/.

Fixes #2471.

Assisted-by: Claude Code:claude-fable-5-2
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011f9aeQh6AJCpEkXY9AdWf5
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review December 3, 2026 06:27
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

bugbot run


Generated by Claude Code

@cursor

cursor Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
CLI output, advisories, and user-facing docs only; no change to vendoring logic beyond recording when metadata is written and when to prompt for commit.

Overview
Fixes #2471: wet vendor and repair runs that only restore work under .socket/vendor/ (uuid-dir .gitignore / .gitattributes, or a redownloaded copy) no longer read as no-ops.

Behavior: Introduces vendor_git_metadata_written (Note-tier) when git metadata is rewritten on an already-vendored artifact; gem in-sync and vendored repair paths emit it after the commitability check. The vendor tally tracks packages with Rebuilt or that advisory; human summaries say restored files under .socket/vendor/ instead of "nothing to do", print Redownloaded <purl> (<path>) on vendor pre-pass redownloads, and append a Next steps block to commit .socket/vendor/ when anything was restored. repair uses the same commit hint when vendored events include a redownload with details.redownloaded or metadata written (excluding unrelated rebuilt events).

Docs/tests: CLI_CONTRACT.md and docs/ecosystems.md document the code and messaging; unit and e2e gem tests cover summaries, advisories, and clone/vendor --check after commit.

Reviewed by Cursor Bugbot for commit 7d574a1. Configure here.

@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: review brief for 7d574a173

What it does
After the 5.1 → 5.2 upgrade, a vendor / scan --mode vendored or repair run can write .gitignore / .gitattributes into a gem's uuid dir, or download a copy again in a fresh clone, and then print "nothing to do" / "Repair complete." with untracked files left behind (#2471). Now those runs print a Note: naming the files, say "restored … files under .socket/vendor/" instead of "nothing to do", and end with a one-step "Next steps: Commit .socket/vendor/". Only the output changes. No file is written differently.

Risk: low. Output and one new advisory code (vendor_git_metadata_written, a skipped/note event in --json). The JSON consumers see one extra advisory on the run that writes the pair. Lockfile, ledger and the bytes written are unchanged. Dry runs stay silent.

Look here

  • vendor/gem.rs:1330: the in-sync path now reports Ok(true) for platform gems too, not only a gem's own tree.
  • commands/vendor.rs:938 and :1023: the restored-package tally (each purl counted once) and the summary wording.
  • commands/vendor.rs:5469: the commit step, only when nothing was applied and it isn't a dry run.
  • [vendored_backend/repair.rs:527](https://github.com/SocketDev/socket-patch/blob/7d574a173f85c3b2f108ed9e8f1b1e549b33f6ef/crates/socket-patch-cli/src/commands/vendored_backend/repair.rs#L527): repair records the advisory only after git is known to commit the dir.
  • commands/repair.rs:529: only a rebuilt event with redownloaded: true or the advisory triggers the commit step. JVM sweeps and Bun workspace copies don't.

Verified

  • Read the whole diff. The uuid dir is derived from copy_rel, which is always <uuid_dir>/<leaf> (gem.rs:571), so the path in the Note is right for platform gems too. In vendor, the only Rebuilt event is the redownload; a dry run records Verified/wouldRedownload, so dry runs never count as restored.
  • Ran cargo test -p socket-patch-cli --lib locally for the new summary, tally, note and repair tests: 8 passed.
  • CI on 7d574a173: ci-ok and clippy green, including the e2e_vendor_gem_build leg that holds the new end-to-end test. No review threads. Bugbot neutral with no findings. CHANGELOG.md untouched. main is green.

Changes I made: none.

Open questions

  • None blocking. As the description says, the npm family and PyPI vendor in-sync paths still restore their metadata silently. That's a follow-up, and no current upgrade path hits it.

Generated by Claude Code

@mikolalysenko Mikola Lysenko (mikolalysenko) added the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review

Projects

None yet

2 participants