Skip to content

Extract shared tokenAuthHeaders helper to deduplicate auth-prefix header assembly in copilot.js - #7875

Merged
lpcox merged 2 commits into
mainfrom
copilot/duplicate-auth-header-assembly
Aug 31, 2026
Merged

Extract shared tokenAuthHeaders helper to deduplicate auth-prefix header assembly in copilot.js#7875
lpcox merged 2 commits into
mainfrom
copilot/duplicate-auth-header-assembly

Conversation

Copilot AI commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Provider adapters repeated auth-header assembly logic across openai.js, anthropic.js, copilot.js, and google-adapter.js, with copilot.js in particular reimplementing the same prefix + ' ' + token Authorization-header concatenation in three separate places (models request, static headers, and /models auth resolution).

Shared helper

  • Added tokenAuthHeaders(prefix, token, extraHeaders) to containers/api-proxy/providers/auth-headers.js — builds an Authorization: <prefix> <token> header, optionally merged with extra headers.
  • bearerAuthHeaders is now implemented in terms of tokenAuthHeaders('Bearer', ...), making it the single source of truth for Authorization-header assembly.

Copilot adapter cleanup

  • containers/api-proxy/providers/copilot.js now calls tokenAuthHeaders instead of manually concatenating the auth prefix and token in buildCopilotModelsRequest, buildStaticHeaders, and getAuthHeaders.
  • Consolidated the GitHub-token prefix computation (requiresGitHubTokenPrefix ? 'token' : 'Bearer') into a single githubTokenAuthPrefix constant instead of recomputing it inline at each call site.
// before
const prefix = requiresGitHubTokenPrefix ? 'token' : 'Bearer';
return withCopilotIntegration({ 'Authorization': prefix + ' ' + githubToken }, integrationId);

// after
return withCopilotIntegration(tokenAuthHeaders(githubTokenAuthPrefix, githubToken), integrationId);

Tests

  • Added unit tests for tokenAuthHeaders covering prefix/token composition, extra-header merging, non-mutation of inputs, and equivalence with bearerAuthHeaders.

openai.js, anthropic.js, and google-adapter.js already composed headers through the shared helpers and did not require changes.

…fix logic

Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor auth-header assembly in API proxy providers Extract shared tokenAuthHeaders helper to deduplicate auth-prefix header assembly in copilot.js Aug 30, 2026
Copilot AI requested a review from lpcox August 30, 2026 22:55
@lpcox
lpcox marked this pull request as ready for review August 31, 2026 14:23
Copilot AI balanced review requested due to automatic review settings August 31, 2026 14:23

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.

🟢 Approval recommended

The refactor preserves existing authentication behavior and has appropriate focused and existing regression coverage.

Pull request overview

Centralizes authorization-header construction and removes repeated Copilot auth-prefix assembly.

Changes:

  • Adds reusable tokenAuthHeaders.
  • Refactors Copilot header construction to use the helper.
  • Adds focused helper tests.
File summaries
File Description
containers/api-proxy/providers/auth-headers.js Adds and exports the shared helper.
containers/api-proxy/providers/copilot.js Reuses centralized auth-prefix/header assembly.
containers/api-proxy/providers/auth-headers.test.js Tests composition, merging, and immutability.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 0
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-actions

Copy link
Copy Markdown
Contributor

✅ Copilot review passed with no inline comments.

@copilot Add the ready-for-aw label to this PR to trigger agentic CI smoke tests.

@github-actions

Copy link
Copy Markdown
Contributor

✅ Coverage Check Passed

Overall Coverage

Metric Base PR Delta
Lines 93.86% 93.88% 📈 +0.02%
Statements 92.67% 92.69% 📈 +0.02%
Functions 93.24% 93.24% ➡️ +0.00%
Branches 86.14% 86.16% 📈 +0.02%
📁 Per-file Coverage Changes (1 files)
File Lines (Before → After) Statements (Before → After)
src/log-directory-setup.ts 96.2% → 100.0% (+3.78%) 96.3% → 100.0% (+3.71%)

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

@github-actions

github-actions Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

🔌 Smoke Services — All services reachable! ✅

🔌 Service connectivity validated by Smoke Services

@github-actions

github-actions Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

📰 VERDICT: Smoke Copilot has concluded. All systems operational. This is a developing story. 🎤

📰 BREAKING: Report filed by Smoke Copilot

@github-actions

github-actions Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Contribution Check completed successfully!

Contribution check complete: PR #7875 follows the relevant CONTRIBUTING.md guidance. It includes unit tests for the new helper, keeps the change in the correct container directory, updates the code in a TypeScript/JS style consistent with the repo, and references the related issue (#7873) in the PR description. No additional reviewer comment needed.

Generated by Contribution Check for #7875

@github-actions

github-actions Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Smoke Copilot BYOK AOAI (Entra) completed. Copilot AOAI BYOK (Entra) mode operational. 🔓

🪪 BYOK (AOAI Entra) report filed by Smoke Copilot BYOK AOAI (Entra)

@github-actions

github-actions Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Build Test Suite completed successfully!

Generated by Build Test Suite for #7875

@github-actions

github-actions Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Smoke Claude passed

Warning

Firewall blocked 1 domain

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

  • api.anthropic.com

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

network:
  allowed:
    - defaults
    - "api.anthropic.com"

See Network Configuration for more information.

Generated by Smoke Claude for #7875

@lpcox
lpcox deployed to aoai-model August 31, 2026 20:22 — with GitHub Actions Active
@github-actions

github-actions Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

✨ The prophecy is fulfilled... Smoke Codex has completed its mystical journey. The stars align. 🌟

Warning

Firewall blocked 2 domains

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

  • msfeed25.pkgs.visualstudio.com
  • registry.npmjs.org

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

network:
  allowed:
    - defaults
    - "msfeed25.pkgs.visualstudio.com"
    - "registry.npmjs.org"

See Network Configuration for more information.

🔮 The oracle has spoken through Smoke Codex

@github-actions

github-actions Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

📰 VERDICT: Smoke Docker Sbx has concluded. All systems operational. This is a developing story. 🎤

📰 BREAKING: Report filed by Smoke Docker Sbx

@github-actions

github-actions Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Smoke Gemini reports failed. Facets need polishing...

💎 Faceted by Smoke Gemini

@github-actions

github-actions Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Smoke Copilot BYOK completed. Copilot BYOK mode operational. 🔓

🔑 BYOK report filed by Smoke Copilot BYOK

@github-actions

github-actions Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

🛡️ Smoke Copilot Network Isolation confirmed the egress allowlist is enforced. ✅

Warning

Firewall blocked 1 domain

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

  • example.com

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

network:
  allowed:
    - defaults
    - "example.com"

See Network Configuration for more information.

🛡️ Egress verdict from Smoke Copilot Network Isolation

@github-actions

github-actions Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

📡 Smoke OTel Tracing completed. All tracing scenarios validated. ✅

📡 OTel tracing validated by Smoke OTel Tracing

@github-actions

github-actions Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Smoke Copilot BYOK AOAI (api-key) completed. Copilot AOAI BYOK (api-key) mode operational. 🔓

🔑 BYOK (AOAI api-key) report filed by Smoke Copilot BYOK AOAI (api-key)

@github-actions

github-actions Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Security Guard completed successfully!

Security review complete - PR #7875 passes analysis. Refactoring extracts duplicate auth-header assembly into shared helper (tokenAuthHeaders). No security weakening: token handling unchanged, no capability additions, no validation regressions, maintains functional equivalence across three call sites. Consolidating security-critical code reduces inconsistency risk.

Generated by Security Guard for #7875

@github-actions

github-actions Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Chroot tests passed! Smoke Chroot - All security and functionality tests succeeded.

Tested by Smoke Chroot

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test: Copilot Engine@Copilot @lpcox

  • ✅ GitHub MCP: connected (list_pull_requests OK)
  • ✅ GitHub.com connectivity: HTTP 200
  • ✅ File write/read test passed

Overall: PASS

📰 BREAKING: Report filed by Smoke Copilot
Add label ready-for-aw to run again

@github-actions

Copy link
Copy Markdown
Contributor

@lpcox Network isolation egress smoke test results:

EGRESS_RESULT allow=pass deny=pass

✅ Allowed domain (github.com) reachable — HTTP 200
✅ Non-allowed domain (example.com) blocked — CONNECT tunnel 403

Overall status: PASS

Warning

Firewall blocked 1 domain

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

  • example.com

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

network:
  allowed:
    - defaults
    - "example.com"

See Network Configuration for more information.

🛡️ Egress verdict from Smoke Copilot Network Isolation
Add label ready-for-aw to run again

@github-actions github-actions Bot added the smoke-copilot-network-isolation Copilot network-isolation egress smoke test label Aug 31, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test: Claude Engine Validation

Check Status
API ✅ PASS
GitHub CLI ✅ PASS
File ✅ PASS

Overall result: PASS

Warning

Firewall blocked 1 domain

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

  • api.anthropic.com

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

network:
  allowed:
    - defaults
    - "api.anthropic.com"

See Network Configuration for more information.

Generated by Smoke Claude for #7875 · claude · haiku45 · 56 AIC · ⊞ 4.5K ·
Add label ready-for-aw to run again

@github-actions

Copy link
Copy Markdown
Contributor

✅ Smoke Test: Copilot BYOK (Direct) Mode

Test Results:

Status: PASS — Direct BYOK mode fully operational

🔑 BYOK report filed by Smoke Copilot BYOK
Add label ready-for-aw to run again

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test: Docker Sbx@lpcox @Copilot

  • MCP connectivity: ✅ (list_pull_requests OK)
  • github.com HTTP: ✅ (200)
  • File write/read: ✅

PR: #7875 Extract shared tokenAuthHeaders helper to deduplicate auth-prefix header assembly in copilot.js

Overall: PASS

📰 BREAKING: Report filed by Smoke Docker Sbx
Add label ready-for-aw to run again

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test Results: GitHub Actions Services Connectivity

  • Redis PING: ❌ (Temporary failure in name resolution)
  • PostgreSQL pg_isready: ❌ (no response)
  • PostgreSQL SELECT 1: ❌ (could not translate host name)

Overall: FAILhost.docker.internal did not resolve in the sandbox network.

🔌 Service connectivity validated by Smoke Services
Add label ready-for-aw to run again

@github-actions

Copy link
Copy Markdown
Contributor

Extract shared tokenAuthHeaders helper to deduplicate auth-prefix header assembly in copilot.js
✅ MCP connectivity
✅ github.com connectivity
✅ File I/O test
✅ BYOK inference test
Running in direct BYOK mode (AWF_AUTH_TYPE=github-oidc + AWF_AUTH_AZURE_* + COPILOT_PROVIDER_BASE_URL) via api-proxy → Azure OpenAI (Foundry, o4-mini-aw) authenticated via Microsoft Entra
Overall: PASS
cc @Copilot @lpcox

🪪 BYOK (AOAI Entra) report filed by Smoke Copilot BYOK AOAI (Entra)
Add label ready-for-aw to run again

@github-actions

Copy link
Copy Markdown
Contributor

@lpcox
Smoke Test Results (Direct BYOK - Azure OpenAI Foundry):
PR #7920: fix: preserve sparse rootfs staging ✅
PR #7903: Add add-llm-provider skill for onboarding new LLM providers/engines ✅

  1. GitHub MCP: ✅ 2. GitHub.com: ✅ 3. File I/O: ✅ 4. Inference: ✅
    Running in direct BYOK mode (COPILOT_PROVIDER_API_KEY + COPILOT_PROVIDER_BASE_URL) via api-proxy → Azure OpenAI (Foundry, o4-mini-aw)
    Status: PASS

🔑 BYOK (AOAI api-key) report filed by Smoke Copilot BYOK AOAI (api-key)
Add label ready-for-aw to run again

@github-actions

Copy link
Copy Markdown
Contributor

Chroot Version Comparison Results

Runtime Host Version Chroot Version Match?
Python Python 3.12.14 Python 3.12.14 ✅ YES
Node.js v24.19.0 v22.23.2 ❌ NO
Go go1.22.12 go1.22.12 ✅ YES

Overall: FAILED — Node.js version mismatch between host and chroot environments. smoke-chroot label not applied.

Tested by Smoke Chroot
Add label ready-for-aw to run again

@github-actions

Copy link
Copy Markdown
Contributor

📡 OTel Tracing Smoke Test Results

  • Scenario 1 (Module Loading)otel.js loads successfully, isEnabled() returns true, exports include startRequestSpan, setTokenAttributes, setBudgetAttributes, endSpan, endSpanError, shutdown, isEnabled, plus internal exporter/serialization helpers.
  • Scenario 2 (Test Suite) ✅ 3 suites / 68 tests passed (otel.test.js, otel-fanout.test.js, otel-workload-identity.test.js).
  • Scenario 3 (Env Var Forwarding)env-passthrough.ts forwards GITHUB_AW_OTEL_TRACE_ID / GITHUB_AW_OTEL_PARENT_SPAN_ID; api-proxy-env-config.ts forwards GH_AW_OTLP_ENDPOINTS, OTEL_EXPORTER_OTLP_ENDPOINT, and both trace context vars.
  • Scenario 4 (Token Tracker Integration)token-tracker-http.js exposes an onUsage callback hook used for OTEL token attribute capture.
  • Scenario 5 (OTEL Diagnostics) ✅ A workflow-level span (gh-aw.agent.setup) was exported to /tmp/gh-aw/otel.jsonl with correct trace/parent-span IDs; the api-proxy sidecar's own per-request span file wasn't present this run since no LLM API calls were proxied by the agent's bash-only workload (expected — token-usage/tracker files show no proxy activity for this run).

All scenarios pass or are expected-pending as designed. No regressions detected in the OTEL tracing integration.

📡 OTel tracing validated by Smoke OTel Tracing
Add label ready-for-aw to run again

@github-actions

Copy link
Copy Markdown
Contributor

PRs:

  • fix: preserve sparse rootfs staging
  • Add add-llm-provider skill for onboarding new LLM providers/engines
  • GitHub merged PR review: ✅
  • safeinputs-gh query: ❌
  • Playwright + file write/read + build: ✅
  • Discussion interaction: ❌
  • Overall status: FAIL

Warning

Firewall blocked 2 domains

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

  • msfeed25.pkgs.visualstudio.com
  • registry.npmjs.org

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

network:
  allowed:
    - defaults
    - "msfeed25.pkgs.visualstudio.com"
    - "registry.npmjs.org"

See Network Configuration for more information.

🔮 The oracle has spoken through Smoke Codex
Add label ready-for-aw to run again

@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 (build only) ✅ PASS
C++ json N/A (build only) ✅ PASS
Deno oak N/A 1/1 passed ✅ PASS
Deno std N/A 1/1 passed ✅ PASS
.NET hello-world N/A (run only) ✅ PASS
.NET json-parse N/A (run only) ✅ PASS
Go color passed ✅ PASS
Go env passed ✅ PASS
Go uuid passed ✅ PASS
Java gson passed ✅ PASS
Java caffeine passed ✅ PASS
Node.js clsx passed ✅ PASS
Node.js execa passed ✅ PASS
Node.js p-limit passed ✅ PASS
Rust fd passed ✅ PASS
Rust zoxide passed ✅ PASS

Overall: 8/8 ecosystems passed — PASS

Notes:

  • Java (Maven) required overriding -Dmaven.repo.local to a writable path (/tmp/gh-aw/agent/m2repo) because ~/.m2/repository was not writable by the runner user in this environment; this is an environment quirk unrelated to the firewall itself. Once redirected, both gson and caffeine compiled and tested successfully through the proxy settings in ~/.m2/settings.xml.
  • All other ecosystems built/installed and ran their test suites without modification.

Generated by Build Test Suite for #7875 · copilot · auto · 75.7 AIC · ⊞ 12K ·
Add label ready-for-aw to run again

@lpcox
lpcox merged commit e6b9499 into main Aug 31, 2026
159 of 163 checks passed
@lpcox
lpcox deleted the copilot/duplicate-auth-header-assembly branch August 31, 2026 20:37
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] Auth-header assembly repeats across API proxy provider adapters

3 participants