Skip to content

refactor: split server.proxy.test.js into 6 focused test modules#3827

Open
Copilot wants to merge 2 commits into
mainfrom
copilot/refactor-server-proxy-tests
Open

refactor: split server.proxy.test.js into 6 focused test modules#3827
Copilot wants to merge 2 commits into
mainfrom
copilot/refactor-server-proxy-tests

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 26, 2026

containers/api-proxy/server.proxy.test.js had grown to 1,711 lines covering 7 distinct test concerns across proxyWebSocket, proxyRequest, and token steering utilities — making navigation, parallel execution, and targeted test runs awkward.

Split

The file is deleted and replaced with six focused modules, each with its own self-contained module setup:

File Tests Responsibility
server.websocket.test.js 13 proxyWebSocket — request validation, CONNECT tunnel, auth injection
server.proxy-headers.test.js 6 X-Initiator injection, tool_calls normalisation
server.anthropic-beta.test.js 11 Deprecated beta header retry/learning/proactive-strip logic
server.error-handling.test.js 3 Client stream errors, upstream errors, proxy errors
server.token-guards.test.js 3 Effective token limit + max-runs 429 guards
server.token-steering.test.js 14 getAndClearPendingSteeringMessage, injectSteeringMessage, integration

Approach

  • Each file sets up its own beforeAll/afterAll loading only the symbols it needs from ./server and ./proxy-request, with jest.resetModules() guard for HTTPS_PROXY isolation.
  • The token-steering describe's inner beforeAll was hoisted to file scope and the duplicate guard-reset calls that resulted were deduplicated.
  • No production code changes. All 50 original test cases pass.

Split the 1,711-line server.proxy.test.js into focused modules:
- server.websocket.test.js       (~280 lines) — proxyWebSocket suite
- server.proxy-headers.test.js   (~130 lines) — X-Initiator + tool_calls
- server.anthropic-beta.test.js  (~530 lines) — anthropic deprecated beta
- server.error-handling.test.js  (~160 lines) — error handling tests
- server.token-guards.test.js    (~190 lines) — token guard tests
- server.token-steering.test.js  (~390 lines) — token steering utilities

All 50 original test cases pass across the new files.
Copilot AI changed the title [WIP] Refactor server.proxy.test.js into focused test modules refactor: split server.proxy.test.js into 6 focused test modules May 26, 2026
Copilot finished work on behalf of lpcox May 26, 2026 00:19
Copilot AI requested a review from lpcox May 26, 2026 00:19
@lpcox lpcox marked this pull request as ready for review May 26, 2026 00:45
Copilot AI review requested due to automatic review settings May 26, 2026 00:45
@github-actions
Copy link
Copy Markdown
Contributor

✅ Coverage Check Passed

Overall Coverage

Metric Base PR Delta
Lines 96.54% 96.58% 📈 +0.04%
Statements 96.38% 96.42% 📈 +0.04%
Functions 97.99% 97.99% ➡️ +0.00%
Branches 90.78% 90.82% 📈 +0.04%
📁 Per-file Coverage Changes (1 files)
File Lines (Before → After) Statements (Before → After)
src/config-writer.ts 89.3% → 90.9% (+1.65%) 89.3% → 90.9% (+1.65%)

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

@github-actions
Copy link
Copy Markdown
Contributor

Smoke Test: Claude Engine ✅

Result: PASS

💥 [THE END] — Illustrated by Smoke Claude

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 the API proxy test suite by splitting the previously monolithic containers/api-proxy/server.proxy.test.js into six focused Jest modules, improving navigability and allowing more targeted test runs without changing production behavior.

Changes:

  • Deleted server.proxy.test.js and redistributed its 50 test cases into 6 concern-specific test files.
  • Each new module performs its own isolated module/env setup (jest.resetModules() + HTTPS_PROXY handling) to avoid cross-test contamination.
  • Preserved coverage across WebSocket proxying, header sanitization, Anthropic beta retry behavior, error handling, token guards, and token steering.
Show a summary per file
File Description
containers/api-proxy/server.proxy.test.js Removed the 1,711-line combined test file in favor of focused modules.
containers/api-proxy/server.websocket.test.js WebSocket upgrade validation + CONNECT tunneling + auth/header injection tests.
containers/api-proxy/server.proxy-headers.test.js x-initiator injection and tool_calls normalization tests.
containers/api-proxy/server.anthropic-beta.test.js Anthropic deprecated beta header retry/learning/proactive stripping tests.
containers/api-proxy/server.error-handling.test.js Client/upstream stream error handling and metrics/log assertions.
containers/api-proxy/server.token-guards.test.js Effective-token and max-runs 429 guard behavior tests.
containers/api-proxy/server.token-steering.test.js Timeout/token steering message generation + body injection unit/integration tests.

Copilot's findings

Tip

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

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

Comment on lines +239 to +242
// Load a fresh proxyRequest that shares the same proxy-request module instance
// as the steering functions (assigned in the top-level beforeAll above).
// This ensures the same module instance handles both the threshold crossing
// and the body injection.
Comment on lines +186 to +193
wsProxy(makeUpgradeReq(), socket, Buffer.alloc(0), 'api.openai.com', { 'Authorization': 'Bearer key' }, 'openai');

return new Promise(resolve => setTimeout(() => {
expect(socket.write).toHaveBeenCalledWith(expect.stringContaining('HTTP/1.1 502 Bad Gateway'));
expect(socket.destroy).toHaveBeenCalled();
resolve();
}, 30));
});
@github-actions

This comment has been minimized.

@github-actions
Copy link
Copy Markdown
Contributor

refactor: split server.proxy.test.js into 6 focused test modules
fix(api-proxy): prevent stream_options injection into OpenAI Responses API requests
Filter unresolvable model aliases from /reflect and models.json
GitHub: ✅ File: ✅ Discussion: ✅ Build: ✅ Overall: PASS

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

🧪 Smoke Test Results

Test Status
GitHub MCP connectivity
GitHub.com HTTP connectivity ⚠️ (pre-step data not expanded)
File write/read ⚠️ (pre-step data not expanded)

Overall: PARTIAL — MCP is functional; pre-computed step outputs (${{ steps.smoke-data.outputs.* }}) were not interpolated before agent execution, so HTTP and file tests could not be verified.

PR: refactor: split server.proxy.test.js into 6 focused test modules — author @Copilot, assignees @lpcox @Copilot.

📰 BREAKING: Report filed by Smoke Copilot

@github-actions
Copy link
Copy Markdown
Contributor

🔬 Smoke Test: API Proxy OpenTelemetry Tracing

Scenario Result Notes
1. Module Loading ✅ Pass otel.js loads successfully; exports: startRequestSpan, setTokenAttributes, endSpan, endSpanError, shutdown, isEnabled + internal helpers
2. Test Suite ✅ Pass 33/33 tests passed across span creation, token attributes, parent context, OTLP export, file fallback, and error handling
3. Env Var Forwarding ✅ Pass api-proxy-service.ts forwards OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_HEADERS, GITHUB_AW_OTEL_TRACE_ID, GITHUB_AW_OTEL_PARENT_SPAN_ID + sets OTEL_SERVICE_NAME=awf-api-proxy
4. Token Tracker Integration ✅ Pass onUsage callback exists in token-tracker-http.js (line 237); invoked after normalized usage extraction
5. OTEL Diagnostics ✅ Pass FileSpanExporter tested; spans export to /var/log/api-proxy/otel.jsonl when no OTLP endpoint configured (graceful degradation confirmed)

All 5 scenarios pass. ✅

📡 OTel tracing validated by Smoke OTel Tracing

@github-actions
Copy link
Copy Markdown
Contributor

Chroot Runtime Version Comparison

Runtime Host Version Chroot Version Match?
Python Python 3.12.13 Python 3.12.3
Node.js v24.15.0 v22.22.3
Go go1.22.12 go1.22.12

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

Tested by Smoke Chroot

@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 #3827 · sonnet46 1.1M ·

@github-actions
Copy link
Copy Markdown
Contributor

Smoke Test Results: FAIL

Check Result
Redis PING ❌ Timeout/no response
PostgreSQL pg_isready ❌ No response
PostgreSQL SELECT 1 ❌ Timeout/no response

host.docker.internal is not reachable from this environment — service containers are not accessible.

🔌 Service connectivity validated by Smoke Services

@github-actions
Copy link
Copy Markdown
Contributor

Smoke Test Results (Gemini)

  • GitHub MCP: ❌ (mcpscripts not found)
  • GitHub.com Connectivity: ❌ (SSL error)
  • File Writing: ✅
  • Bash Tool: ✅

Overall Status: FAIL

Warning

Firewall blocked 1 domain

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

  • localhost

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

network:
  allowed:
    - defaults
    - "localhost"

See Network Configuration for more information.

💎 Faceted by Smoke Gemini

@github-actions
Copy link
Copy Markdown
Contributor

Smoke Test: Copilot BYOK (Offline) Mode

Test Result
GitHub MCP connectivity ✅ PR listed successfully
GitHub.com HTTP ⚠️ Pre-step data unavailable (template vars not substituted)
File write/read ⚠️ Pre-step data unavailable (template vars not substituted)
BYOK inference (api-proxy → api.githubcopilot.com) ✅ Agent responded via BYOK path

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

PR: refactor: split server.proxy.test.js into 6 focused test modules by @Copilot — assignees: @lpcox, @Copilot

Overall: PARTIAL (smoke-data pre-step outputs not injected; BYOK inference confirmed ✅)

🔑 BYOK report filed by Smoke Copilot BYOK

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 server.proxy.test.js into focused test modules

3 participants