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:
- Creating 6 new test files
- Moving each
describe() block to its corresponding file
- Ensuring each file imports the necessary functions from
proxy-request.js
- Verifying all tests still pass after the split
- Updating any test runner configurations if needed
- 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:
- Run the full test suite:
npm test -- containers/api-proxy/server.*.test.js
- Verify all 50 test cases still pass
- Confirm no duplicate or missing tests
- Check that coverage metrics remain unchanged
Detected by Refactoring Scanner workflow. Run date: 2026-05-25
Generated by Refactoring Opportunity Scanner · ● 6.5M · ◷
Refactoring Opportunity
Summary
containers/api-proxy/server.proxy.test.jsEvidence
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.jsincludingproxyRequest,proxyWebSocket, and token steering utilities.Current structure breakdown:
Complexity indicators:
it()blocks)expect()calls)beforeEachblocksafterEachblocksThe two largest sections (anthropic deprecated beta handling + token steering) comprise 54% of the file (926 lines).
Proposed Split
Split
server.proxy.test.jsinto focused test modules aligned with the functionality being tested:1.
server.websocket.test.js(~280 lines)proxyWebSockettest suite2.
server.proxy-headers.test.js(~150 lines)3.
server.anthropic-beta.test.js(~550 lines)4.
server.error-handling.test.js(~170 lines)5.
server.token-guards.test.js(~200 lines)6.
server.token-steering.test.js(~400 lines)getAndClearPendingSteeringMessagetestsinjectSteeringMessagetestsShared test utilities (if needed):
server.test-utils.jsAffected Files
Files that import from
proxy-request.js(the module under test):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:describe()block to its corresponding fileproxy-request.jsBenefits
Testing Strategy
After the split:
npm test -- containers/api-proxy/server.*.test.jsDetected by Refactoring Scanner workflow. Run date: 2026-05-25