Skip to content

Fix vendored gem directories losing files git ignores (#2348) - #2451

Merged
Mikola Lysenko (mikolalysenko) merged 7 commits into
mainfrom
agent/fix-vendored-gem-tree-gitignored-files
Dec 2, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 7 commits into
mainfrom
agent/fix-vendored-gem-tree-gitignored-files

Conversation

@mikolalysenko

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

Copy link
Copy Markdown
Collaborator

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

Refs #2348

Summary

A gem vendored as its own directory (.socket/vendor/gem/<uuid>/<name>-<version>/) could lose files at commit. A project ignore rule (the .rspec line of GitHub's Rails.gitignore) or a .gitignore shipped inside the gem kept files of the copy out of git. The checkout that vendored the gem verified; every fresh clone failed vendor --check and vex with vendor_inventory_mismatch.

This PR gives the plain gem directory the handling that a gem vendored as platform gems already has:

  • The uuid directory gets a .gitignore (!*) and the shared .gitattributes, so project rules and filters do not apply below it.
  • A .gitignore the gem ships is emptied in the copy when its rules match a file of the copy (vendor_gem_gitignore_neutralized). One that hides nothing is kept byte for byte, because a gem can ship one as data (Jekyll's site template). One the patch rewrites is kept.
  • A rule that ignores the uuid directory itself refuses the gem with vendor_artifact_gitignored before any download, dry run included. After the copy is written, git is asked about every file, and the gem is refused and unwound if one would still be left out.
  • An in-sync re-run and repair write the pair when it is missing, which is how a copy vendored by an earlier release gets it.

Scope: plain gems only. The Cargo, Go and Composer directories of #2348 are not changed here, so this is Refs, not Fixes. The gem helpers take no gem-specific input and can be shared when those backends follow.

Root cause

vendor/gem.rs ran the three steps (uuid metadata, emptying shipped .gitignore files, the git check-ignore probe) only when the lock pins the gem as platform gems. redownload.rs restored the uuid metadata under the same condition. A gem's own tree was assumed to be source files that no rule matches.

Do-no-harm notes for the reviewer

  • Copies vendored by an earlier release keep verifying. repair restores each shipped .gitignore as the ledger inventory records it, so an old entry is restored with the gem's rules intact and still matches its inventory (restore_keeps_a_shipped_gitignore_an_earlier_release_recorded, which also passes on main).
  • Such a copy is not rewritten in place. The in-sync test looks only at patched files, so rewriting the copy and its inventory there could bless drift. Instead, the run that writes the missing pair asks git about the copy and warns vendor_gem_copy_gitignored (new code, documented) with the remedy git add -f <copy dir>.
  • Platform gem trees behave as before: every shipped .gitignore is still emptied there, because existing ledger inventories record them that way.
  • A gem committed as its archive for a Bazel hub is asked nothing new. The new directory-rule check runs after the hub branch.

Evidence

Run locally on this branch (Ruby 3.3.6, Bundler 4.0.18, git 2.43):

Command Result
cargo test -p socket-patch-core --lib vendor:: 3280 passed
cargo test -p socket-patch-cli --lib --test in_process_vendor --test e2e_vex_vendor --test vendor_revert_tamper_e2e all passed
cargo test -p socket-patch-cli --test e2e_vendor_gem_build --test e2e_redirect_gem_build --test e2e_gem_native_ext_build -- --ignored 15, 56 and 11 passed
cargo clippy --locked --workspace --all-features -- -D warnings (the CI command) clean

cargo clippy --all-targets reports errors in test code on main as well (none in the lines this PR adds); CI does not run it that way.

Red to green:

  • Core unit tests, module vendor::gem::tests::committable_gem_trees. Commit 2163464 adds five of them before the fix; four fail on main:
    • a_file_a_project_rule_ignores_reaches_a_fresh_clone: real git commit and git clone; the clone holds .rspec and the entry verifies there.
    • a_rule_that_ignores_the_vendored_dir_refuses_the_gem: refused dry and wet, nothing written, service not asked.
    • a_gitignore_the_gem_ships_is_emptied_in_the_copy: emptied at any depth, the template and the patched one kept, inventory healthy, re-run in sync, restore reproduces the tree.
    • the_uuid_dir_metadata_is_put_back_by_a_rerun_and_by_restore.
  • Added with the review fixes: a_shipped_gitignore_an_earlier_release_kept_is_reported_once and repair_writes_the_missing_metadata_of_a_healthy_copy.
  • Real Bundler, e2e_vendor_gem_build::gem_vendor_file_a_project_rule_ignores_reaches_a_git_clone: diff-lcs 1.5.1 (ships .rspec) in a project with Rails.gitignore lines; after git commit and git clone, vendor --check exits 0 in the clone and a frozen bundle install loads the patched gem. It fails with main's gem.rs and redownload.rs.

Review

/code-review high ran on the diff. Fixed: emptying a .gitignore the gem uses as data; no heads-up for an old copy whose shipped .gitignore still hides files; repair not writing the pair for a healthy copy although the docs said so; the directory-rule check firing for an archive-wired Bazel gem; contract rows; a misplaced doc comment; the test git helper reading the machine's git config.

Cursor Bugbot found one issue: a negation under an ignored directory was read as re-including the file. Fixed, with the unit test a_shipped_gitignore_is_read_as_git_reads_it.

Not fixed, with reasons:

Docs

CLI_CONTRACT.md: the gem row of the vendored table, vendor_artifact_gitignored, vendor_artifact_gitignore_unchecked, and a new row for vendor_gem_copy_gitignored. docs/ecosystems.md: new section "Ruby gems: vendored gems and .gitignore".

Follow-ups

https://claude.ai/code/session_011f9aeRRUb7jeJQjA9NUduE


Generated by Claude Code

Refs #2348.

Assisted-by: Claude Code:claude-fable-5-2
Four of the five cases fail on main: a file of a plain gem's vendored
directory that an ignore rule matches is left out of the commit, a
rule that ignores the vendored dir is not refused, a .gitignore the
gem ships keeps its rules, and the uuid dir gets no git metadata.
The fifth pins what repair does for a copy vendored before the fix.

Refs #2348.

Assisted-by: Claude Code:claude-fable-5-2
A gem vendored as its own directory got none of the ignore handling a
gem vendored as platform gems has, so a project rule (the .rspec of
GitHub's Rails.gitignore) or a .gitignore the gem ships left files of
the copy out of the commit. Every fresh clone then failed
vendor --check and vex with vendor_inventory_mismatch.

Every vendored gem now gets the uuid dir's .gitignore and
.gitattributes, has the .gitignore files it ships emptied in the
copy, and is refused (vendor_artifact_gitignored) when git would
still leave a file out. An in-sync re-run and repair put the pair
back. Repair keeps a shipped .gitignore that the ledger inventory of
an earlier release recorded, so such a copy still verifies.

Refs #2348.

Assisted-by: Claude Code:claude-fable-5-2
A real-Bundler case commits and clones a project whose .gitignore
has the .rspec rule of GitHub's Rails.gitignore, with a gem that
ships that file (diff-lcs 1.5.1). The clone holds the whole copy,
vendor --check passes there, and a frozen bundle install loads the
patched gem. It fails against main's backend.

The CLI contract and the ecosystem guide now describe the uuid dir's
git metadata and the emptied .gitignore for every vendored gem.

Refs #2348.

Assisted-by: Claude Code:claude-fable-5-2
Review findings on the vendored gem dir fix.

A gem can ship a .gitignore as data (a template it copies into new
projects). In a gem's own tree only a .gitignore whose rules match a
file of the copy is emptied now; the rest stay byte for byte. Repair
restores each one as the ledger inventory records it.

A copy that an earlier release vendored keeps the gem's .gitignore as
shipped. The in-sync run that writes the uuid dir's pair for it now
warns vendor_gem_copy_gitignored when git would still leave a file
out, and names git add -f. Repair writes the pair for a healthy copy
too, as the docs say.

The check for a rule that ignores the uuid dir moved behind the Bazel
hub branch, so a gem committed as its archive is asked what it was
asked before.

Refs #2348.

Assisted-by: Claude Code:claude-fable-5-2
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review December 2, 2026 14:30
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

bugbot run


Generated by Claude Code

@cursor

cursor Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes vendoring write/refuse paths and repair behavior for all gem directory layouts; mistakes could refuse valid gems or still lose files on clone, but scope is limited to the gem backend with extensive tests.

Overview
Vendored plain Ruby gems now get the same git-commit guarantees that platform-gem trees already had: uuid-dir !* metadata, pre-download refusal when the vendor path is ignored, and a post-write check that every file in the copy would be tracked.

The gem backend neutralizes only shipped .gitignore files that actually hide copy files (templates and patch-rewritten ignores stay intact), records that shape in the ledger, and repair/redownload restore ignores from inventory so older entries still verify. vendor_gem_copy_gitignored warns once when an in-sync run adds the uuid pair but a legacy shipped ignore still drops files, with git add -f as the remedy. repair also restores missing gem uuid git metadata alongside npm-family entries.

Docs and contract rows were updated (CLI_CONTRACT.md, new docs/ecosystems.md section). Tests add core committable_gem_trees coverage and an ignored host e2e that commits, clones, and runs frozen bundle install.

Reviewed by Cursor Bugbot for commit 8900ea7. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 8900ea7. Configure here.

The check for whether a .gitignore the gem ships hides a file asked
about the file before its directories, so a negation looked like it
re-included a file under an ignored directory. Git never looks inside
such a directory. The copy then kept that .gitignore, and the fresh
vendor refused the gem where it could have emptied the file.

Directories are now asked top-down, first match settles it.

Refs #2348.

Assisted-by: Claude Code:claude-fable-5-2
Both sides appended a test to e2e_vendor_gem_build.rs; both are kept.

Assisted-by: Claude Code:claude-fable-5-2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants