Skip to content

refactor: extract shared Docker test fixture constants to eliminate copy-paste across 6 test files - #2618

Merged
lpcox merged 2 commits into
mainfrom
copilot/refactor-duplicate-test-fixture
May 6, 2026
Merged

refactor: extract shared Docker test fixture constants to eliminate copy-paste across 6 test files#2618
lpcox merged 2 commits into
mainfrom
copilot/refactor-duplicate-test-fixture

Conversation

Copilot AI commented May 6, 2026

Copy link
Copy Markdown
Contributor

baseConfig and mockNetworkConfig were copy-pasted verbatim across 6 test files (~102 duplicate lines). Any change to the shared mock shape required edits in 6 places, with inconsistencies already creeping in.

Changes

  • New: src/test-helpers/docker-test-fixtures.test-utils.ts — single source of truth for baseConfig (Omit<WrapperConfig, 'workDir'>) and mockNetworkConfig
  • Updated: src/services/{squid,doh-proxy,cli-proxy,api-proxy,agent}-service.test.ts and src/compose-generator.test.ts — replace inline declarations with imports from the shared module
// Before (repeated in 6 files):
const baseConfig: Omit<WrapperConfig, 'workDir'> = {
  allowedDomains: ['github.com', 'npmjs.org'],
  agentCommand: 'echo "test"',
  ...
};
const mockNetworkConfig = { subnet: '172.30.0.0/24', squidIp: '172.30.0.10', agentIp: '172.30.0.20' };

// After:
import { baseConfig, mockNetworkConfig } from '../test-helpers/docker-test-fixtures.test-utils';

The jest.mock('execa', ...) block with mockExecaFn/mockExecaSync intentionally remains per-file — Jest hoists jest.mock() before imports are resolved, so the factory closure cannot reference variables from an external module. Each file now carries a comment explaining this constraint.

The .test-utils.ts suffix follows the existing convention (src/commands/test-helpers.test-utils.ts) and is excluded from the TypeScript build output via tsconfig.json.

Copilot AI changed the title [WIP] Refactor duplicate code in Docker test fixtures refactor: extract shared Docker test fixture constants to eliminate copy-paste across 6 test files May 6, 2026
Copilot finished work on behalf of lpcox May 6, 2026 14:09
Copilot AI requested a review from lpcox May 6, 2026 14:09
@lpcox
lpcox marked this pull request as ready for review May 6, 2026 21:17
@lpcox
lpcox requested a review from Mossaka as a code owner May 6, 2026 21:17
Copilot AI review requested due to automatic review settings May 6, 2026 21:17
@github-actions

github-actions Bot commented May 6, 2026

Copy link
Copy Markdown
Contributor

✅ Coverage Check Passed

Overall Coverage

Metric Base PR Delta
Lines 86.81% 86.89% 📈 +0.08%
Statements 86.75% 86.83% 📈 +0.08%
Functions 81.39% 81.39% ➡️ +0.00%
Branches 79.55% 79.59% 📈 +0.04%
📁 Per-file Coverage Changes (1 files)
File Lines (Before → After) Statements (Before → After)
src/container-lifecycle.ts 87.1% → 88.2% (+1.14%) 87.5% → 88.6% (+1.11%)
✨ New Files (1 files)
  • src/test-helpers/docker-test-fixtures.test-utils.ts: 100.0% lines

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

@github-actions

github-actions Bot commented May 6, 2026

Copy link
Copy Markdown
Contributor

Smoke Test Results

✅ GitHub MCP: Listed 2 merged PRs
✅ Playwright: GitHub page loaded
✅ File Writing: Test file created
✅ Bash Tool: File verified

Status: PASS

💥 [THE END] — Illustrated by Smoke Claude

@github-actions

github-actions Bot commented May 6, 2026

Copy link
Copy Markdown
Contributor

🔬 Smoke Test Results

Test Result
GitHub MCP connectivity ✅ PR listed: "feat(api-proxy): OIDC authentication for Azure OpenAI (Entra-only)"
GitHub.com HTTP connectivity ⚠️ Template variable unresolved (${{ steps.smoke-data.outputs.SMOKE_HTTP_CODE }})
File write/read ⚠️ Template variable unresolved (${{ steps.smoke-data.outputs.SMOKE_FILE_PATH }})

PR: "refactor: extract shared Docker test fixture constants to eliminate copy-paste across 6 test files"
Author: @Copilot | Assignees: @lpcox, @Copilot

Overall Status: ⚠️ PARTIAL — MCP ✅, pre-step smoke data not injected (workflow template vars unresolved).

📰 BREAKING: Report filed by Smoke Copilot

@github-actions

github-actions Bot commented May 6, 2026

Copy link
Copy Markdown
Contributor

🔥 Smoke Test: Copilot BYOK (Offline) Mode

Test Result
GitHub MCP (list merged PRs) ✅ PR #2599 "feat(api-proxy): OIDC authentication for Azure OpenAI"
GitHub.com connectivity ⚠️ Template var not expanded (${{ steps.smoke-data.outputs.SMOKE_HTTP_CODE }})
File write/read ⚠️ Template var not expanded (${{ steps.smoke-data.outputs.SMOKE_FILE_PATH }})
BYOK inference (this response)

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

Overall: PARTIAL — BYOK inference and MCP pass; pre-step template vars were not substituted.

PR author: @Copilot · Assignees: @lpcox, @Copilot

🔑 BYOK report filed by Smoke Copilot BYOK

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 reduces duplication in the unit-test suite by extracting shared Docker compose test fixtures into a single reusable test-utils module, keeping service/compose tests consistent and easier to maintain.

Changes:

  • Added a shared test-utils module exporting baseConfig and mockNetworkConfig.
  • Updated compose-generator and service unit tests to import the shared fixtures instead of duplicating inline constants.
  • Added per-test-file comments clarifying why jest.mock('execa', ...) must remain local (hoisting behavior).
Show a summary per file
File Description
src/test-helpers/docker-test-fixtures.test-utils.ts New shared source of truth for baseConfig and mockNetworkConfig used by multiple Docker compose-related tests.
src/services/squid-service.test.ts Replaced inline fixture constants with imports from the shared test-utils module.
src/services/doh-proxy-service.test.ts Replaced inline fixture constants with imports from the shared test-utils module.
src/services/cli-proxy-service.test.ts Replaced inline fixture constants with imports from the shared test-utils module.
src/services/api-proxy-service.test.ts Replaced inline fixture constants with imports from the shared test-utils module.
src/services/agent-service.test.ts Replaced inline fixture constants with imports from the shared test-utils module.
src/compose-generator.test.ts Replaced inline fixture constants with imports from the shared test-utils module.

Copilot's findings

Tip

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

  • Files reviewed: 7/7 changed files
  • Comments generated: 0

@github-actions

github-actions Bot commented May 6, 2026

Copy link
Copy Markdown
Contributor

Smoke Test

PRs: feat(api-proxy): OIDC authentication for Azure OpenAI (Entra-only); Enable Copilot BYOK provider-env fallback, base-path routing, and hardened token isolation
✅ GitHub PR review
❌ safeinputs-gh PR query (tool unavailable)
✅ Playwright GitHub title
❌ Tavily search (no tools exposed)
✅ File write/read and bash
❌ Discussion query tool unavailable; oracle comment posted via fallback
✅ npm ci && npm run build
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

github-actions Bot commented May 6, 2026

Copy link
Copy Markdown
Contributor

Chroot Smoke Test Results

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

Result: ❌ Not all tests passed. Python and Node.js versions differ between host and chroot environments.

Tested by Smoke Chroot

@github-actions

github-actions Bot commented May 6, 2026

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 #2618 · ● 1.4M ·

@github-actions

github-actions Bot commented May 6, 2026

Copy link
Copy Markdown
Contributor

Smoke Test Results

Check Result
Redis PING ❌ timeout
PostgreSQL pg_isready ❌ no response
PostgreSQL SELECT 1 ❌ timeout

Overall: FAILhost.docker.internal is not reachable from this runner. Service containers are unavailable.

🔌 Service connectivity validated by Smoke Services

@lpcox
lpcox merged commit b1f552a into main May 6, 2026
71 of 74 checks passed
@lpcox
lpcox deleted the copilot/refactor-duplicate-test-fixture branch May 6, 2026 21:43
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.

[Duplicate Code] Docker test fixture boilerplate copy-pasted across 7 test files

3 participants