Skip to content

feat(config:install): improve destination directory detection#48

Open
miguelsanchez-upsun wants to merge 10 commits intomainfrom
cli-134-bin-dir-detection
Open

feat(config:install): improve destination directory detection#48
miguelsanchez-upsun wants to merge 10 commits intomainfrom
cli-134-bin-dir-detection

Conversation

@miguelsanchez-upsun
Copy link
Copy Markdown
Collaborator

@miguelsanchez-upsun miguelsanchez-upsun commented Apr 27, 2026

Summary

  • Expand the bin-dir allowlist with package-manager-adjacent locations (Scoop on Windows) and honor XDG_BIN_HOME.
  • Prefer the bin directory that already contains the running executable so the alt config installs alongside it; fall back to the first writable PATH entry.
  • Skip Homebrew-managed directories (/opt/homebrew/bin on macOS, /home/linuxbrew/.linuxbrew/bin on Linux): a user who installed via Homebrew gets the alt in /usr/local/bin or ~/.local/bin instead of polluting the brew prefix.
  • Honor XDG_CONFIG_HOME when locating the config directory (previously ignored on macOS and Windows), even if the target does not yet exist.
  • Make -y skip the confirmation prompt (previously neither -y nor --no-interaction did — the prompt only checked stdin TTY).
  • Use access(2) for the bin-dir writability check on Unix instead of probing with a temp file.

Copilot AI review requested due to automatic review settings April 27, 2026 18:02
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Improves config:install destination directory selection for alt config/executable installs and aligns interactive behavior with --no-interaction / -y.

Changes:

  • Honor XDG_CONFIG_HOME when computing the alt config directory.
  • Rework FindBinDir() with an expanded per-OS allowlist, writability checks, and preference to co-locate with the running executable (incl. symlink resolution).
  • Make config:install confirmation prompt respect no-interaction (so -y/--yes skips it).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
internal/config/alt/fs.go Adds XDG handling for config dir; overhauls bin-dir selection with allowlist, writability probing, and executable co-location logic.
internal/config/alt/fs_test.go Refactors and significantly expands bin-dir selection tests; updates config-dir tests for new resolution behavior.
commands/config_install.go Skips confirmation prompt when no-interaction is enabled (including via -y/--yes).
Comments suppressed due to low confidence (1)

commands/config_install.go:110

  • This change makes -y/--yes (via no-interaction) skip the confirmation prompt, but commands/config_install_test.go doesn't currently exercise the interactive-confirmation path (most test environments have non-interactive stdin). Consider adding a unit test that forces terminal.Stdin to interactive and verifies that the prompt is skipped when viper.GetBool("no-interaction") is true (may require injecting/stubbing the confirmation function for testability).
	if terminal.Stdin.IsInteractive() && !viper.GetBool("no-interaction") {
		if !terminal.AskConfirmation("Are you sure you want to continue?", true) {
			os.Exit(1)
		}
		cmd.PrintErrln()

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/config/alt/fs.go
Comment thread internal/config/alt/fs.go Outdated
Comment thread internal/config/alt/fs_test.go
Comment on lines +44 to +46
if runtime.GOOS == "windows" {
t.Skip("path setup in this test is unix-style")
}
Copy link

Copilot AI Apr 27, 2026

Choose a reason for hiding this comment

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

TestFindBinDir is now skipped entirely on Windows, but this PR introduces/changes Windows-specific allowlist entries (e.g., Scoop shims). Consider adding Windows-only tests (e.g., via _test.go with //go:build windows) to cover the Windows branch of binDirAllowlist() and FindBinDir() behavior.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Don't think this is needed, there's no Windows-specific logic to exercise beyond what the existing branches do on Linux/macOS.

Comment thread internal/config/alt/fs.go Outdated
Comment thread internal/config/alt/fs.go
@pjcdawkins
Copy link
Copy Markdown
Contributor

Hm I think actually we should never be saving our own binaries to the HomeBrew path: it should be owned entirely via HomeBrew.

pjcdawkins and others added 3 commits April 27, 2026 22:01
Move the running-executable match into an exeMatcher closure so the loop
in FindBinDir reads as one straightforward pass: skip if not on PATH or
not writable, return on co-location, otherwise track first-valid for the
fallback. No behavior change.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Replace the temp-file probe in isWritableDir with golang.org/x/sys/unix
Access on Unix, falling back to the probe file only on Windows where no
equivalent syscall is available. The temp file was created and deleted
on every config:install invocation across each allowlist entry; the
permission-bit check has the same semantics without the side effect.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Remove /opt/homebrew/bin (macOS) and /home/linuxbrew/.linuxbrew/bin
(Linux) from the bin-directory allowlist. Those directories belong to
Homebrew and should not be written to by config:install — when the
running CLI was itself installed via Homebrew, the alt now lands in
/usr/local/bin or ~/.local/bin instead.

The symlink-resolution branch in exeMatcher is kept: a Cellar-style
layout is still reachable when the user opts in via XDG_BIN_HOME, and
the existing test exercises that path.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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