Skip to content

[Test Coverage] Improve host-iptables-shared branch coverage#3403

Merged
lpcox merged 2 commits into
mainfrom
test/host-iptables-shared-coverage-e5be9158ce969d5c
May 19, 2026
Merged

[Test Coverage] Improve host-iptables-shared branch coverage#3403
lpcox merged 2 commits into
mainfrom
test/host-iptables-shared-coverage-e5be9158ce969d5c

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

Summary

Extends src/host-iptables-shared.test.ts to cover previously untested branches in host-iptables-shared.ts, the security-critical module responsible for iptables rule management.

Coverage Improvements

Before: host-iptables.ts had 83.63% statement coverage and only 55.55% branch coverage.

The following uncovered branches are now tested:

Function Branches Added
cleanupChain matchPredicate option path (custom line selector)
getNetworkBridgeName Empty stdout → null; docker error → null
getDockerBridgeGateway Empty stdout → null; invalid IPv4 format → null; docker error → null
isIp6tablesAvailable Cache hit path (second call skips syscall)
disableIpv6ViaSysctl Success path; sysctl failure → does not throw
enableIpv6ViaSysctl Early return when IPv6 not disabled; re-enable after disable; sysctl failure → does not throw
addDnsRules Rollback of UDP rule when TCP rule fails; re-throws original error even when rollback fails

Security-Critical Paths Covered

  • DNS rule rollback atomicity: addDnsRules must rollback any successfully-added rules if a later add fails, preventing inconsistent firewall state.
  • IPv6 bypass prevention: disableIpv6ViaSysctl / enableIpv6ViaSysctl lifecycle is now fully exercised, ensuring IPv6 can't be used as an unfiltered bypass path.
  • Gateway validation: getDockerBridgeGateway invalid-IP branch prevents unvalidated strings from being injected into iptables rules.
  • Cache correctness: isIp6tablesAvailable cache ensures consistent behavior throughout a single run.

Test Notes

All tests follow existing patterns (mocked execa, jest.clearAllMocks() in beforeEach, testHelpers.resetIpv6State() to reset module-level state). No Docker, iptables, or network access required.

Generated by Test Coverage Improver · ● 23.1M ·

Add tests for uncovered branches in host-iptables-shared.ts:
- cleanupChain: matchPredicate option
- getNetworkBridgeName: empty output and error paths
- getDockerBridgeGateway: empty output, invalid IPv4 format, error paths
- isIp6tablesAvailable: cache hit path
- disableIpv6ViaSysctl: success and failure paths
- enableIpv6ViaSysctl: no-op when not disabled, re-enable path, failure path
- addDnsRules: rollback when TCP rule fails, re-throws original error

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@lpcox lpcox marked this pull request as ready for review May 19, 2026 14:21
Copilot AI review requested due to automatic review settings May 19, 2026 14:21
@github-actions
Copy link
Copy Markdown
Contributor Author

github-actions Bot commented May 19, 2026

✅ Coverage Check Passed

Overall Coverage

Metric Base PR Delta
Lines 95.40% 95.64% 📈 +0.24%
Statements 95.22% 95.48% 📈 +0.26%
Functions 96.55% 96.55% ➡️ +0.00%
Branches 87.87% 87.95% 📈 +0.08%
📁 Per-file Coverage Changes (2 files)
File Lines (Before → After) Statements (Before → After)
src/config-writer.ts 83.0% → 85.6% (+2.54%) 83.0% → 85.6% (+2.54%)
src/host-iptables-shared.ts 91.7% → 100.0% (+8.34%) 90.6% → 100.0% (+9.42%)

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

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 extends the unit test suite for src/host-iptables-shared.ts to improve branch coverage for security-sensitive iptables and IPv6/sysctl behaviors, without requiring Docker/iptables access at test time.

Changes:

  • Added tests for previously uncovered branches in cleanupChain, getNetworkBridgeName, and getDockerBridgeGateway.
  • Added caching-path coverage for isIp6tablesAvailable.
  • Added success/failure-path coverage for IPv6 sysctl toggling (disableIpv6ViaSysctl / enableIpv6ViaSysctl) and DNS rule rollback behavior (addDnsRules).
Show a summary per file
File Description
src/host-iptables-shared.test.ts Adds targeted unit tests to exercise untested branches in host-iptables-shared (bridge discovery, gateway validation, IPv6 handling, and DNS rule rollback).

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

Comment on lines +113 to +119
it('returns null and warns when gateway is not a valid IPv4 address', async () => {
mockedExeca.mockResolvedValueOnce(execaResult({ stdout: 'not-an-ip' }));

const result = await getDockerBridgeGateway();

expect(result).toBeNull();
});
Comment thread src/host-iptables-shared.test.ts Outdated
Comment on lines 13 to 17
describe('host-iptables-shared', () => {
beforeEach(() => {
jest.clearAllMocks();
testHelpers.resetIpv6State();
});
@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 github-actions Bot mentioned this pull request May 19, 2026
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@lpcox
Copy link
Copy Markdown
Collaborator

lpcox commented May 19, 2026

@copilot address review feedback

Copy link
Copy Markdown
Contributor

Copilot AI commented May 19, 2026

@copilot address review feedback

Addressed in 592e356.

  • Switched this suite to use setupHostIptablesTestSuite(testHelpers.resetIpv6State) for consistent shared setup.
  • Updated the invalid gateway test to assert logger.warn is called, matching the test name/behavior.

Copilot AI requested a review from lpcox May 19, 2026 14:38
@github-actions
Copy link
Copy Markdown
Contributor Author

Smoke Test Results

GitHub API: recent-prs.json contains 2 PR entries
Playwright: GitHub.com page title contains "GitHub"
File verify: smoke-test-claude-26104435630.txt exists

Result: PASS — All tests passed

💥 [THE END] — Illustrated by Smoke Claude

@github-actions
Copy link
Copy Markdown
Contributor Author

🔥 Smoke Test: Copilot BYOK (Offline) Mode

Test Result
1. GitHub MCP (list PRs) ✅ PR #3396 fetched successfully
2. GitHub.com connectivity ⚠️ Pre-step output not resolved (template unexpanded)
3. File write/read ⚠️ Pre-step output not resolved (template unexpanded)
4. BYOK inference (this response) ✅ Agent responded via api-proxy → api.githubcopilot.com

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

Overall: PARTIAL — BYOK inference ✅, pre-step data not substituted ⚠️

PR author: @github-actions[bot] · Reviewer: @lpcox

🔑 BYOK report filed by Smoke Copilot BYOK

@github-actions
Copy link
Copy Markdown
Contributor Author

Gemini Smoke Test Results

  1. Internalize DOMAIN_CHAR_PATTERN and decouple tests from non-API regex internals
  2. Privatize ruleset internals and test rules parsing through public API
  • GitHub MCP Testing: ✅
  • GitHub.com Connectivity: ✅
  • File Writing Testing: ✅
  • Bash Tool Testing: ✅

Overall Status: PASS

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

@github-actions
Copy link
Copy Markdown
Contributor Author

🔬 Smoke Test Results

Test Result
GitHub MCP connectivity ✅ PR listed successfully
GitHub.com HTTP ✅ 200 OK
File write/read ⚠️ Template vars unexpanded (skipped)

PR: [Test Coverage] Improve host-iptables-shared branch coverage
Author: @github-actions[bot] · Assignees: none

Overall: PASS (2/2 verifiable tests passed)

📰 BREAKING: Report filed by Smoke Copilot

@github-actions
Copy link
Copy Markdown
Contributor Author

Smoke test Codex: FAIL
✅ Last merged PRs: Internalize DOMAIN_CHAR_PATTERN and decouple tests from non-API regex internals; Privatize ruleset internals and test rules parsing through public API
❌ safeinputs-gh PR query: tool unavailable
✅ Playwright: GitHub title verified
❌ Tavily search: no search tool exposed
✅ File write/read: smoke-test-codex-26104435634.txt
⚠️ Discussion: query tool unavailable; skipped
✅ Build: npm ci && npm run 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 Author

Chroot Smoke Test Results

Runtime Host Version Chroot Version Match?
Python Python 3.12.13 Python 3.12.3 ❌ NO
Node.js v24.15.0 v20.20.2 ❌ NO
Go go1.22.12 go1.22.12 ✅ YES

Result: ❌ Not all tests passed — Python patch version and Node.js minor version differ between host and chroot environments.

Tested by Smoke Chroot

@github-actions
Copy link
Copy Markdown
Contributor Author

Smoke Test: GitHub Actions Services Connectivity

Check Result
Redis PING ❌ Timeout/no response
PostgreSQL pg_isready ❌ No response on port 5432
PostgreSQL SELECT 1 ❌ Not attempted (pg_isready failed)

Overall: FAILhost.docker.internal is not reachable from this environment. Service containers are unavailable.

🔌 Service connectivity validated by Smoke Services

@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

Generated by Build Test Suite for issue #3403 · ● 3.7M ·

Copilot finished work on behalf of lpcox May 19, 2026 14:57
@lpcox lpcox merged commit 01e4eab into main May 19, 2026
65 of 68 checks passed
@lpcox lpcox deleted the test/host-iptables-shared-coverage-e5be9158ce969d5c branch May 19, 2026 15:11
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