Propagate gh path to extensions - #14282
Draft
williammartin wants to merge 1 commit into
Draft
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 2d2a360b-c34f-4ba5-8bf9-5105d9347fb5
Contributor
There was a problem hiding this comment.
Copilot review overview
Review tier: Balanced
Findings: 1
New issues introduced by this change (1)
| Severity | Finding |
|---|---|
pkg/cmd/extension/manager.go — 💭 Commentary: Document the new extension environment contract This makes GH_PATH a value that gh… |
What changed in this PR
Propagates the resolved gh executable path to extensions, enabling authentication when gh is absent from PATH.
Changes:
- Adds the executable path to the extension manager.
- Exposes it to extensions through
GH_PATH. - Adds acceptance coverage for both extension invocation forms.
| File | Description |
|---|---|
pkg/cmd/factory/default.go |
Passes the resolved executable path to the manager. |
pkg/cmd/extension/manager.go |
Sets GH_PATH for dispatched extensions. |
acceptance/testdata/extension/extension-env.txtar |
Verifies token retrieval without relying on PATH. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| // adjust things like usage strings. | ||
| externalCmd.Env = append(externalCmd.Environ(), "GH_EXTENSION=1") | ||
| // Tell the extension that gh dispatched it and provide a reliable path back to this executable. | ||
| externalCmd.Env = append(externalCmd.Environ(), "GH_EXTENSION=1", "GH_PATH="+m.ghPath) |
Member
Author
There was a problem hiding this comment.
Yeh I don't think that should be part of the contract, in fact I think GH_EXTENSION probably shouldn't be in the help environment either. Remove that.
|
|
|
Duplicate of # |
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.

Fixes #14093
Description
Extensions using
go-ghretrieve keychain-backed credentials by invokinggh auth token. When the originalghexecutable is run by explicit path and is not otherwise onPATH, the extension cannot find it and authentication fails.Pass the already-resolved executable path to extension processes through
GH_PATH. This gives extensions a reliable path back to the sameghexecutable that dispatched them.How did you test this change?
Given an extension needs to retrieve the active authentication token and
ghis unavailable onPATHWhen the extension is invoked as either
gh <extension>orgh extension exec <extension>Then it can invoke
"$GH_PATH" auth tokenand retrieve the expected token.Key points
GH_PATHalready supports an explicit user override and resolves stable installation paths such as Homebrew symlinks. Reusing the factory's resolved path avoids independently resolving the executable during extension dispatch.Notes for reviewers
Start with
pkg/cmd/extension/manager.go, then review the black-box scenario inacceptance/testdata/extension/extension-env.txtar.Authorship and follow-up
Who wrote this:
Who answers review comments: