Skip to content

[Refactoring] Split containers/api-proxy/server.test.js — 1,696-line test file across 15 describe blocks #2907

@github-actions

Description

@github-actions

Refactoring Opportunity

Summary

  • File: containers/api-proxy/server.test.js
  • Current size: 1,696 lines
  • Responsibilities identified: 15 distinct describe blocks testing unrelated units

Evidence

The file tests at least 15 independent functions in a single flat test file:

19:  describe('httpProbe', ...)
150: describe('validateApiKeys', ...)
348: describe('fetchJson', ...)
446: describe('extractModelIds', ...)
492: describe('fetchStartupModels', ...)
602: describe('reflectEndpoints', ...)
690: describe('healthResponse', ...)
725: describe('makeModelBodyTransform', ...)
827: describe('buildModelsJson', ...)
898: describe('writeModelsJson', ...)
956: describe('composeBodyTransforms', ...)
1008: describe('createProviderServer', ...)   # ~419 lines alone (1008–1427)
1427: describe('provider adapter alwaysBind', ...)
1530: describe('copilot adapter BYOK model fetch', ...)
1646: describe('extractBillingHeaders', ...)

createProviderServer alone spans ~419 lines (1008–1427). Several describes are for lifecycle/server-startup concerns while others test pure transformation utilities — these have no reason to live together.

The file exceeds 1,500 lines and is the second-largest test file in the repository.

Proposed Split

containers/api-proxy/server.test.js (1,696 lines) could be split into:

  • server.network.test.jshttpProbe, fetchJson, fetchStartupModels, reflectEndpoints (~350 lines). Network utility functions.
  • server.models.test.jsextractModelIds, buildModelsJson, writeModelsJson, makeModelBodyTransform, composeBodyTransforms (~430 lines). Model transformation and persistence.
  • server.lifecycle.test.jscreateProviderServer, provider adapter alwaysBind, copilot adapter BYOK model fetch, healthResponse (~620 lines). Server startup and provider lifecycle.
  • server.billing.test.jsvalidateApiKeys, extractBillingHeaders (~200 lines). Auth and billing header logic.

Affected Callers

This is a test file; no production code imports it. Splitting requires updating the Jest config if it uses explicit file lists, but the default glob pattern **/*.test.js will pick up the new files automatically.

Effort Estimate

Low

Benefits

  • Each test file focuses on one concern, making failures easier to diagnose
  • Jest can run individual feature test files in isolation (faster feedback)
  • New contributors can navigate to the test for a specific function without scrolling through 1,700 lines

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

Generated by Refactoring Opportunity Scanner · ● 794.9K ·

  • expires on Jul 10, 2026, 2:34 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