Skip to content

refactor: split server.test.js into focused test files#2969

Merged
lpcox merged 2 commits into
mainfrom
copilot/refactor-server-test-file
May 12, 2026
Merged

refactor: split server.test.js into focused test files#2969
lpcox merged 2 commits into
mainfrom
copilot/refactor-server-test-file

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 12, 2026

✨ Enhancement

What does this improve?

containers/api-proxy/server.test.js had grown to 1,696 lines and mixed 15 unrelated describe blocks into a single flat file. This change splits that coverage by concern so failures are easier to localize and the test surface is easier to navigate.

Why is this valuable?

The largest block in the file (createProviderServer) alone spanned ~400 lines, while network helpers, model transforms, lifecycle behavior, and billing/auth concerns all lived together. Breaking these apart makes targeted iteration practical without changing production behavior.

Implementation approach:

  • Test file split

    • removed the monolithic containers/api-proxy/server.test.js
    • introduced focused replacements:
      • containers/api-proxy/server.network.test.js
      • containers/api-proxy/server.models.test.js
      • containers/api-proxy/server.lifecycle.test.js
      • containers/api-proxy/server.billing.test.js
  • Concern-based grouping

    • Network: httpProbe, fetchJson, extractModelIds, fetchStartupModels, reflectEndpoints
    • Models: makeModelBodyTransform, buildModelsJson, writeModelsJson, composeBodyTransforms
    • Lifecycle: healthResponse, createProviderServer, provider alwaysBind behavior, Copilot BYOK model fetch
    • Billing/Auth: validateApiKeys, extractBillingHeaders
  • Minimal refactor surface

    • preserved existing assertions and helper behavior
    • moved only the shared imports/helpers needed by each new file
    • relied on existing Jest test discovery rather than introducing config churn
// before
containers/api-proxy/server.test.js

// after
containers/api-proxy/server.network.test.js
containers/api-proxy/server.models.test.js
containers/api-proxy/server.lifecycle.test.js
containers/api-proxy/server.billing.test.js

Copilot AI changed the title [WIP] Refactor server.test.js by splitting into smaller files Refactor api-proxy server tests into focused concern-based files May 12, 2026
Copilot finished work on behalf of lpcox May 12, 2026 00:56
Copilot AI requested a review from lpcox May 12, 2026 00:56
@lpcox lpcox changed the title Refactor api-proxy server tests into focused concern-based files refactor: split server.test.js into focused test files May 12, 2026
Copy link
Copy Markdown
Collaborator

@lpcox lpcox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good split of the 1,696-line server.test.js into 4 focused test files by domain (billing, lifecycle, models, network). No test coverage lost. Closes #2907.

@lpcox
Copy link
Copy Markdown
Collaborator

lpcox commented May 12, 2026

/copilot review

@lpcox lpcox closed this May 12, 2026
@lpcox lpcox reopened this May 12, 2026
@lpcox lpcox marked this pull request as ready for review May 12, 2026 01:00
@lpcox lpcox requested a review from Mossaka as a code owner May 12, 2026 01:00
Copilot AI review requested due to automatic review settings May 12, 2026 01:00
@github-actions
Copy link
Copy Markdown
Contributor

✅ Coverage Check Passed

Overall Coverage

Metric Base PR Delta
Lines 87.89% 87.97% 📈 +0.08%
Statements 87.85% 87.92% 📈 +0.07%
Functions 83.51% 83.51% ➡️ +0.00%
Branches 79.79% 79.84% 📈 +0.05%
📁 Per-file Coverage Changes (1 files)
File Lines (Before → After) Statements (Before → After)
src/container-lifecycle.ts 87.3% → 88.4% (+1.09%) 87.7% → 88.7% (+1.06%)

Coverage comparison generated by scripts/ci/compare-coverage.ts

@github-actions
Copy link
Copy Markdown
Contributor

🔬 Smoke Test Results

Test Status
GitHub MCP connectivity ❌ 401 Bad credentials
GitHub.com HTTP connectivity ⚠️ Data not available (template vars unresolved)
File write/read (/tmp/gh-aw/agent/smoke-test-copilot-25706647304.txt)

Overall: FAIL — GitHub MCP authentication unavailable in this environment.

Triggered by workflow run 25706647304

📰 BREAKING: Report filed by Smoke Copilot

@github-actions
Copy link
Copy Markdown
Contributor

Smoke Test: Copilot BYOK (Offline) Mode

Test Result
GitHub MCP connectivity ❌ (401 Bad credentials)
GitHub.com HTTP connectivity ⚠️ (template vars not expanded)
File write/read ⚠️ (template vars not expanded)
BYOK inference (this response)

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

Overall: FAIL — GitHub MCP returned 401; pre-step template variables (${{ steps.smoke-data.outputs.* }}) were not substituted, so HTTP and file tests could not be verified. Author: @lpcox.

🔑 BYOK report filed by Smoke Copilot BYOK

@github-actions
Copy link
Copy Markdown
Contributor

Smoke Test Codex

  • fix: add --ignore-scripts to security-guard Claude Code install
  • refactor: remove dead exports from export audit
  • ✅ GitHub PR review, ✅ Playwright, ✅ File/Bash, ✅ Discussion comment, ✅ Build
  • ❌ Safe Inputs GH, ❌ Tavily search
  • Overall status: FAIL

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 Results

❌ GitHub MCP Testing — gh CLI auth failed (HTTP 401)
✅ Playwright Testing — GitHub page title verified
✅ File Writing Testing — test file created
✅ Bash Tool Testing — file read verification passed

Overall Status: FAIL (GitHub MCP auth issue)

💥 [THE END] — Illustrated by Smoke Claude

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 Jest test suite by removing the monolithic containers/api-proxy/server.test.js and splitting its coverage into smaller, concern-focused test files to improve navigability and failure localization without changing production behavior.

Changes:

  • Removed containers/api-proxy/server.test.js (previously large, mixed concerns).
  • Added focused test suites for network helpers, model helpers, lifecycle/provider-server behavior, and billing/auth helpers.
Show a summary per file
File Description
containers/api-proxy/server.test.js Removes the previous monolithic test file.
containers/api-proxy/server.network.test.js Adds tests for network helpers (probe/fetch/model discovery/reflect).
containers/api-proxy/server.models.test.js Adds tests for model transforms, models.json generation/writes, and composed transforms.
containers/api-proxy/server.lifecycle.test.js Adds tests for health response, provider server behavior, alwaysBind behavior, and BYOK model fetch.
containers/api-proxy/server.billing.test.js Adds tests for key validation and billing header extraction.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comments suppressed due to low confidence (2)

containers/api-proxy/server.lifecycle.test.js:438

  • jest.restoreAllMocks() already restores the process.stdout.write spy returned by collectLogOutput(). Calling spy.mockRestore() immediately afterwards is redundant and can be error-prone across Jest versions. Either remove spy.mockRestore() here or avoid restoreAllMocks and restore only the spies you created in this test.
    jest.restoreAllMocks();
    spy.mockRestore();

containers/api-proxy/server.lifecycle.test.js:464

  • jest.restoreAllMocks() already restores the process.stdout.write spy returned by collectLogOutput(). Calling spy.mockRestore() immediately afterwards is redundant and can be error-prone across Jest versions. Either remove spy.mockRestore() here or avoid restoreAllMocks and restore only the spies you created in this test.
    jest.restoreAllMocks();
    spy.mockRestore();

  • Files reviewed: 5/5 changed files
  • Comments generated: 2

Comment on lines +95 to +99
afterEach((done) => {
let remaining = servers.length;
if (!remaining) { done(); return; }
servers.splice(0).forEach((s) => s.close(() => { if (!--remaining) done(); }));
});
Comment on lines +410 to +412
jest.restoreAllMocks();
spy.mockRestore();

@github-actions
Copy link
Copy Markdown
Contributor

Chroot Version Comparison Results

Runtime Host Version Chroot Version Match?
Python Python 3.12.13 Python 3.12.3
Node.js v24.14.1 v20.20.2
Go go1.22.12 go1.22.12

Overall: Not all tests passed — Python and Node.js versions differ between host and chroot environments. Go versions match.

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 #2969 · ● 1.3M ·

@github-actions
Copy link
Copy Markdown
Contributor

Smoke Test Results

Check Result
Redis PING ❌ Timeout/no response
PostgreSQL pg_isready ❌ No response
PostgreSQL SELECT 1 ❌ Timeout/no response

Overall: FAILhost.docker.internal is not reachable from this environment. Service containers appear unavailable.

🔌 Service connectivity validated by Smoke Services

@lpcox lpcox merged commit 1db879d into main May 12, 2026
68 of 72 checks passed
@lpcox lpcox deleted the copilot/refactor-server-test-file branch May 12, 2026 01:31
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 containers/api-proxy/server.test.js — 1,696-line test file across 15 describe blocks

3 participants