Refactor agent volume assembly into focused mount modules#3638
Conversation
|
| Metric | Base | PR | Delta |
|---|---|---|---|
| Lines | 95.98% | 96.07% | 📈 +0.09% |
| Statements | 95.81% | 95.87% | 📈 +0.06% |
| Functions | 98.02% | 97.85% | 📉 -0.17% |
| Branches | 89.44% | 89.48% | 📈 +0.04% |
📁 Per-file Coverage Changes (2 files)
| File | Lines (Before → After) | Statements (Before → After) |
|---|---|---|
src/services/agent-volumes.ts |
91.7% → 0.0% (-91.72%) | 91.9% → 0.0% (-91.91%) |
src/config-writer.ts |
83.0% → 85.6% (+2.54%) | 83.0% → 85.6% (+2.54%) |
✨ New Files (9 files)
src/services/agent-volumes/credential-hiding.ts: 100.0% linessrc/services/agent-volumes/docker-socket.ts: 92.0% linessrc/services/agent-volumes/etc-mounts.ts: 100.0% linessrc/services/agent-volumes/home-strategy.ts: 97.4% linessrc/services/agent-volumes/hosts-file.ts: 79.5% linessrc/services/agent-volumes/ssl-mounts.ts: 100.0% linessrc/services/agent-volumes/system-mounts.ts: 100.0% linessrc/services/agent-volumes/volume-builder.ts: 100.0% linessrc/services/agent-volumes/workspace-mounts.ts: 100.0% lines
Coverage comparison generated by scripts/ci/compare-coverage.ts
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
This PR refactors the security-critical agent volume assembly logic by decomposing the former monolithic buildAgentVolumes() implementation into a small orchestrator (volume-builder.ts) plus focused mount-concern modules (system, home, etc, hosts, docker socket, SSL, workspace/custom mounts, credential hiding), while keeping the external API available via re-exports.
Changes:
- Added
src/services/agent-volumes/volume-builder.tsorchestrating the mount list construction via dedicated builders. - Introduced focused mount modules for system/home/etc/hosts/docker socket/SSL/workspace/custom mounts and credential-hiding overlays.
- Kept backwards compatibility through
src/services/agent-volumes.tsre-export and adjustedsrc/services/agent-service.tsre-export; added a targeted credential-hiding unit test.
Show a summary per file
| File | Description |
|---|---|
| src/services/agent-volumes/workspace-mounts.ts | Adds workspace + essential mounts builder and chroot-adjusted custom mount translation. |
| src/services/agent-volumes/volume-builder.ts | New orchestrator assembling volume mounts and applying dockerHostPathPrefix translation. |
| src/services/agent-volumes/system-mounts.ts | Extracts read-only system mounts and chroot workspace/tmp mounts. |
| src/services/agent-volumes/ssl-mounts.ts | Extracts optional SSL CA certificate mount. |
| src/services/agent-volumes/hosts-file.ts | Extracts chroot /etc/hosts generation/mount with pre-resolution and host access support. |
| src/services/agent-volumes/home-strategy.ts | Extracts empty chroot-home mount + selective tool/state directory mounts. |
| src/services/agent-volumes/etc-mounts.ts | Extracts minimal /etc mounts needed in chroot. |
| src/services/agent-volumes/docker-socket.ts | Extracts Docker socket exposure/hiding logic and DOCKER_HOST unix socket parsing. |
| src/services/agent-volumes/credential-hiding.ts | Extracts credential file /dev/null overlays for both $HOME and /host$HOME. |
| src/services/agent-volumes/credential-hiding.test.ts | Adds direct unit coverage for credential overlay list generation. |
| src/services/agent-volumes.ts | Re-exports buildAgentVolumes from the new orchestrator for compatibility. |
| src/services/agent-service.ts | Updates the backwards-compatibility re-export to point at the new orchestrator. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 12/12 changed files
- Comments generated: 1
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
@copilot merge main |
✅ Coverage Check PassedOverall Coverage
📁 Per-file Coverage Changes (2 files)
✨ New Files (9 files)
Coverage comparison generated by |
Merged |
Smoke Test ResultsGitHub MCP: ✅ Retrieved PR #3636 "Refactor agent environment assembly into focused modules" Status: PARTIAL — MCP connectivity confirmed cc
|
|
✅ Smoke test validation passed
Result: PASS
|
Smoke Test Results (BYOK Offline Mode)Running in BYOK offline mode (
Status: FAIL (file test failed) PR Author:
|
Smoke Test: FAIL✅ Refactor agent environment assembly into focused modules Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "registry.npmjs.org"See Network Configuration for more information.
|
Smoke Test: Services Connectivity❌ Redis - Connection timeout (host.docker.internal:6379) Result: FAIL - No service connections succeeded
|
Chroot Version Comparison ResultsThe chroot environment runtime versions were compared against the host:
Overall Result: ❌ Not all runtimes match Analysis
The mismatches are expected since the chroot uses Ubuntu 22.04 base packages while the host may have newer versions installed.
|
|
Smoke test result: FAIL. Connectivity and MCP test failed. Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "localhost"See Network Configuration for more information.
|
🏗️ Build Test Suite ResultsAll 18 projects across 8 ecosystems passed successfully!
Overall: 8/8 ecosystems passed — ✅ PASS Summary by Ecosystem:
|
buildAgentVolumes()insrc/services/agent-volumes.tshad grown into a single ~400-line security-critical function spanning system mounts, hosts generation, credential masking, DinD socket handling, and workspace/home policy. This PR decomposes that path into focused modules while preserving the existing external API and behavior.Modular volume architecture
src/services/agent-volumes/volume-builder.tsas the orchestrator forbuildAgentVolumes.system-mounts.tshome-strategy.tsetc-mounts.tshosts-file.tscredential-hiding.tsdocker-socket.tsssl-mounts.tsworkspace-mounts.tsAPI compatibility and caller update
src/services/agent-volumes.tsinto a re-export of the new orchestrator.src/services/agent-service.tsre-export to./agent-volumes/volume-builder.Security-sensitive logic isolation
Focused test coverage for extracted logic
src/services/agent-volumes/credential-hiding.test.tsto validate home and/hostcredential overlay generation remains intact.