Skip to content

Fix gem remedy unit tests for paths that need quoting (#2276) - #2278

Open
Mikola Lysenko (mikolalysenko) wants to merge 3 commits into
mainfrom
agent/fix-gem-remedy-tests-shell-quoting
Open

Mikola Lysenko (mikolalysenko) wants to merge 3 commits into
mainfrom
agent/fix-gem-remedy-tests-shell-quoting

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

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

Fixes #2276

Summary

Test-only change in crates/socket-patch-cli/src/commands/gem_refresh.rs. Two unit tests of the stale-gem remedy failed on the Windows nightly because they expected paths the code does not print. No behavior of the CLI changes.

Root cause

The remedy bullet prints rm -rf <paths> && bundle install and renders each path through shell_word, which single-quotes a path holding a character outside [A-Za-z0-9_@%+=:,./-]. The tests built the expected command from Path::display(). A Windows temp path holds \, so the bullet has quoted paths and the tests looked for unquoted ones. On Linux a temp path is safe unquoted, and a PR runs no Windows tests, so this only showed on the nightly.

The review of the first fix found a second mismatch in a_copy_no_ruby_owns_is_removed_with_its_gem_dir: it joined specifications/json-1.0.0.gemspec onto the gem home as one component, while the code joins the directory and the file name apart. On Windows the test's path keeps a / where the remedy has a \.

What changed

  • a_copy_no_ruby_owns_is_removed_with_its_gem_dir and a_gem_dir_without_its_gemspec_is_the_thing_to_remove build the expected command with shell_word. The warning detail lists paths unquoted (display_list), so those assertions stay.
  • The first of them builds its gemspec and archive paths a component at a time.
  • the_rm_remedy_quotes_a_path_the_shell_would_split wrapped display() in literal quotes, which breaks under a temp dir with a ' in its path. It uses shell_word too.

Evidence

  • Red on main (cfc870f) on Linux, with a temp dir that needs quoting: TMPDIR='/…/tmp dir' cargo test -p socket-patch-cli --lib gem_refresh:: fails the same two tests at the same lines as the nightly (gem_refresh.rs:2413 and :2473), 11 passed, 2 failed.
  • Green on this branch: the same command passes 13 of 13 with the default temp dir, with tmp dir and with it's a dir.
  • cargo test -p socket-patch-cli --lib: 1076 passed.
  • cargo clippy --locked --workspace --all-features -- -D warnings (CI's command): clean. With --all-targets the local toolchain reports lints in integration-test files this PR does not touch; none are in gem_refresh.rs.
  • Windows: CI run 45793556040 (workflow_dispatch, os=windows) on ebf0df9 is green, test (windows-latest, 1) included. Its log shows all three changed tests ok; the two from CI: two gem_refresh unit tests from #2251 fail on the Windows nightly (expected path not shell-quoted) #2276 failed in that job on the nightly.
  • PR CI on ebf0df9: clippy and every other check pass except hosted-e2e, and so ci-ok. That failure is CI: hosted-e2e gem leg fails on every PR: production published activestorage 6.0.3 patch 146ef6aa, not in GEM_UUIDS #2270 (gem_bundler_hosted_install_proof, production patch 146ef6aa-… not in GEM_UUIDS), which is red on main too. Bugbot found no issues.
  • No end-to-end suite was run: only unit-test expectations changed.

Follow-ups

  • Fix the stale-gem remedy beside another Ruby tree (#2242) #2258 (open) adds a_copy_beside_another_rubys_tree_is_removed_with_its_gem_dir with the same display() expectation. It fails under the spaced temp dir too and will need the same change, in whichever of the two PRs merges second.
  • Not changed here, and older than this PR: on Windows the remedy itself is a POSIX command (rm -rf '…' && bundle install) that cmd.exe and Windows PowerShell do not accept. Whether Windows users should get a different command is a product question.

https://claude.ai/code/session_011f9aePn2Jt8HwcDumwxsHx


Generated by Claude Code

Refs #2276.

Assisted-by: Claude Code:claude-fable-5-2
Two gem_refresh unit tests built the expected `rm -rf ... && bundle
install` command from Path::display(), but the code renders each path
of that command through shell_word, which single-quotes a path holding
a character outside its safe set. A Windows temp path holds a
backslash, so both tests failed on the Windows nightly. A temp dir
with a space in its path fails them the same way on Linux.

Build the expected commands with shell_word. The warning detail lists
the paths unquoted, so its assertions stay as they are.

Fixes #2276.

Assisted-by: Claude Code:claude-fable-5-2
a_copy_no_ruby_owns_is_removed_with_its_gem_dir joined
`specifications/json-1.0.0.gemspec` onto the gem home as one
component. The code joins the directory and the file name apart, so on
Windows the test's path kept a `/` where the remedy has a `\\`, and
the expected command and detail would still not match there.

the_rm_remedy_quotes_a_path_the_shell_would_split wrapped display() in
literal quotes, which breaks under a temp dir with a `'` in its path.
It now uses shell_word too.

Refs #2276.

Assisted-by: Claude Code:claude-fable-5-2
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review November 26, 2026 09:37
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

bugbot run


Generated by Claude Code

@cursor

cursor Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Only unit test expectations change; CLI remedy output behavior is unchanged.

Overview
Test-only updates in gem_refresh.rs so stale-gem remedy assertions match what report actually prints: summary bullets use reinstall_command, which formats each path with shell_word (single quotes when needed), not raw Path::display().

In the_rm_remedy_quotes_a_path_the_shell_would_split, a_copy_no_ruby_owns_is_removed_with_its_gem_dir, and a_gem_dir_without_its_gemspec_is_the_thing_to_remove, expected rm -f / rm -rf … && bundle install strings now use shell_word for paths. That fixes failures on Windows (backslashes) and awkward temp dirs (spaces, quotes) while display() expectations remain for per-gem warning detail text via display_list.

a_copy_no_ruby_owns_is_removed_with_its_gem_dir also builds gemspec/cache paths with separate join steps so path shape matches production on Windows.

Reviewed by Cursor Bugbot for commit ebf0df9. 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.

✅ Bugbot reviewed your changes and found no new issues!

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

Reviewed by Cursor Bugbot for commit ebf0df9. Configure here.

@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] hosted-e2e is red on ebf0df9, and with it ci-ok will be. The failure is #2270, not this PR's: gem_bundler_hosted_install_proof fails on all 3 attempts because production wired patch 146ef6aa-…, which is not in GEM_UUIDS. The other 15 hosted legs pass. It fails the same way on main (cfc870f) and this PR changes only unit-test expectations in gem_refresh.rs. Once #2270 is fixed on main, a re-run of hosted-e2e should be all this needs.


Generated by Claude Code

@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: review brief

What it does
Fixes the two gem_refresh unit tests that fail on the Windows nightly (#2276). The tests now build the expected rm -rf … && bundle install remedy with shell_word, the same quoting the code uses, instead of Path::display(). Test-only: no CLI behavior changes.

Risk
Low. Only expectations inside #[cfg(test)] change; nothing ships to users.

Look here

  • gem_refresh.rs:1989: the quoting test drops its hand-written '…' quotes for shell_word, so a temp dir holding ' works too.
  • [gem_refresh.rs:2387-2405](https://github.com/SocketDev/socket-patch/blob/ebf0df9666a56f560eeadd2f5a53047e41855077/crates/socket-patch-cli/src/commands/gem_refresh.rs#L2387-L2405): the gemspec and archive paths are joined one component at a time, as the code builds them, and the command is quoted with shell_word. The warning detail still lists paths unquoted, which matches display_list.
  • gem_refresh.rs:2480: the gem-dir-without-gemspec bullet.
  • shell_word, gem_refresh.rs:508: the helper the tests now share with the code.

Verified

Changes I made
None.

Open questions


Generated by Claude Code

@mikolalysenko Mikola Lysenko (mikolalysenko) added the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Nov 26, 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

Development

Successfully merging this pull request may close these issues.

CI: two gem_refresh unit tests from #2251 fail on the Windows nightly (expected path not shell-quoted)

2 participants