Skip to content

[Test Coverage] container-lifecycle.ts#6396

Merged
lpcox merged 2 commits into
mainfrom
test-coverage/container-lifecycle-701bc99068b97540
Jul 19, 2026
Merged

[Test Coverage] container-lifecycle.ts#6396
lpcox merged 2 commits into
mainfrom
test-coverage/container-lifecycle-701bc99068b97540

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Summary

Adds 20 unit tests for src/container-lifecycle.ts, a security-critical file with <20% coverage that manages Docker container lifecycle for the AWF firewall.

Coverage added

startContainers

  • Success path and --pull never flag
  • Delegation to handleHealthcheckError when no specific container failed
  • Retry logic for transient awf-api-proxy and awf-squid startup failures
  • Non-retriable awf-cli-proxy failure with specific error message
  • DNS resolution failure detail in cli-proxy error
  • Topology mode onNetworkReady callback invocation
  • Repeated failure on retry (api-proxy and cli-proxy)

runAgentCommand

  • Exit codes 0 and non-zero propagation
  • Blocked domain warning on non-zero exit
  • Exit code 143 when agent externally killed
  • Exit code 124 on timeout with container stop
  • Error propagation from docker wait

fastKillAgentContainer

  • Marks agent as killed and sends stop command
  • Custom timeout parameter
  • Error tolerance (no throw when docker unavailable)

Approach

All tests use jest.mock() for execa, Docker, and dependency modules — no real Docker or iptables calls.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • awmgmcpg

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

Generated by Test Coverage Improver · 107.1 AIC · ⊞ 5.5K ·

Covers startContainers, runAgentCommand, and fastKillAgentContainer:
- Success paths and error delegation to handleHealthcheckError
- Retry logic for api-proxy and squid transient startup failures
- cli-proxy failure error with DNS detail
- Topology mode onNetworkReady callback
- Timeout exit code (124) and external kill (143)
- Blocked domain reporting
- fastKillAgentContainer custom timeout and error tolerance

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@lpcox
lpcox marked this pull request as ready for review July 19, 2026 16:30
Copilot AI review requested due to automatic review settings July 19, 2026 16:30
@github-actions

Copy link
Copy Markdown
Contributor Author

✅ Coverage Check Passed

Overall Coverage

Metric Base PR Delta
Lines 98.43% 98.48% 📈 +0.05%
Statements 98.27% 98.31% 📈 +0.04%
Functions 99.16% 99.16% ➡️ +0.00%
Branches 94.22% 94.25% 📈 +0.03%
📁 Per-file Coverage Changes (2 files)
File Lines (Before → After) Statements (Before → After)
src/container-lifecycle.ts 99.1% → 100.0% (+0.87%) 99.2% → 100.0% (+0.83%)
src/log-directory-setup.ts 96.2% → 100.0% (+3.78%) 96.3% → 100.0% (+3.71%)

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

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

Adds mocked unit coverage for Docker container lifecycle behavior.

Changes:

  • Tests startup, retry, timeout, exit-code, and fast-kill paths.
  • Adds coverage for cli-proxy DNS diagnostics.
Show a summary per file
File Description
src/container-lifecycle.test.ts Adds lifecycle unit tests with mocked dependencies.

Review details

Tip

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

  • Files reviewed: 1/1 changed files
  • Comments generated: 4
  • Review effort level: Medium

Comment thread src/container-lifecycle.test.ts Outdated
Comment on lines +2 to +5
* Unit tests for container-lifecycle.ts
*
* Covers: startContainers, runAgentCommand, fastKillAgentContainer
* Uses jest.mock() for all Docker/execa/fs dependencies.
Comment thread src/container-lifecycle.test.ts Outdated
Comment on lines +253 to +255
const result = await runAgentCommand(WORK_DIR, ['github.com']);
expect(result.exitCode).toBe(1);
expect(result.blockedDomains).toEqual(['evil.com']);
Comment thread src/container-lifecycle.test.ts Outdated
Comment on lines +285 to +291
jest.useFakeTimers();
const resultPromise = runAgentCommand(WORK_DIR, [], undefined, 0.001);
await jest.runAllTimersAsync();
const result = await resultPromise;
jest.useRealTimers();

expect(result.exitCode).toBe(124);
Comment thread src/container-lifecycle.test.ts Outdated
Comment on lines +70 to +85
import { isAgentExternallyKilled, markAgentExternallyKilled, containerLifecycleStateTestHelpers } from './container-lifecycle-state';

const mockDidContainerFailStartup = didContainerFailStartup as jest.MockedFunction<typeof didContainerFailStartup>;
const mockHandleHealthcheckError = handleHealthcheckError as jest.MockedFunction<typeof handleHealthcheckError>;
const mockLogContainerLogsToStderr = logContainerLogsToStderr as jest.MockedFunction<typeof logContainerLogsToStderr>;
const mockDetectDnsResolutionFailure = detectDnsResolutionFailure as jest.MockedFunction<typeof detectDnsResolutionFailure>;
const mockCheckSquidLogs = checkSquidLogs as jest.MockedFunction<typeof checkSquidLogs>;
const mockRunComposeDown = runComposeDown as jest.MockedFunction<typeof runComposeDown>;
const mockIsAgentExternallyKilled = isAgentExternallyKilled as jest.MockedFunction<typeof isAgentExternallyKilled>;
const mockMarkAgentExternallyKilled = markAgentExternallyKilled as jest.MockedFunction<typeof markAgentExternallyKilled>;

const WORK_DIR = '/tmp/awf-test';

beforeEach(() => {
jest.resetAllMocks();
containerLifecycleStateTestHelpers.resetAgentExternallyKilled();
@lpcox

lpcox commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator

@copilot address review feedback

Copilot AI commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

@copilot address review feedback

Addressed in d0b3086.

  • Removed duplicate broad suite src/container-lifecycle.test.ts to avoid overlap/drift with focused suites.
  • Kept coverage in existing focused files (src/container-start.test.ts, src/run-agent-command.test.ts, src/container-stop.test.ts).
  • Added the CLI-proxy DNS-detail branch test in src/container-start.test.ts (EAI_AGAIN host surfaced in error).
  • Verified with: npm test -- --runInBand src/container-start.test.ts src/run-agent-command.test.ts src/container-stop.test.ts.

@lpcox
lpcox enabled auto-merge (squash) July 19, 2026 17:11
@github-actions

github-actions Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

Smoke Gemini completed. All facets verified. 💎

Smoke test completed with FAIL status due to connectivity issues.

@github-actions

github-actions Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

🔌 Smoke Services — All services reachable! ✅

@github-actions

github-actions Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

📡 Smoke OTel Tracing completed. All tracing scenarios validated. ✅

@github-actions

github-actions Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

Chroot tests passed! Smoke Chroot - All security and functionality tests succeeded.

@github-actions

github-actions Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

✨ The prophecy is fulfilled... Smoke Codex has completed its mystical journey. The stars align. 🌟

Copilot finished work on behalf of lpcox July 19, 2026 17:11
@github-actions

github-actions Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

📰 VERDICT: Smoke Docker Sbx has concluded. All systems operational. This is a developing story. 🎤

@github-actions

github-actions Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

Smoke Copilot BYOK AOAI (api-key) completed. Copilot AOAI BYOK (api-key) mode operational. 🔓

Copilot AI requested a review from lpcox July 19, 2026 17:11
@github-actions

Copy link
Copy Markdown
Contributor Author

🚀 Security Guard has started processing this pull request

@github-actions

github-actions Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

Smoke Copilot BYOK completed. Copilot BYOK mode operational. 🔓

@github-actions

github-actions Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

Contribution Check completed successfully!

PR #6396 meets the applicable CONTRIBUTING.md guidelines; no comment needed.

@github-actions

github-actions Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

🛡️ Smoke Copilot Network Isolation confirmed the egress allowlist is enforced. ✅

@github-actions

github-actions Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

🔑 Smoke Copilot PAT PAT auth validated. All systems operational. ✅

@github-actions

github-actions Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

📰 VERDICT: Smoke Copilot has concluded. All systems operational. This is a developing story. 🎤

@github-actions

github-actions Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

Build Test Suite completed successfully!

@github-actions

github-actions Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

Smoke Claude passed

@github-actions

github-actions Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

Smoke Copilot BYOK AOAI (Entra) completed. Copilot AOAI BYOK (Entra) mode operational. 🔓

@github-actions

Copy link
Copy Markdown
Contributor Author

🔬 Smoke Test Results

Test Status
GitHub MCP connectivity
GitHub.com HTTP ⚠️ pre-step data unavailable
File write/read ⚠️ pre-step data unavailable

Overall: PASS (MCP reachable; pre-step template vars not expanded into prompt)

cc @lpcox

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • awmgmcpg

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

📰 BREAKING: Report filed by Smoke Copilot
Add label ready-for-aw to run again

@github-actions

Copy link
Copy Markdown
Contributor Author

Smoke test: Copilot network-isolation egress

EGRESS_RESULT allow=pass deny=pass

✅ Test 1 (allowed domain api.github.com): HTTP 200
✅ Test 2 (blocked domain example.com): blocked (403 from proxy)

Overall: PASS@lpcox

Warning

Firewall blocked 2 domains

The following domains were blocked by the firewall during workflow execution:

  • awmgmcpg
  • example.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "awmgmcpg"
    - "example.com"

See Network Configuration for more information.

🛡️ Egress verdict from Smoke Copilot Network Isolation
Add label ready-for-aw to run again

@github-actions

Copy link
Copy Markdown
Contributor Author

Smoke Test Results

Overall status: FAIL

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • localhost

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "localhost"

See Network Configuration for more information.

💎 Faceted by Smoke Gemini
Add label ready-for-aw to run again

@github-actions github-actions Bot added smoke-copilot-network-isolation Copilot network-isolation egress smoke test smoke-copilot-byok labels Jul 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor Author

Smoke Test: Copilot BYOK (Direct Mode) ✅ PASS

  • ✅ GitHub MCP connectivity
  • ✅ GitHub.com HTTP 200
  • ✅ File write/read test
  • ✅ BYOK inference (agent → api-proxy → api.githubcopilot.com)

Running in direct BYOK mode via COPILOT_PROVIDER_API_KEY with api-proxy sidecar injection.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • awmgmcpg

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

🔑 BYOK report filed by Smoke Copilot BYOK
Add label ready-for-aw to run again

@github-actions github-actions Bot mentioned this pull request Jul 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor Author

Smoke Test: Copilot PAT Auth

Test Result
GitHub MCP connectivity
GitHub.com HTTP ✅ (pre-step)
File write/read ⚠️ (template vars unexpanded in workflow)

Overall: PASS
Auth mode: PAT (COPILOT_GITHUB_TOKEN)
Author: @lpcox

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • awmgmcpg

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

🔑 PAT report filed by Smoke Copilot PAT
Add label ready-for-aw to run again

@github-actions

Copy link
Copy Markdown
Contributor Author

Smoke Test: Claude Engine Validation

Check Result
API Status ✅ PASS
GH Check ✅ PASS
File Status ✅ PASS

Overall Result: PASS

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • awmgmcpg

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

Generated by Smoke Claude for #6396 · 35.1 AIC · ⊞ 3.3K ·
Add label ready-for-aw to run again

@github-actions

Copy link
Copy Markdown
Contributor Author

Smoke Test Results

  • Redis PING: ❌ (host.docker.internal DNS fails; bridge IP unreachable)
  • PostgreSQL pg_isready: ❌ (no response)
  • PostgreSQL SELECT 1: ❌ (connection failed)

Overall: FAIL — service containers not reachable from this runner environment.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • awmgmcpg

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

🔌 Service connectivity validated by Smoke Services
Add label ready-for-aw to run again

@github-actions

Copy link
Copy Markdown
Contributor Author

Chroot Version Comparison

Runtime Host Version Chroot Version Match?
Python Python 3.12.13 Python 3.12.3
Node.js v24.18.0 v22.23.1
Go go1.22.12 go1.22.12

Go versions match; Python and Node.js versions differ between host and chroot.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • awmgmcpg

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

Tested by Smoke Chroot
Add label ready-for-aw to run again

@github-actions

Copy link
Copy Markdown
Contributor Author

Smoke test results:

  • chore: upgrade gh-aw to v0.82.13 (pre-release) and recompile workflows ✅
  • refactor: centralize network policy into sandbox-network-policy.json ✅
  • GitHub title check ✅
  • File write/cat ✅
  • Discussion comment ✅
  • npm ci && npm run build ✅
    Overall: PASS

Warning

Firewall blocked 2 domains

The following domains were blocked by the firewall during workflow execution:

  • awmgmcpg
  • registry.npmjs.org

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "awmgmcpg"
    - "registry.npmjs.org"

See Network Configuration for more information.

🔮 The oracle has spoken through Smoke Codex
Add label ready-for-aw to run again

@github-actions

Copy link
Copy Markdown
Contributor Author

GitHub MCP connectivity: ✅
GitHub.com connectivity: ✅
File write/read test: ✅
BYOK inference test: ✅

Running in direct BYOK mode (AWF_AUTH_TYPE=github-oidc + AWF_AUTH_AZURE_* + COPILOT_PROVIDER_BASE_URL) via api-proxy → Azure OpenAI (Foundry, o4-mini-aw) authenticated via Microsoft Entra

@lpcox Overall: PASS

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • awmgmcpg

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

🪪 BYOK (AOAI Entra) report filed by Smoke Copilot BYOK AOAI (Entra)
Add label ready-for-aw to run again

@github-actions

Copy link
Copy Markdown
Contributor Author

OTEL Smoke Test Results

Scenario Result
Scenario 1: Module Loading otel.js loaded successfully; exports: startRequestSpan, setTokenAttributes, setBudgetAttributes, endSpan, endSpanError, shutdown, isEnabled, plus test-only internals
Scenario 2: Test Suite ✅ OTEL tests exist — otel.test.js has 39 test() cases across 12 describe() blocks covering module init, exports, span creation, token attributes, and parent context propagation
Scenario 3: Env Var Forwarding src/services/api-proxy-env-config.ts forwards GH_AW_OTLP_ENDPOINTS, OTEL_* vars, GITHUB_AW_OTEL_TRACE_ID, and GITHUB_AW_OTEL_PARENT_SPAN_ID to the api-proxy container
Scenario 4: Token Tracker Integration onUsage callback exists in token-tracker-http.js (line 285); invoked after normalized usage extraction — confirmed OTEL hook point
Scenario 5: OTEL Diagnostics ⚠️ No live container run in this workflow — graceful degradation confirmed: when no OTLP endpoint is configured, spans fall back to /var/log/api-proxy/otel.jsonl

Overall: ✅ All implemented scenarios pass; no unexpected failures.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • awmgmcpg

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

📡 OTel tracing validated by Smoke OTel Tracing
Add label ready-for-aw to run again

@github-actions

Copy link
Copy Markdown
Contributor Author

🏗️ 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 passed ✅ PASS
Go env passed ✅ PASS
Go uuid passed ✅ PASS
Java gson 1/1 passed ✅ PASS
Java caffeine 1/1 passed ✅ PASS
Node.js clsx passed ✅ PASS
Node.js execa passed ✅ PASS
Node.js p-limit passed ✅ PASS
Rust fd 1/1 passed ✅ PASS
Rust zoxide 1/1 passed ✅ PASS

Overall: 8/8 ecosystems passed — ✅ PASS

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • awmgmcpg

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

Generated by Build Test Suite for #6396 · 34.8 AIC · ⊞ 7.1K ·
Add label ready-for-aw to run again

@github-actions

Copy link
Copy Markdown
Contributor Author

@lpcox Smoke Test Results:

  • GitHub MCP connectivity: ✅
  • GitHub.com connectivity: ✅
  • File write/read: ✅
  • BYOK inference: ✅
    Running in direct BYOK mode (COPILOT_PROVIDER_API_KEY + COPILOT_PROVIDER_BASE_URL) via api-proxy → Azure OpenAI (Foundry, o4-mini-aw)
    PASS

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • awmgmcpg

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

🔑 BYOK (AOAI api-key) report filed by Smoke Copilot BYOK AOAI (api-key)
Add label ready-for-aw to run again

@github-actions

Copy link
Copy Markdown
Contributor Author

🔥 Smoke Test Results

Test Status
GitHub MCP connectivity ✅ Connected (data filtered by policy)
GitHub.com HTTP ⚠️ Pre-step data unavailable (template vars not expanded)
File write/read ⚠️ Pre-step data unavailable (template vars not expanded)

Overall: ⚠️ PARTIAL — MCP reachable; pre-computed smoke data was not injected into the prompt (template substitution did not occur).

cc @lpcox

📰 BREAKING: Report filed by Smoke Docker Sbx
Add label ready-for-aw to run again

@lpcox
lpcox merged commit db44ecd into main Jul 19, 2026
141 of 142 checks passed
@lpcox
lpcox deleted the test-coverage/container-lifecycle-701bc99068b97540 branch July 19, 2026 17:24
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.

3 participants