Skip to content

refactor: extract Copilot API resolver from cli.ts#2636

Merged
lpcox merged 1 commit intomainfrom
refactor/split-cli
May 6, 2026
Merged

refactor: extract Copilot API resolver from cli.ts#2636
lpcox merged 1 commit intomainfrom
refactor/split-cli

Conversation

@lpcox
Copy link
Copy Markdown
Collaborator

@lpcox lpcox commented May 6, 2026

Summary

Extracts 4 Copilot API helper functions from src/cli.ts (lines 131-214) into a focused src/copilot-api-resolver.ts module (84 lines):

  • resolveCopilotApiKey() — resolves BYOK key from env vars
  • deriveCopilotApiTargetFromProviderBaseUrl() — extracts hostname
  • deriveCopilotApiBasePathFromProviderBaseUrl() — extracts base path
  • resolveCopilotApiRouting() — combined target/path resolution with precedence

Backwards Compatibility

cli.ts re-exports all symbols, so existing imports (e.g., cli.test.ts) continue to work unchanged.

Verification

  • ✅ Build passes (npm run build)
  • ✅ All 32 cli tests pass
  • ✅ Lint passes (0 errors)

Closes #2624

Extract resolveCopilotApiKey, deriveCopilotApiTargetFromProviderBaseUrl,
deriveCopilotApiBasePathFromProviderBaseUrl, and resolveCopilotApiRouting
into src/copilot-api-resolver.ts (84 lines).

cli.ts re-exports all symbols for backwards compatibility.

All 32 cli tests pass. Build passes.

Closes #2624

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 6, 2026 23:16
@lpcox lpcox requested a review from Mossaka as a code owner May 6, 2026 23:16
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 6, 2026

✅ Coverage Check Passed

Overall Coverage

Metric Base PR Delta
Lines 86.81% 86.91% 📈 +0.10%
Statements 86.75% 86.85% 📈 +0.10%
Functions 80.71% 80.88% 📈 +0.17%
Branches 79.59% 79.63% 📈 +0.04%
📁 Per-file Coverage Changes (2 files)
File Lines (Before → After) Statements (Before → After)
src/cli.ts 31.6% → 29.0% (-2.53%) 32.0% → 29.0% (-2.98%)
src/container-lifecycle.ts 87.1% → 88.2% (+1.14%) 87.5% → 88.6% (+1.11%)
✨ New Files (1 files)
  • src/copilot-api-resolver.ts: 95.7% lines

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

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

This PR refactors Copilot BYOK/Copilot API routing helper logic out of src/cli.ts into a dedicated src/copilot-api-resolver.ts module, keeping cli.ts as the public/backwards-compatible export surface for existing consumers.

Changes:

  • Added src/copilot-api-resolver.ts containing the 4 Copilot API resolution/derivation helpers (key, target, base path, combined routing).
  • Updated src/cli.ts to import the helpers for internal use and re-export them for backwards compatibility (e.g., existing cli.test.ts imports).
Show a summary per file
File Description
src/copilot-api-resolver.ts New focused module for Copilot API key/target/base-path resolution helpers.
src/cli.ts Removes inlined helper implementations; imports and re-exports helpers from the new module to preserve existing import paths.

Copilot's findings

Tip

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

  • Files reviewed: 2/2 changed files
  • Comments generated: 0

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 6, 2026

🔥 Smoke Test: Copilot BYOK (Offline) Mode

Test Result
GitHub MCP (list PRs) ✅ — "refactor: eliminate duplicate log source resolution logic"
GitHub.com connectivity ⚠️ — template var not expanded (${{ steps.smoke-data.outputs.SMOKE_HTTP_CODE }})
File write/read ⚠️ — template var not expanded (${{ steps.smoke-data.outputs.SMOKE_FILE_PATH }})
BYOK inference (api-proxy → api.githubcopilot.com) ✅ — responding now

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

Overall: PARTIAL — MCP and BYOK inference pass; pre-step template vars were not substituted so HTTP/file tests are unverifiable.

PR by @lpcox · Assignees: none listed

🔑 BYOK report filed by Smoke Copilot BYOK

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 6, 2026

Smoke Test Results

✅ GitHub MCP: refactor: eliminate duplicate log source resolution logic
✅ Playwright: GitHub page title verified
✅ File Writing: /tmp/gh-aw/agent/smoke-test-claude-25466464266.txt created
✅ Bash Verification: File contents confirmed

Status: PASS

💥 [THE END] — Illustrated by Smoke Claude

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 6, 2026

🧪 Smoke Test Results

Test Result
GitHub MCP connectivity ✅ PR list returned successfully
GitHub.com HTTP connectivity ⚠️ Pre-step data not available (template vars unexpanded)
File write/read ⚠️ Pre-step data not available (template vars unexpanded)

PR: "refactor: extract Copilot API resolver from cli.ts" by @lpcox
Overall status: PARTIAL — MCP ✅, pre-step outputs unavailable for HTTP/file tests

📰 BREAKING: Report filed by Smoke Copilot

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 6, 2026

🔮 Codex smoke: FAIL
PRs: refactor: eliminate duplicate log source resolution logic; refactor: extract shared Docker test fixture constants to eliminate copy-paste across 6 test files
✅ GitHub PR review
❌ safeinputs-gh query
✅ Playwright title
❌ Tavily search
✅ File + bash
✅ Discussion comment
✅ npm ci && npm run build

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

github-actions Bot commented May 6, 2026

🏗️ 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 #2636 · ● 1.5M ·

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 6, 2026

🧪 Chroot Runtime Version Comparison

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

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

Tested by Smoke Chroot

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 6, 2026

Smoke Test Results — PR #2636

Check Result
Redis PING ❌ timeout (no response on host.docker.internal:6379)
PostgreSQL pg_isready ❌ no response on host.docker.internal:5432
PostgreSQL SELECT 1 ❌ skipped (pg_isready failed)

Overall: FAIL — service containers appear unreachable from this runner environment. host.docker.internal resolves to 172.17.0.1 but neither Redis nor PostgreSQL responded.

🔌 Service connectivity validated by Smoke Services

@lpcox
Copy link
Copy Markdown
Collaborator Author

lpcox commented May 6, 2026

@copilot address the review feedback

Copy link
Copy Markdown
Contributor

Copilot AI commented May 6, 2026

@copilot address the review feedback

I checked the PR review details and there are currently no generated review comments to address on this PR (the reviewer summary shows 0 comments). Please point me to the specific feedback you want me to apply, and I’ll make the update right away.

Copilot finished work on behalf of lpcox May 6, 2026 23:36
@lpcox lpcox merged commit 692afd9 into main May 6, 2026
69 of 73 checks passed
@lpcox lpcox deleted the refactor/split-cli branch May 6, 2026 23:48
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.

[Refactoring] Split src/cli.ts (1,446 lines) — extract Copilot API helpers, orchestrator, and logs handlers

3 participants