fix(cli): cc-connect upgrade resolves symlinked launch path#3
Open
Nemoljy wants to merge 2 commits into
Open
Conversation
`install.sh` symlinks the built cc-connect binary into `~/.local/bin/`, and on macOS `std::env::current_exe()` returns the launch path verbatim (the symlink itself), not the canonical target. `locate_install_repo` therefore walked up from `~/.local/bin/` -> `~/.local/` -> `~/` -> `/`, found no `.git` ancestor, and bailed — breaking `cc-connect upgrade` for every source install where the user launched via the symlink. Canonicalize the exe before walking up. Refactor the walk into a testable `locate_install_repo_from(exe: &Path)` (pub(crate) so the forthcoming `cc-connect doctor` upgrade-target check can reuse the same logic without re-entering `current_exe`). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The "upgrade fails from a symlinked launch" footgun fixed in the
previous commit was invisible until the user actually ran
`cc-connect upgrade`. Add an `upgrade target` line to
`cc-connect doctor` that runs the same lookup against the running
binary's canonical path, so the answer is visible at the same place
users already look when something feels off.
- Source install (`~/.local/bin/cc-connect` -> `<clone>/target/...`):
[OK] cc-connect upgrade target: /Users/.../cc-connect
- Binary install (bootstrap.sh into `~/.cc-connect/bin/`):
[--] no git checkout above this binary — `cc-connect upgrade`
won't work. If you installed via bootstrap.sh, re-run it
to upgrade; otherwise `git pull && ./install.sh` from
inside the clone.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
install.shsymlinks~/.local/bin/cc-connect→<clone>/target/release/cc-connect. On macOS,std::env::current_exe()returns the launch path verbatim (the symlink), not the canonical target — socc-connect upgrade'slocate_install_repowalked up from~/.local/bin/, never found a.gitancestor, and bailed for every source install launched the standard way. Canonicalize before walking up.locate_install_repo_from(exe: &Path)(pub(crate)) and havecc-connect doctorreuse it so this footgun surfaces indoctor— until now it was invisible until the user actually rancc-connect upgrade.Closes #2.
Test plan
cargo fmt --all -- --checkcargo clippy --workspace --all-targets --tests -- -D warningscargo test --workspace— including two new unit tests incrates/cc-connect/src/lifecycle.rs::tests:locate_install_repo_from_resolves_symlinked_launch— positive: builds a tempdir checkout +~/.local/bin-style symlink, asserts the canonical checkout is returned.locate_install_repo_from_errors_outside_checkout— negative: preserves the original actionable "re-run from inside the clone" error../target/debug/cc-connect doctor(run from inside the repo) now reports[OK] cc-connect upgrade target: /Users/.../cc-connectbetweencc-connect binaryandidentity.key. Pre-existing checks unchanged.Domain & docs
None of the toggles apply — no new domain term, no architectural decision, no wire-format / threat-surface change.
Notes for the reviewer
Two commits, split deliberately so the fix can land without the doctor enhancement if you'd prefer to gate that separately:
fix(cli): cc-connect upgrade resolves symlinked launch path— the canonicalize fix +pub(crate)refactor + tests.feat(cli): doctor surfaces cc-connect upgrade target repo— adds the matchingcc-connect doctorline that would have caught this in doctor instead of in upgrade.Linux wasn't independently verified —
/proc/self/exeis generally canonical there, so the bug is likely macOS-only in practice.canonicalizeis harmless on Linux (no-op on an already-canonical path).