[Test Coverage] Improve config-writer.ts branch coverage with edge case tests#3739
Conversation
Add comprehensive edge case tests for config-writer.ts to improve branch coverage from 69.09% to target >85%: - ensureDirectory error handling (non-directory path) - Chroot home directory creation paths (new vs existing) - Home subdirectory creation (.copilot, .cache, etc.) - Conditional .gemini directory creation based on geminiApiKey - Audit directory creation when missing - URL pattern parsing when allowedUrls is provided - API proxy configuration conditional inclusion - Multiple path validation scenarios These tests focus on security-critical configuration paths including: - Directory permission and ownership setup - Conditional feature enablement (API proxy, URL filtering) - File system edge cases that could affect container security All tests use mocked dependencies (fs, ssl-bump, squid-config) for fast, deterministic execution without Docker requirements. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
This PR expands src/config-writer.test.ts to increase branch coverage in writeConfigs() by adding tests for security-relevant edge cases (directory validation, chroot/home directory lifecycle, conditional feature configuration, and audit artifact creation).
Changes:
- Added tests for directory setup edge cases, including non-directory
workDirand chroot home directory creation/reuse paths. - Added tests for conditional home subdirectory creation (including
.gemini) and audit artifact output. - Added tests for
allowedUrlsparsing behavior and conditional API proxy configuration in generated Squid/policy inputs.
Show a summary per file
| File | Description |
|---|---|
src/config-writer.test.ts |
Adds multiple new unit tests to cover previously-uncovered branches in writeConfigs() (directory validation, chroot/home lifecycle, URL patterns, API proxy config, audit outputs, seccomp error path). |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 2
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>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Smoke Test Results ✅ PASS
Overall: PASS — Claude engine validation complete.
|
Smoke Test Results ✅Author:
Overall Status: PASS
|
Copilot BYOK Smoke Test ResultsMode: BYOK offline (COPILOT_OFFLINE=true) via api-proxy → api.githubcopilot.com
Overall: PARTIAL PASS (3/4 verifiable tests passed) PR #3739 Details:
|
Smoke Test Codex✅ Merged PRs reviewed: Reduce Documentation Maintainer workflow prompt/tool overhead; refactor(api-proxy): extract nested callbacks from proxyRequest into focused module-level functions 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.
|
Services Connectivity Test Results❌ Redis: Connection timeout Overall: FAIL — Cannot reach GitHub Actions services at host.docker.internal
|
|
Smoke Test Result: FAIL 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.
|
Chroot Runtime Version Test ResultsComparison between host and chroot environments:
Overall Result: ❌ Tests did not pass The chroot environment has different versions of Python and Node.js compared to the host. Only Go versions match. This indicates that the chroot selective bind mount strategy does not fully inherit the host runtime versions.
|
🏗️ Build Test Suite Results
Overall: 8/8 ecosystems passed — ✅ PASS All build and test operations completed successfully across all ecosystems.
|
Summary
This PR improves test coverage for
src/config-writer.ts, focusing on security-critical edge cases and branch coverage. The module currently has 85.48% line coverage but only 69.09% branch coverage — this PR specifically targets the uncovered branches.Coverage Improvements
Before
Target After
Tests Added
1. Directory Validation Edge Cases (Security-Critical)
This tests the security check that prevents using a file as a directory, which could bypass permission checks.
2. Chroot Home Directory Lifecycle
Tests both paths in the
if (!fs.existsSync(emptyHomeDir))condition (lines 171-173).3. Home Subdirectory Creation (Credential Isolation)
Ensures whitelisted home directories are created with correct ownership before Docker bind-mounts them.
4. Conditional Feature Enablement
Tests both branches of the ternary operator in line 181.
5. URL Pattern Parsing
Tests SSL Bump URL filtering configuration paths.
6. API Proxy Configuration
Tests the conditional spread operator that adds
apiProxyIpandapiProxyPortsto Squid config.7. Audit Directory Creation
Tests directory creation for post-run forensics (squid.conf, policy-manifest.json).
Security Focus
These tests specifically cover:
Testing Approach
Validation
Due to security restrictions in the agentic workflow environment, tests cannot be executed during PR creation. However, the tests:
config-writer.test.tsWhat's Not Covered (Intentional)
The one test case I did NOT add is for the embedded seccomp profile path (line 209-211) because:
__AWF_SECCOMP_PROFILE__)Files Changed
src/config-writer.test.ts- Added 11 new test cases (193 → 492 lines, +299 lines)Next Steps
After this PR, remaining coverage gaps are in:
cli.ts- 0% coverage (entry point, command-line parsing)