Repository navigation
Fix Composer global home lookup order (#586) - #1421
Conversation
Assisted-by: Claude Code:claude-opus-5-5
When composer isn't on PATH and COMPOSER_HOME is unset, global discovery guessed the Composer home in Composer 1's order and checked ~/.composer first. Composer 2 checks the XDG config dir first on an XDG system (any XDG_* variable set, or /etc/xdg present), so a leftover ~/.composer hid the real global install and scan -g, apply -g and vex -g silently found nothing. Probe $XDG_CONFIG_HOME/composer (or ~/.config/composer) before ~/.composer on XDG systems, as Composer 2's Factory::getHomeDir does. Non-XDG systems and Windows keep their current order. Fixes #586 Assisted-by: Claude Code:claude-opus-5-5
The env() helper in the composer crawler tests is only used by unix-only tests, so it would be dead code (and a clippy error) on Windows. Assisted-by: Claude Code:claude-opus-5-5
Follow-ups from review of the XDG-first order: - Count an XDG_CONFIG_HOME in the supplied environment as an XDG system, so it is never dropped from the probes. - Skip the XDG home when XDG_CONFIG_HOME is relative instead of guessing ~/.config, which Composer would not use; an empty value still means ~/.config, as in Composer. - Build the candidate list on the blocking pool, since the XDG check stats /etc/xdg. - Clear XDG_CONFIG_HOME in a shim test that relies on the HOME fallback, and fix a mislabeled unit-test assertion. Refs #586 Assisted-by: Claude Code:claude-opus-5-5
|
BugBot review Generated by Claude Code |
There was a problem hiding this comment.
✅ 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 ab0ffcb. Configure here.
|
[agent] Generated by Claude Code |
|
Ready for review (burn-down agent)
Generated by Claude Code |
Final review briefWhat it does: Fixes #586. When neither Risk: low. It only changes the last-resort fallback. Windows ordering is the same as before. On non-XDG systems, Look here:
Verified:
Changes I made: none. Open questions (non-blocking):
Auto-merge is armed, so approving sends this straight to the merge queue. Generated by Claude Code |
…g-home-order # Conflicts: # crates/socket-patch-core/src/crawlers/composer_crawler.rs
LLM Description written by Claude Code:claude-opus-5-5
Fixes #586
Summary
Global Composer discovery (
scan -g,apply -g,vex -g) now finds a Composer 2 global install in the XDG config dir even when an old~/.composerdirectory is still around andcomposerisn't on PATH.Root cause
When
COMPOSER_HOMEis unset andcomposer global config homecan't run (composernot on PATH, e.g. acomposer.pharinstall),get_composer_homefalls back tocomposer_home_candidates(crates/socket-patch-core/src/crawlers/composer_crawler.rs). That list probed~/.composerbefore the XDG home, which is Composer 1's rule. Composer 2'sFactory::getHomeDirchecks$XDG_CONFIG_HOME/composer(or~/.config/composer) first on an XDG system (anyXDG_*env var set, or/etc/xdgexists), and only then~/.composer. So a leftover~/.composer, even an empty one, hid the real global install and global commands silently found nothing (exit 0).Fix
~/.composer, matching Composer 2. XDG detection mirrors Composer'suseXdg. AnXDG_CONFIG_HOMEin the supplied environment also counts.XDG_CONFIG_HOMEmeans~/.config, as in Composer. A relative one is skipped rather than guessed, so it can't put a directory Composer wouldn't use ahead of~/.composer.~/.config/composerstays as a last probe everywhere.default_composer_home), since the XDG check stats/etc/xdg.composer_home_candidateskeeps its signature, so it doesn't conflict with Fix Composer vendor-dir config cascade (#439, #686) #1408, which also calls it.Trade-off: Composer 1 still checks
~/.composerfirst. socket-patch can't tell which Composer major is installed without runningcomposer, and whencomposeris on PATH its own answer already wins. So the fallback follows Composer 2. Composer 1 is end-of-life, and packagist stopped serving it on 2025-09-01.Tests (red → green)
~/.composer+ real~/.config/composer, XDG systemcovgap_crawlers_composer_crawler::get_vendor_paths_global_xdg_home_outranks_stale_dot_composerleft: [], the issue's exact symptom)XDG_CONFIG_HOMEset,~/.composer/vendoralso presentcovgap_crawlers_composer_crawler::get_vendor_paths_global_xdg_config_home_outranks_stale_dot_composer~/.composer/vendor)XDG_CONFIG_HOMEcomposer_crawler::tests::test_home_candidates_*(3 unit tests)Commands run locally (Linux, as root):
cargo fmt --all -- --check: okcargo clippy --workspace --all-features -- -D warnings: okcargo test --workspace --all-features --no-fail-fast: all 281 composer tests pass. 13 tests fail only in this sandbox: chmod-based write-failure tests that can't fail as root (*_write_failure_*,*unremovable*,relax_loop_must_not_traverse_symlinked_root, etc.), pluse2e_bun_lockb, which needs network access to patches-api.socket.dev. None touch Composer code. CI runs them as non-root.e2e_vendor_composer_build,e2e_redirect_composer_build) exercise project mode, not the global-home fallback, so they weren't re-run locally. CI runs them.npm/,pypi/,gem/) changes are needed: they only dispatch to the binary./code-review high
I fixed every confirmed finding in ab0ffcb except one. Not fixed: "Composer 1 users with both dirs get the XDG dir". That is the intended trade-off described above.
🤖 Generated with Claude Code
https://claude.ai/code/session_011PgPZPKvQDRtAkxyHR3Pe8
Generated by Claude Code