Skip to content

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

@github-actions

Description

@github-actions

Refactoring Opportunity

Summary

  • File: containers/api-proxy/server.proxy.test.js
  • Current size: 1,711 lines
  • Responsibilities identified: 7 distinct test concerns
  • Priority score: 5/7 (threshold: 4)

Evidence

This test file has grown to 1,711 lines and covers 7 distinct areas of functionality. The file tests multiple exported functions from proxy-request.js including proxyRequest, proxyWebSocket, and token steering utilities.

Current structure breakdown:

Test Suite Lines Percentage
proxyWebSocket 265 15.5%
proxyRequest X-Initiator injection 124 7.2%
proxyRequest anthropic deprecated beta handling 537 31.4%
proxyRequest error handling 150 8.8%
proxyRequest effective token guard 79 4.6%
proxyRequest max-runs guard 92 5.4%
token steering utilities 389 22.7%

Complexity indicators:

  • 50 test cases (it() blocks)
  • 153 assertions (expect() calls)
  • 5 beforeEach blocks
  • 7 afterEach blocks

The two largest sections (anthropic deprecated beta handling + token steering) comprise 54% of the file (926 lines).

Proposed Split

Split server.proxy.test.js into focused test modules aligned with the functionality being tested:

1. server.websocket.test.js (~280 lines)

  • proxyWebSocket test suite
  • Request validation, proxy configuration, CONNECT tunnel tests

2. server.proxy-headers.test.js (~150 lines)

  • X-Initiator injection tests
  • HTTP header manipulation tests

3. server.anthropic-beta.test.js (~550 lines)

  • Anthropic deprecated beta header handling
  • Header learning and stripping logic

4. server.error-handling.test.js (~170 lines)

  • Error handling tests
  • Upstream error responses

5. server.token-guards.test.js (~200 lines)

  • Effective token guard tests
  • Max-runs guard tests
  • Combined guard state tests

6. server.token-steering.test.js (~400 lines)

  • getAndClearPendingSteeringMessage tests
  • injectSteeringMessage tests
  • Steering state management tests

Shared test utilities (if needed):

  • Common mocks, fixtures, and helpers can be extracted to server.test-utils.js

Affected Files

Files that import from proxy-request.js (the module under test):

containers/api-proxy/model-discovery.js
containers/api-proxy/otel.js
containers/api-proxy/server.js
containers/api-proxy/server.models.test.js
containers/api-proxy/server.proxy.test.js (this file)

Only the test file itself would be split. No changes to the module under test or its consumers.

Effort Estimate

Medium - The split is straightforward since the test suites are already well-organized into top-level describe() blocks. The main work involves:

  1. Creating 6 new test files
  2. Moving each describe() block to its corresponding file
  3. Ensuring each file imports the necessary functions from proxy-request.js
  4. Verifying all tests still pass after the split
  5. Updating any test runner configurations if needed
  6. Deleting the original consolidated file

Benefits

  • Faster test execution: Smaller files can be run in parallel more efficiently
  • Easier navigation: Developers can quickly find tests for specific functionality
  • Reduced cognitive load: Each file focuses on a single aspect of proxy behavior
  • Better IDE performance: Large files can slow down syntax highlighting and code intelligence
  • Clearer test organization: File names immediately indicate what functionality is being tested
  • Easier review: Pull requests touching specific functionality only affect relevant test files

Testing Strategy

After the split:

  1. Run the full test suite: npm test -- containers/api-proxy/server.*.test.js
  2. Verify all 50 test cases still pass
  3. Confirm no duplicate or missing tests
  4. Check that coverage metrics remain unchanged

Detected by Refactoring Scanner workflow. Run date: 2026-05-25

Generated by Refactoring Opportunity Scanner · ● 6.5M ·

  • expires on Jul 24, 2026, 3:56 PM UTC

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions