Skip to content

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

Merged
lpcox merged 3 commits into
mainfrom
copilot/refactor-server-proxy-tests
May 26, 2026
Merged

refactor: split server.proxy.test.js into 6 focused test modules#3827
lpcox merged 3 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

github-actions Bot commented May 26, 2026

✅ Coverage Check Passed

Overall Coverage

Metric Base PR Delta
Lines 96.54% 96.60% 📈 +0.06%
Statements 96.38% 96.44% 📈 +0.06%
Functions 97.99% 98.00% 📈 +0.01%
Branches 90.78% 90.88% 📈 +0.10%
📁 Per-file Coverage Changes (2 files)
File Lines (Before → After) Statements (Before → After)
src/host-iptables-rules.ts 97.0% → 97.7% (+0.68%) 97.0% → 97.7% (+0.67%)
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

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

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

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.

@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 26, 2026

@copilot address review feedback

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 26, 2026

@copilot address review feedback

Addressed in d0373cc.

  • Updated the token-steering test comment to correctly describe re-requiring from the cached module instance.
  • Replaced the two fixed setTimeout(..., 30) waits in websocket tests with event-driven waits (error / secureConnect + setImmediate) to make timing deterministic.
  • Verified with: npx jest --verbose --ci server.websocket.test.js server.token-steering.test.js --runInBand.

Copilot finished work on behalf of lpcox May 26, 2026 02:23
@github-actions
Copy link
Copy Markdown
Contributor

Smoke Test: Claude Engine ✅

Total: PASS

💥 [THE END] — Illustrated by Smoke Claude

@github-actions
Copy link
Copy Markdown
Contributor

🧪 Smoke Test: Copilot BYOK (Offline) Mode

Test Result
GitHub MCP (list PRs)
GitHub.com connectivity ✅ (pre-step data unavailable — template vars unexpanded)
File write/read ✅ (pre-step data unavailable — template vars unexpanded)
BYOK inference (this response)

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

Overall: PASS · Author: @Copilot · Assignees: @lpcox, @Copilot

🔑 BYOK report filed by Smoke Copilot BYOK

@github-actions
Copy link
Copy Markdown
Contributor

  • Disambiguate internal test-helper exports across six modules ✅\n- Remove unused src/services/agent-environment.ts barrel export ✅\n- GitHub reads ✅ · Playwright ✅ · file I/O ✅ · discussion ✅ · build ✅\n- 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: API Proxy OpenTelemetry Tracing

Scenario Result Details
1. Module Loading ✅ Pass otel.js loads successfully; exports: startRequestSpan, setTokenAttributes, endSpan, endSpanError, shutdown, isEnabled + internal symbols
2. Test Suite ✅ Pass 33/33 tests passed in otel.test.js (ProxyAwareOtlpExporter, FileSpanExporter, shutdown)
3. Env Var Forwarding ✅ Pass src/services/api-proxy-service.ts forwards OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_HEADERS, GITHUB_AW_OTEL_TRACE_ID, GITHUB_AW_OTEL_PARENT_SPAN_ID to the api-proxy container
4. Token Tracker Integration ✅ Pass onUsage callback exists at line 237 and onSpanEnd at lines 185/234/279 in token-tracker-http.js
5. OTEL Diagnostics ✅ Pass File fallback exporter writes to /var/log/api-proxy/otel.jsonl; OTLP export activates when OTEL_EXPORTER_OTLP_ENDPOINT is set

All 5 scenarios passed. OTEL tracing integration is fully functional.

📡 OTel tracing validated by Smoke OTel Tracing

@github-actions
Copy link
Copy Markdown
Contributor

🔬 Smoke Test Results

Test Status
GitHub MCP connectivity
GitHub.com HTTP connectivity
File write/read

PR: refactor: split server.proxy.test.js into 6 focused test modules
Author: @Copilot | Assignees: @lpcox @Copilot

Overall: PASS

📰 BREAKING: Report filed by Smoke Copilot

@github-actions
Copy link
Copy Markdown
Contributor

Chroot Smoke Test Results

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

Overall: ❌ 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 1M ·

@github-actions
Copy link
Copy Markdown
Contributor

Smoke Test Results

  • Redis (6379): ❌ host.docker.internal unreachable
  • PostgreSQL pg_isready (5432): ❌ host.docker.internal unreachable
  • PostgreSQL SELECT 1: ❌ host.docker.internal unreachable

Overall: FAIL — Service containers are not reachable from this runner environment. host.docker.internal does not resolve or is not routable.

🔌 Service connectivity validated by Smoke Services

@github-actions
Copy link
Copy Markdown
Contributor

Smoke Test: Gemini Engine Validation

  • Review last 2 merged PRs: ❌ (Failed to list PRs: Missing tools/Unauthorized)
  • Connectivity to github.com: ❌ (Status 000: SSL routines::wrong version number)
  • File Writing Testing: ✅ (Passed)
  • Bash Tool Testing: ✅ (Passed)

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

@lpcox lpcox merged commit 9db98c1 into main May 26, 2026
67 of 68 checks passed
@lpcox lpcox deleted the copilot/refactor-server-proxy-tests branch May 26, 2026 03: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.

[Refactoring] Split server.proxy.test.js into focused test modules

3 participants