Skip to content

refactor: Split compose-generator.ts into focused service builders#2558

Merged
lpcox merged 7 commits intomainfrom
copilot/refactor-split-compose-generator
May 5, 2026
Merged

refactor: Split compose-generator.ts into focused service builders#2558
lpcox merged 7 commits intomainfrom
copilot/refactor-split-compose-generator

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 5, 2026

src/compose-generator.ts contained a single ~1,520-line generateDockerCompose() function responsible for building all six container service configs. This makes it hard to review, test, and modify individual service configurations in isolation.

Changes

New src/services/ modules — each service is now a self-contained builder:

File Lines Owns
src/services/squid-service.ts 134 Squid proxy: volumes, SSL, healthcheck, image selection
src/services/agent-service.ts 1,099 Agent env vars, bind mounts, service config, iptables-init
src/services/api-proxy-service.ts 261 API proxy sidecar + agent env mutations for credential isolation
src/services/doh-proxy-service.ts 48 DNS-over-HTTPS sidecar
src/services/cli-proxy-service.ts 117 CLI (DIFC) proxy sidecar + agent env mutations

src/network-allocator.ts (~68 lines) — extracts the previously dead-code getExistingDockerSubnets / _generateRandomSubnet helpers.

src/compose-generator.ts — reduced from 1,651 → 253 lines; now a thin orchestration facade:

const squidService  = buildSquidService({ ... });
const environment   = buildAgentEnvironment({ ... });
const agentVolumes  = buildAgentVolumes({ ... });
const agentService  = buildAgentService({ ... });
const iptablesInit  = buildIptablesInitService({ ... });

if (config.enableApiProxy && networkConfig.proxyIp) {
  const { service, agentEnvAdditions } = buildApiProxyService({ ... });
  Object.assign(environment, agentEnvAdditions);
  agentService.depends_on['api-proxy'] = { condition: 'service_healthy' };
}
// ... doh-proxy, cli-proxy

Notes

  • generateDockerCompose() signature is unchanged — zero impact on callers
  • Optional sidecar builders return agentEnvAdditions instead of mutating inputs directly; the orchestrator applies them with Object.assign
  • The shared NetworkConfig and ImageBuildConfig interfaces are defined in squid-service.ts and re-used by the other service modules

- Extract src/network-allocator.ts (~68 lines): subnet allocation helpers
- Create src/services/squid-service.ts (~134 lines): Squid proxy service builder
- Create src/services/agent-service.ts (~1099 lines): agent env, volumes, service + iptables-init
- Create src/services/api-proxy-service.ts (~261 lines): API proxy service builder
- Create src/services/doh-proxy-service.ts (~48 lines): DoH proxy service builder
- Create src/services/cli-proxy-service.ts (~117 lines): CLI proxy service builder
- Reduce src/compose-generator.ts to 253 lines thin orchestration facade (down from 1,651)

All 1747 tests pass. No TypeScript or lint errors."

Agent-Logs-Url: https://github.com/github/gh-aw-firewall/sessions/5c906a4c-d75e-4981-96ac-b575c9f5dc28
Copilot AI changed the title [WIP] Refactor src/compose-generator.ts into focused service builders refactor: Split compose-generator.ts into focused service builders May 5, 2026
Copilot finished work on behalf of lpcox May 5, 2026 14:00
Copilot AI requested a review from lpcox May 5, 2026 14:00
@lpcox lpcox marked this pull request as ready for review May 5, 2026 18:27
@lpcox lpcox requested a review from Mossaka as a code owner May 5, 2026 18:27
Copilot AI review requested due to automatic review settings May 5, 2026 18:27
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 5, 2026

⚠️ Coverage Regression Detected

This PR decreases test coverage. Please add tests to maintain coverage levels.

Overall Coverage

Metric Base PR Delta
Lines 86.45% 86.72% 📈 +0.27%
Statements 86.38% 86.65% 📈 +0.27%
Functions 90.61% 90.36% 📉 -0.25%
Branches 79.23% 79.25% 📈 +0.02%
📁 Per-file Coverage Changes (2 files)
File Lines (Before → After) Statements (Before → After)
src/container-lifecycle.ts 86.1% → 87.2% (+1.09%) 86.3% → 87.4% (+1.08%)
src/compose-generator.ts 90.4% → 98.5% (+8.08%) 90.1% → 98.5% (+8.46%)
✨ New Files (6 files)
  • src/network-allocator.ts: 16.1% lines
  • src/services/agent-service.ts: 95.5% lines
  • src/services/api-proxy-service.ts: 98.4% lines
  • src/services/cli-proxy-service.ts: 94.7% lines
  • src/services/doh-proxy-service.ts: 88.9% lines
  • src/services/squid-service.ts: 100.0% lines

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

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

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 Docker Compose generation by splitting the previously monolithic generateDockerCompose() implementation into focused service-builder modules under src/services/, plus extracting Docker subnet inspection helpers into src/network-allocator.ts. The goal is to make individual service definitions easier to review and evolve independently while keeping the generateDockerCompose() call signature intact.

Changes:

  • Introduced dedicated service builders for squid, agent (+ iptables-init), api-proxy, doh-proxy, and cli-proxy compose service definitions.
  • Simplified src/compose-generator.ts into an orchestration layer that wires together the builders and applies sidecar-driven agent env additions.
  • Extracted Docker network subnet discovery/random subnet generation helpers into src/network-allocator.ts.
Show a summary per file
File Description
src/compose-generator.ts Reduced to orchestration: constructs shared paths/config, calls service builders, assembles services map.
src/network-allocator.ts New module containing Docker subnet inspection and random subnet selection helper(s).
src/services/squid-service.ts New squid compose service builder (volumes, SSL mounts, healthcheck, image/build selection).
src/services/agent-service.ts New agent builder module (agent env, volumes, agent service, iptables-init service).
src/services/api-proxy-service.ts New api-proxy sidecar builder plus computed agent env additions for credential isolation.
src/services/doh-proxy-service.ts New DoH sidecar builder (cloudflared service config).
src/services/cli-proxy-service.ts New CLI proxy sidecar builder plus agent env additions for DIFC proxy routing.

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: 2

Comment thread src/compose-generator.ts Outdated
Comment thread src/network-allocator.ts Outdated
@github-actions

This comment has been minimized.

lpcox and others added 2 commits May 5, 2026 11:34
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Comment thread src/compose-generator.ts Fixed
…ort, function or class'

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@lpcox
Copy link
Copy Markdown
Collaborator

lpcox commented May 5, 2026

@copilot merge main

…t-compose-generator

Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 5, 2026

@copilot merge main

Done — merged main into this branch (commit 1852a00). No conflicts.

Copilot finished work on behalf of lpcox May 5, 2026 20:23
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 5, 2026

@copilot merge main

Done — merged main into the PR branch (commit 347f41e). Also fixed a broken import that resulted from the merge: network-allocator.ts exports generateRandomSubnet (renamed in a prior fix commit), but compose-generator.ts still imported the old _generateRandomSubnet name; removed that stale import/re-export entirely (commit 70f0efe). All 1,743 tests pass.

Copilot finished work on behalf of lpcox May 5, 2026 20:26
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 5, 2026

✅ Coverage Check Passed

Overall Coverage

Metric Base PR Delta
Lines 86.45% 86.77% 📈 +0.32%
Statements 86.39% 86.69% 📈 +0.30%
Functions 80.51% 81.22% 📈 +0.71%
Branches 79.23% 79.25% 📈 +0.02%
📁 Per-file Coverage Changes (2 files)
File Lines (Before → After) Statements (Before → After)
src/container-lifecycle.ts 86.1% → 87.2% (+1.09%) 86.3% → 87.4% (+1.08%)
src/compose-generator.ts 90.4% → 98.5% (+8.04%) 90.1% → 98.5% (+8.39%)
✨ New Files (6 files)
  • src/network-allocator.ts: 0.0% lines
  • src/services/agent-service.ts: 95.5% lines
  • src/services/api-proxy-service.ts: 98.4% lines
  • src/services/cli-proxy-service.ts: 94.7% lines
  • src/services/doh-proxy-service.ts: 88.9% lines
  • src/services/squid-service.ts: 100.0% lines

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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 5, 2026

Smoke Test: Copilot BYOK — PASS

  • ✅ GitHub MCP: PR list confirmed (dependabot[bot] PR chore(deps): Bump postcss from 8.5.8 to 8.5.14 in /docs-site #2580 returned)
  • ⚠️ HTTP test: pre-step data unavailable (template vars unexpanded)
  • ⚠️ File write/read: pre-step data unavailable (template vars unexpanded)
  • ✅ BYOK inference: responding via api-proxy → api.githubcopilot.com (COPILOT_OFFLINE=true)

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

Author: @Copilot | Assignees: @lpcox, @Copilot

🔑 BYOK report filed by Smoke Copilot BYOK

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 5, 2026

Smoke Tests Passed

  • ✅ GitHub MCP: Retrieved 2 merged PRs
  • ✅ Playwright: GitHub page loaded (title contains "GitHub")
  • ✅ File Writing: Test file created
  • ✅ Bash Tool: File verified

Status: PASS

💥 [THE END] — Illustrated by Smoke Claude

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 5, 2026

🔬 Smoke Test Results

Test Status
GitHub MCP connectivity
File write/read (smoke-test-copilot-25400415501.txt)
GitHub.com connectivity

PR: "refactor: Split compose-generator.ts into focused service builders" — author @Copilot, assignees @lpcox @Copilot

Overall: PASS

📰 BREAKING: Report filed by Smoke Copilot

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 5, 2026

🔮 Codex smoke: FAIL
PR: Split docker-manager-compose.test.ts (3,525 lines) by service area
PR: refactor: extract shared parameterised test factory for log sub-commands
✅ GitHub PR review
❌ Safe Inputs GH CLI: safeinputs-gh unavailable
✅ Playwright: title contains GitHub
❌ Tavily: no search tool exposed
✅ File + bash verification
✅ Discussion comment + 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
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 5, 2026

Smoke Test Results: FAIL

Check Result
Redis PING ❌ Connection timeout
PostgreSQL pg_isready ❌ No response
PostgreSQL SELECT 1 ❌ Not attempted (pg_isready failed)

host.docker.internal is not reachable from this runner environment. Service containers may not be running or the hostname is not resolving correctly.

🔌 Service connectivity validated by Smoke Services

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 5, 2026

🏗️ 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

Note: Maven required --Dmaven.repo.local=/tmp/... workaround since the default ~/.m2/repository was owned by root and not writable.

Generated by Build Test Suite for issue #2558 · ● 708.3K ·

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 5, 2026

🧪 Chroot Version 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

Overall: ❌ FAILED — Python and Node.js versions differ between host and chroot.

Tested by Smoke Chroot

@lpcox lpcox merged commit b5c88f3 into main May 5, 2026
62 of 68 checks passed
@lpcox lpcox deleted the copilot/refactor-split-compose-generator branch May 5, 2026 21:25
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 src/compose-generator.ts — 1,520-line single function into focused service builders

4 participants