Skip to content

refactor: remove duplicate HTTP helpers from OidcTokenProvider#2898

Merged
lpcox merged 3 commits into
mainfrom
copilot/fix-duplicate-http-helpers
May 11, 2026
Merged

refactor: remove duplicate HTTP helpers from OidcTokenProvider#2898
lpcox merged 3 commits into
mainfrom
copilot/fix-duplicate-http-helpers

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 11, 2026

OidcTokenProvider privately re-implemented _httpGet, _httpPost, and _getProxyAgent — ~65 lines of logic already exported by github-oidc.js and used correctly by the sibling AwsOidcTokenProvider and GcpOidcTokenProvider. The duplicate had already drifted (e.g. timeout message "OIDC request timeout" vs "GitHub OIDC request timeout").

✨ Enhancement

containers/api-proxy/oidc-token-provider.js

  • Drop https, http, HttpsProxyAgent imports
  • Import mintGitHubOidcToken, httpPost from ./github-oidc
  • Delegate _mintGitHubOidcToken() to the shared mintGitHubOidcToken() utility — consistent with AwsOidcTokenProvider / GcpOidcTokenProvider
  • Replace _httpPost with a thin wrapper around the shared httpPost, preserving test-mockability
  • Remap generic 'Token exchange timeout' errors to the Azure-specific 'Azure token exchange timeout' message in _exchangeForAzureToken
  • Delete _httpGet, _getProxyAgent private methods (~65 lines total removed)
// Before
const https = require('https');
const http = require('http');
const { HttpsProxyAgent } = require('https-proxy-agent');

// After — consistent with AwsOidcTokenProvider / GcpOidcTokenProvider
const { mintGitHubOidcToken, httpPost } = require('./github-oidc');

containers/api-proxy/oidc-token-provider.test.js

  • Integration test previously monkey-patched _httpPost to redirect HTTPS→HTTP; replaced with an _exchangeForAzureToken override, matching the pattern used by the AWS and GCP sibling tests.
  • Added focused tests for _mintGitHubOidcToken() (audience + auth header validation) and _exchangeForAzureToken() timeout error remapping.

Replace private `_httpGet`, `_httpPost`, and `_getProxyAgent` methods in
`OidcTokenProvider` with the equivalent exported functions `httpGet` and
`httpPost` from `github-oidc.js`.  This removes ~65 lines of near-identical
production logic in the credential-exchange path and makes `OidcTokenProvider`
consistent with the sibling `AwsOidcTokenProvider` and `GcpOidcTokenProvider`
classes, which already import from `github-oidc.js`.

Also update the integration test to override `_exchangeForAzureToken` (instead
of the now-deleted `_httpPost`) to route requests to the local HTTP mock server,
matching the pattern used by the AWS and GCP sibling tests.
Copilot AI changed the title [WIP] Fix duplicate HTTP helpers in OidcTokenProvider refactor: remove duplicate HTTP helpers from OidcTokenProvider May 11, 2026
Copilot AI requested a review from lpcox May 11, 2026 14:00
Copilot finished work on behalf of lpcox May 11, 2026 14:00
@lpcox lpcox marked this pull request as ready for review May 11, 2026 15:00
@lpcox lpcox requested a review from Mossaka as a code owner May 11, 2026 15:00
Copilot AI review requested due to automatic review settings May 11, 2026 15:00
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 11, 2026

✅ Coverage Check Passed

Overall Coverage

Metric Base PR Delta
Lines 87.83% 87.91% 📈 +0.08%
Statements 87.79% 87.87% 📈 +0.08%
Functions 83.01% 83.01% ➡️ +0.00%
Branches 79.92% 79.96% 📈 +0.04%
📁 Per-file Coverage Changes (1 files)
File Lines (Before → After) Statements (Before → After)
src/container-lifecycle.ts 87.1% → 88.2% (+1.14%) 87.5% → 88.6% (+1.11%)

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

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

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

Refactors the Azure OidcTokenProvider in containers/api-proxy to stop maintaining its own HTTP/proxy helper implementations and instead reuse the shared github-oidc helpers already used by the AWS/GCP OIDC providers.

Changes:

  • Replaced OidcTokenProvider’s internal HTTP GET/POST + proxy-agent helpers with httpGet/httpPost from ./github-oidc.
  • Deleted the duplicated private helper methods (_httpGet, _httpPost, _getProxyAgent) from OidcTokenProvider.
  • Updated the Azure OIDC provider test to avoid monkey-patching _httpPost, switching to an _exchangeForAzureToken override that calls shared httpPost.
Show a summary per file
File Description
containers/api-proxy/oidc-token-provider.js Removes duplicated HTTP/proxy helper logic and uses shared httpGet/httpPost from github-oidc.
containers/api-proxy/oidc-token-provider.test.js Updates the integration-style test strategy to use shared httpPost via an _exchangeForAzureToken override.

Copilot's findings

Tip

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

Comments suppressed due to low confidence (1)

containers/api-proxy/oidc-token-provider.test.js:86

  • The overridden _exchangeForAzureToken helper doesn't check response.statusCode before JSON-parsing/returning the token. If the mock ever returns a non-200 (or non-JSON) response, the test will fail with a JSON parse error instead of clearly asserting the expected error path. Consider asserting statusCode === 200 (and/or surfacing the response body) to make failures actionable and to align with the production method's behavior.
      const response = await httpPost(
        `http://127.0.0.1:${serverPort}/test-tenant-id/oauth2/v2.0/token`,
        body,
        { 'Content-Type': 'application/x-www-form-urlencoded' }
      );
      const data = JSON.parse(response.body);
      return { access_token: data.access_token, expires_in: data.expires_in || 3600 };
  • Files reviewed: 2/2 changed files
  • Comments generated: 2

Comment on lines +71 to +73
// Override _exchangeForAzureToken to use mock server over http
provider._exchangeForAzureToken = async (oidcJwt) => {
const body = new URLSearchParams({
Comment on lines 153 to 164
/**
* Mint a GitHub OIDC token with the specified audience.
* @returns {Promise<string>} The GitHub-issued JWT
*/
async _mintGitHubOidcToken() {
const url = new URL(this._requestUrl);
url.searchParams.set('audience', this._oidcAudience);

const response = await this._httpGet(url.toString(), {
const response = await httpGet(url.toString(), {
'Authorization': `Bearer ${this._requestToken}`,
'Accept': 'application/json',
});
@github-actions github-actions Bot mentioned this pull request May 11, 2026
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@lpcox
Copy link
Copy Markdown
Collaborator

lpcox commented May 11, 2026

@copilot merge main

…-http-helpers

# Conflicts:
#	containers/api-proxy/oidc-token-provider.js
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 11, 2026

@copilot merge main

Done — merged main into this branch. The conflict in oidc-token-provider.js was resolved by combining both sides: the PR's import cleanup, and main's additions (mintGitHubOidcToken delegation in _mintGitHubOidcToken, thin _httpPost wrapper, and 'Token exchange timeout''Azure token exchange timeout' remapping). All 33 tests pass.

Copilot finished work on behalf of lpcox May 11, 2026 17:54
@github-actions
Copy link
Copy Markdown
Contributor

🔬 Smoke Test Results

Test Status
GitHub MCP connectivity ❌ 401 Bad Credentials
GitHub.com HTTP connectivity ⚠️ Pre-step data not injected (template vars unsubstituted)
File write/read ⚠️ Pre-step data not injected (template vars unsubstituted)

Overall: FAIL

The workflow pre-step outputs (steps.smoke-data.outputs.*) were not substituted into the task prompt — raw ${{ }} expressions were passed verbatim. GitHub MCP authentication also returned 401. PR author/assignee info unavailable due to auth failure.

📰 BREAKING: Report filed by Smoke Copilot

@github-actions
Copy link
Copy Markdown
Contributor

Smoke Test Results

  • ✅ Playwright: GitHub navigation & title verification passed
  • ✅ File Writing: Test file created successfully at /tmp/gh-aw/agent/
  • ✅ Bash Tool: File content verified
  • ❌ GitHub MCP: Remote API auth failed (environment limitation)

Overall: 3/4 tests passed. Core functionality working.

💥 [THE END] — Illustrated by Smoke Claude

@github-actions
Copy link
Copy Markdown
Contributor

Smoke Test: Copilot BYOK (Offline) Mode

Test Result
1. GitHub MCP (list PRs) ❌ 401 Bad credentials
2. GitHub.com HTTP ⚠️ Pre-step data not injected (template unexpanded)
3. File Write/Read ⚠️ Pre-step data not injected (template unexpanded)
4. BYOK Inference (agent responding)

Running in BYOK offline mode (COPILOT_OFFLINE=true) via api-proxy → api.githubcopilot.com

Overall: FAIL — pre-computed step outputs were not injected (GitHub Actions expressions not expanded), and GitHub MCP returned 401.

🔑 BYOK report filed by Smoke Copilot BYOK

@github-actions
Copy link
Copy Markdown
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 #2898 · ● 512.9K ·

@github-actions
Copy link
Copy Markdown
Contributor

Hide internal CLI exports from the public entry point
Remove dead mockLogger export from logger test helper
GitHub reads: ❌ safeinputs-gh unavailable; public REST fallback reviewed titles
Playwright/file/bash/build: ✅
Tavily/discussion query: ❌ tools unavailable
Overall status: FAIL

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • registry.npmjs.org

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

network:
  allowed:
    - defaults
    - "registry.npmjs.org"

See Network Configuration for more information.

🔮 The oracle has spoken through Smoke Codex

@github-actions
Copy link
Copy Markdown
Contributor

Chroot Version Comparison Results

Runtime Host Version Chroot Version Match?
Python Python 3.12.13 Python 3.12.3
Node.js v24.14.1 v20.20.2
Go go1.22.12 go1.22.12

Result: Not all tests passed. Python and Node.js versions differ between host and chroot environments.

Tested by Smoke Chroot

@github-actions
Copy link
Copy Markdown
Contributor

Smoke Test Results

  • Redis PING: ❌ (timeout — host.docker.internal:6379 unreachable)
  • PostgreSQL pg_isready: ❌ (host.docker.internal:5432 - no response)
  • PostgreSQL SELECT 1: ❌ (skipped — host unreachable)

Overall: FAIL — service containers are not reachable via host.docker.internal from this environment.

🔌 Service connectivity validated by Smoke Services

@lpcox lpcox merged commit a4b7e91 into main May 11, 2026
65 of 70 checks passed
@lpcox lpcox deleted the copilot/fix-duplicate-http-helpers branch May 11, 2026 19:53
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.

[Duplicate Code] OidcTokenProvider duplicates HTTP helpers already exported by github-oidc.js

3 participants