Split docker-manager-compose.test.ts (3,525 lines) by service area#2560
Split docker-manager-compose.test.ts (3,525 lines) by service area#2560
Conversation
Split the 3525-line test file into 6 focused files: - src/compose-generator.test.ts: general image/network/digest tests (234 lines) - src/services/squid-service.test.ts: squid container config tests - src/services/agent-service.test.ts: agent container tests (all agent, envFile, enableHostAccess, NO_PROXY, allowHostPorts, containerWorkDir, proxyLogsDir, dnsServers, tmpfs, toolchain fallback, GITHUB_PATH) - src/services/api-proxy-service.test.ts: API proxy sidecar tests - src/services/doh-proxy-service.test.ts: DoH proxy sidecar tests - src/services/cli-proxy-service.test.ts: CLI proxy sidecar tests All 268 tests preserved. Zero lint errors introduced. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
✅ Coverage Check PassedOverall Coverage
📁 Per-file Coverage Changes (1 files)
Coverage comparison generated by |
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.
There was a problem hiding this comment.
Pull request overview
This PR refactors the Docker Compose generation test suite by deleting the former monolithic src/docker-manager-compose.test.ts and replacing it with multiple focused test files organized by service area, aiming to improve readability and make the suite easier to navigate and parallelize.
Changes:
- Split Docker Compose generation tests into six service-scoped test files (agent, squid, api-proxy, DoH proxy, CLI proxy, and general compose generation).
- Preserved the existing assertions/coverage while re-homing them into smaller, easier-to-maintain suites.
- Duplicated local mocks (
execa, configs) per file to keep each suite self-contained.
Show a summary per file
| File | Description |
|---|---|
| src/compose-generator.test.ts | Focused tests for compose generation defaults, image selection, digests, and network config. |
| src/services/squid-service.test.ts | Validates Squid service container configuration and squid.conf base64 injection behavior. |
| src/services/agent-service.test.ts | Large agent-focused suite covering mounts, env propagation, chroot/hosts pre-resolution, tmpfs overlays, etc. |
| src/services/api-proxy-service.test.ts | Validates api-proxy sidecar inclusion, env forwarding/isolation, limits, and agent wiring. |
| src/services/doh-proxy-service.test.ts | Validates DoH sidecar inclusion, healthcheck, limits, and agent DNS/env behavior. |
| src/services/cli-proxy-service.test.ts | Validates CLI proxy sidecar behavior (DIFC proxy host parsing, env, depends_on, hardening). |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comments suppressed due to low confidence (4)
src/services/agent-service.test.ts:180
- This test mutates
process.env.COPILOT_GITHUB_TOKENbut the cleanup happens after assertions, so a failure will leak the env var into later tests. Wrap the mutation intry/finallyand restore the previous value (or delete) infinally.
it('should forward COPILOT_GITHUB_TOKEN when api-proxy is disabled', () => {
process.env.COPILOT_GITHUB_TOKEN = 'ghp_test_token';
const configNoProxy = { ...mockConfig, enableApiProxy: false };
const result = generateDockerCompose(configNoProxy, mockNetworkConfig);
const env = result.services.agent.environment as Record<string, string>;
src/services/agent-service.test.ts:189
- This test sets
process.env.COPILOT_API_KEYand deletes it at the end of the test body. If an assertion throws, cleanup won’t run and later tests may be affected. Usetry/finallyto restore the prior value.
it('should forward COPILOT_API_KEY when api-proxy is disabled', () => {
process.env.COPILOT_API_KEY = 'cpat_test_byok_key';
const configNoProxy = { ...mockConfig, enableApiProxy: false };
const result = generateDockerCompose(configNoProxy, mockNetworkConfig);
const env = result.services.agent.environment as Record<string, string>;
src/services/agent-service.test.ts:209
- Same env-leak risk here:
process.env.AWF_ONE_SHOT_TOKEN_DEBUGis mutated and only deleted after assertions. Usetry/finally(restore previous value) so failures don’t pollute subsequent tests.
it('should forward AWF_ONE_SHOT_TOKEN_DEBUG when set', () => {
process.env.AWF_ONE_SHOT_TOKEN_DEBUG = '1';
const result = generateDockerCompose(mockConfig, mockNetworkConfig);
const env = result.services.agent.environment as Record<string, string>;
expect(env.AWF_ONE_SHOT_TOKEN_DEBUG).toBe('1');
src/services/agent-service.test.ts:701
- This test claims to verify that domains already present in
/etc/hostsaren’t duplicated, but it only checkslocalhostMatchesis defined (which will almost always be true). Add an assertion thatmockExecaSyncwas not called forgetent hosts localhost, or assert the hosts file did not gain an extra localhost entry.
// Count occurrences of 'localhost' - should only be the original entries, not duplicated
const localhostMatches = content.match(/localhost/g);
// /etc/hosts typically has multiple localhost entries (127.0.0.1 and ::1)
// The key assertion is that getent should NOT have been called for localhost
// since it's already in the hosts file
- Files reviewed: 6/7 changed files
- Comments generated: 6
| allowedDomains: ['github.com', 'npmjs.org'], | ||
| agentCommand: 'echo "test"', | ||
| logLevel: 'info', | ||
| keepContainers: false, | ||
| workDir: '/tmp/awf-test', |
| allowedDomains: ['github.com', 'npmjs.org'], | ||
| agentCommand: 'echo "test"', | ||
| logLevel: 'info', | ||
| keepContainers: false, | ||
| workDir: '/tmp/awf-test', |
| allowedDomains: ['github.com', 'npmjs.org'], | ||
| agentCommand: 'echo "test"', | ||
| logLevel: 'info', | ||
| keepContainers: false, | ||
| workDir: '/tmp/awf-test', |
| allowedDomains: ['github.com', 'npmjs.org'], | ||
| agentCommand: 'echo "test"', | ||
| logLevel: 'info', | ||
| keepContainers: false, | ||
| workDir: '/tmp/awf-test', |
| allowedDomains: ['github.com', 'npmjs.org'], | ||
| agentCommand: 'echo "test"', | ||
| logLevel: 'info', | ||
| keepContainers: false, | ||
| workDir: '/tmp/awf-test', |
| allowedDomains: ['github.com', 'npmjs.org'], | ||
| agentCommand: 'echo "test"', | ||
| logLevel: 'info', | ||
| keepContainers: false, | ||
| workDir: '/tmp/awf-test', |
|
@copilot merge main and address the review feedback |
…t-docker-manager-compose-test Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
Done — merged main and fixed all workDir races (commit |
🔥 Smoke Test: Copilot BYOK (Offline) Mode
Running in BYOK offline mode ( PR: "Split docker-manager-compose.test.ts (3,525 lines) by service area" · Author: Overall: PASS ✅
|
🔬 Smoke Test Results
PR: Split docker-manager-compose.test.ts (3,525 lines) by service area Overall: PARTIAL — MCP ✅, pre-step template variables were not expanded so HTTP/file tests could not be verified.
|
Smoke Test SummaryPRs: refactor: extract shared parameterised test factory for log sub-commands; refactor: split cli.test.ts by feature area into co-located test files 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 Results✅ GitHub API: Last 2 merged PRs retrieved Overall Status: PASS
|
Smoke Test Results
Overall: FAIL —
|
🏗️ Build Test Suite Results
Overall: 8/8 ecosystems passed — ✅ PASS
|
Chroot Version Comparison Results
Result: Not all tests passed — Python and Node.js versions differ between host and chroot environments.
|
src/docker-manager-compose.test.tshad grown to 3,525 lines with 10+ distinct service areas crammed into a singledescribeblock, making it the largest file in the repo and difficult to navigate or parallelize in CI.Changes
Deleted the monolithic file and replaced it with six focused test files:
src/compose-generator.test.tssrc/services/squid-service.test.tssrc/services/agent-service.test.tsenvFile,enableHostAccess,allowHostPorts,containerWorkDir,proxyLogsDir,dnsServers, tmpfs overlay, toolchain vars,GITHUB_PATH)src/services/api-proxy-service.test.tsAWF_ANTHROPIC_*forwardingsrc/services/doh-proxy-service.test.tssrc/services/cli-proxy-service.test.tsAll 268 tests are preserved. Each file carries its own execa mock,
mockConfig, andmockNetworkConfig— no shared helper module introduced, keeping each file independently readable.