Skip to content

test(dns-server): raise coverage to ~99% and enforce the 90% gate - #96

Merged
PenguinzTech merged 4 commits into
v2.1.xfrom
chore/enforce-coverage-90
Sep 2, 2026
Merged

test(dns-server): raise coverage to ~99% and enforce the 90% gate#96
PenguinzTech merged 4 commits into
v2.1.xfrom
chore/enforce-coverage-90

Conversation

@PenguinzTech

Copy link
Copy Markdown
Contributor

Summary

Release is gated on the 90% coverage standard. The dns-server coverage check was masked (--cov-fail-under=98 || true) which hid that real coverage was only ~45%, and the coverage step was missing a test-only dependency (responses) so two suites failed collection — meaning the gate would have errored even if unmasked.

Changes

  • 14 new unit-test suites bringing the thin modules to ~99–100% (real behavior + edge/error paths, mocked externals): cert_manager, selective_dns_routing, selective_router, manager_client, resilience, config, main, http3_serving, dns_resolver, cache_manager, prometheus_metrics, metrics_reporter, observability, grpc_server.
  • Fixed a real DoS bug found while testing: prometheus_metrics.py imported prometheus_client.Counter over collections.Counter (name shadow), so the top_domains cap trim always raised (silently swallowed) and the dict was never bounded — the DoS cap added in fix(dns-server): stop JWT leak in /metrics, gate metrics+status, harden DoS #87 was inoperative. Aliased to CollectionsCounter; the cap now actually enforces (regression test included).
  • CI (build.yml, server-release.yml): install requirements-dev.txt in the coverage step (provides responses), remove the || true mask, set --cov-fail-under=90 so the gate is real.

Verification

  • Local lower bound (excluding the 2 responses-dependent suites): 99% (1951 stmts, 25 missing) — CI with responses will be higher. 583 tests pass. flake8 clean on all 15 changed files; workflows valid; gitleaks clean.
  • Coverage measured with the dotted --cov=app form (the --cov=path/to/file.py form silently mismeasures — a pytest-cov quirk).

Note

Another real bug surfaced while testing (not fixed here): cert_manager.verify_client_cert omits the padding arg on the RSA-CA signature check, so it always fails for RSA CAs (behind the mtls flag). Flagged for follow-up.

🤖 Generated with Claude Code

Release is gated on 90% coverage; the dns-server coverage check was masked
(--cov-fail-under=98 || true) and hid that real coverage was ~45%. It was also
missing a test-only dependency (`responses`), so two suites failed collection
and the gate would have errored even if unmasked.

- Added 14 unit-test suites covering the previously-thin modules to ~99-100%:
  cert_manager, selective_dns_routing, selective_router, manager_client,
  resilience, config, main, http3_serving, dns_resolver, cache_manager,
  prometheus_metrics, metrics_reporter, observability, grpc_server. Real
  behavior + edge/error paths, mocked externals.
- Fixed a real DoS bug found while testing: prometheus_metrics.py imported
  `prometheus_client.Counter` over `collections.Counter` (name shadow), so the
  top_domains cap trim always raised (silently swallowed) and the dict was never
  bounded. Aliased to CollectionsCounter; the cap now actually enforces.
- CI (build.yml, server-release.yml): install requirements-dev.txt in the
  coverage step (provides `responses`), remove the `|| true` mask, and set
  --cov-fail-under=90 so the gate is real.

Local lower bound (excluding the 2 responses-dependent suites): 99% (1951 stmts,
25 missing). flake8 clean on all files; workflows valid.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@PenguinzTech PenguinzTech self-assigned this Sep 2, 2026
Comment thread dns-server/tests/test_cert_manager_coverage.py Fixed
Comment thread dns-server/tests/test_selective_router_coverage.py Fixed
Two CI failures on the coverage gate:
- test_manager_client_coverage.py uses the `requests_mock` fixture from the
  requests-mock package, which was installed locally but not declared — CI
  errored with "fixture 'requests_mock' not found". Added requests-mock to
  dns-server/requirements-dev.txt (installed by the coverage step).
- CodeQL raised 2 high false positives (py/incomplete-url-substring-sanitization)
  on membership checks in the new test files (`"host" in dict`, `"name" in list`
  — not URL sanitization). Added .github/codeql/codeql-config.yml with
  paths-ignore for test/vendored code and wired it into codeql.yml init;
  production code is still scanned.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@socket-security

socket-security Bot commented Sep 2, 2026

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedpypi/​psutil@​7.2.294100100100100
Addedpypi/​requests-mock@​1.12.1100100100100100

View full report

PenguinzTech and others added 2 commits September 2, 2026 14:38
CI (stricter env) surfaced 3 test failures on the coverage run:
- cert_manager.create_server_cert used the host FQDN as the X.509 CommonName
  with no length cap; a >64-char hostname (e.g. the CI runner's) raised
  ValueError during cert generation -- a real bug for long-hostname hosts. CN is
  now truncated to 64 chars; the full hostname still goes in the SAN.
- prometheus_metrics system-metrics tests require psutil (an optional guarded
  import in the module); added psutil to requirements-dev.txt so the psutil path
  runs under test.

Coverage gate itself already passed (97.86% >= 90%). All 134 cert/prometheus
tests pass locally; flake8 clean.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The 40 selective-routing coverage tests passed in the pip test env but failed in
CI's Docker-image test run (`docker run ... pytest tests/`) with
TableNotFoundError for dns_group / dns_routing_zone / user_group_assignment /
group_zone_access. Like the token-hash test before it, they relied on conftest
importing the manager schema to create those tables, which silently no-ops when
manager/ isn't checked out alongside (the Docker case).

Added an autouse fixture that creates the four tables directly against db_engine
(checkfirst=True, row-only teardown), mirroring test_selective_dns_routing_
token_hash.py. Also fixed one test that used a token but hadn't declared the
token_table fixture. Verified against a fresh copy with no manager/ sibling
(60 passed, twice); coverage still 100%.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@PenguinzTech
PenguinzTech merged commit 0b684c9 into v2.1.x Sep 2, 2026
16 checks passed
@PenguinzTech
PenguinzTech deleted the chore/enforce-coverage-90 branch September 2, 2026 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants