Skip to content

Propagate gh path to extensions - #14282

Draft
williammartin wants to merge 1 commit into
trunkfrom
williammartin-propagate-gh-path-to-extensions
Draft

Propagate gh path to extensions#14282
williammartin wants to merge 1 commit into
trunkfrom
williammartin-propagate-gh-path-to-extensions

Conversation

@williammartin

Copy link
Copy Markdown
Member

Fixes #14093

Description

Extensions using go-gh retrieve keychain-backed credentials by invoking gh auth token. When the original gh executable is run by explicit path and is not otherwise on PATH, 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 same gh executable that dispatched them.

How did you test this change?

Given an extension needs to retrieve the active authentication token and gh is unavailable on PATH
When the extension is invoked as either gh <extension> or gh extension exec <extension>
Then it can invoke "$GH_PATH" auth token and retrieve the expected token.

Key points

GH_PATH already 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 in acceptance/testdata/extension/extension-env.txtar.

Authorship and follow-up

Who wrote this:

  • A human wrote it.
  • An agent wrote it under close human direction.
  • An agent wrote it independently, and no human has guided the implementation beyond the initial prompt.

Who answers review comments:

  • @williammartin will read and reply directly. Name the account.
  • An agent will draft replies and @username will read them before they are posted.
  • Nobody has explicitly committed to replying.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 2d2a360b-c34f-4ba5-8bf9-5105d9347fb5
Copilot AI balanced review requested due to automatic review settings August 28, 2026 08:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

Review tier: Balanced
Findings: 1 Low severity

New issues introduced by this change (1)
Severity Finding
Low severity 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)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

@kjbyrnes84-lgtm

Copy link
Copy Markdown

@kjbyrnes84-lgtm

Copy link
Copy Markdown

Duplicate of #

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.

gh stack submit fails with authentication token not found for host github.com

3 participants