Refactoring Opportunity
Summary
- File:
src/api-proxy-config.test.ts
- Current size: 855 lines
- Issue: 11 distinct validation concerns in single test file
Evidence
The test file has grown to 855 lines with 11 top-level describe blocks covering unrelated validation functions:
Line 13: describe('validateApiProxyConfig', () => {
Line 100: describe('validateApiTargetInAllowedDomains', () => {
Line 175: describe('emitApiProxyTargetWarnings', () => {
Line 351: describe('emitCliProxyStatusLogs', () => {
Line 404: describe('warnClassicPATWithCopilotModel', () => {
Line 444: describe('resolveApiTargetsToAllowedDomains', () => {
Line 595: describe('validateAnthropicCacheTailTtl', () => {
Line 628: describe('extractGhesDomainsFromEngineApiTarget', () => {
Line 676: describe('extractGhecDomainsFromServerUrl', () => {
Line 766: describe('resolveApiTargetsToAllowedDomains with GHEC', () => {
Line 814: describe('resolveApiTargetsToAllowedDomains with GHES', () => {
These fall into clear functional groups:
- Core validation (validateApiProxyConfig, validateApiTargetInAllowedDomains, validateAnthropicCacheTailTtl)
- Domain resolution (resolveApiTargetsToAllowedDomains + GHES/GHEC variants, domain extraction functions)
- Warning/logging (emitApiProxyTargetWarnings, emitCliProxyStatusLogs, warnClassicPATWithCopilotModel)
Proposed Split
Split into 3 focused test files grouped by validation concern:
1. api-proxy-config-validation.test.ts (~280 lines)
validateApiProxyConfig (87 lines)
validateApiTargetInAllowedDomains (75 lines)
validateAnthropicCacheTailTtl (33 lines)
- Focus: Core configuration validation logic
2. api-proxy-config-domains.test.ts (~400 lines)
resolveApiTargetsToAllowedDomains (151 lines)
resolveApiTargetsToAllowedDomains with GHEC (48 lines)
resolveApiTargetsToAllowedDomains with GHES (138 lines)
extractGhesDomainsFromEngineApiTarget (48 lines)
extractGhecDomainsFromServerUrl (90 lines)
- Focus: Domain resolution and extraction (GHES/GHEC/GHEC handling)
3. api-proxy-config-warnings.test.ts (~200 lines)
emitApiProxyTargetWarnings (176 lines)
emitCliProxyStatusLogs (53 lines)
warnClassicPATWithCopilotModel (40 lines)
- Focus: Warning/logging functions
Rationale
Clear functional boundaries:
- Validation tests check correctness of config structure
- Domain tests verify GHES/GHEC/GHEC URL parsing and allowlist logic
- Warning tests ensure appropriate user-facing messages
Easier navigation:
- Developers can locate tests by concern (validation vs. domain logic vs. warnings)
- Test file names match the code's functional areas
Parallel development:
- Teams can work on validation, domain resolution, and warning logic independently without merge conflicts
Affected Files
No production code changes required. Only test organization.
Effort Estimate
Low (1 day)
- Split file into 3 focused test files
- Update Jest
describe structure if needed
- Verify all tests still pass
Benefits
- Faster test file navigation
- Clearer test organization
- Reduced cognitive load (each file ~200-400 lines)
- Easier to identify missing test coverage per concern
Generated by Refactoring Opportunity Scanner · ● 7.5M · ◷
Refactoring Opportunity
Summary
src/api-proxy-config.test.tsEvidence
The test file has grown to 855 lines with 11 top-level
describeblocks covering unrelated validation functions:These fall into clear functional groups:
Proposed Split
Split into 3 focused test files grouped by validation concern:
1.
api-proxy-config-validation.test.ts(~280 lines)validateApiProxyConfig(87 lines)validateApiTargetInAllowedDomains(75 lines)validateAnthropicCacheTailTtl(33 lines)2.
api-proxy-config-domains.test.ts(~400 lines)resolveApiTargetsToAllowedDomains(151 lines)resolveApiTargetsToAllowedDomains with GHEC(48 lines)resolveApiTargetsToAllowedDomains with GHES(138 lines)extractGhesDomainsFromEngineApiTarget(48 lines)extractGhecDomainsFromServerUrl(90 lines)3.
api-proxy-config-warnings.test.ts(~200 lines)emitApiProxyTargetWarnings(176 lines)emitCliProxyStatusLogs(53 lines)warnClassicPATWithCopilotModel(40 lines)Rationale
Clear functional boundaries:
Easier navigation:
Parallel development:
Affected Files
No production code changes required. Only test organization.
Effort Estimate
Low (1 day)
describestructure if neededBenefits