Skip to content

test: raise coverage 71.7% -> 90.9% with httptest-driven fetchOnce#1

Merged
TeoSlayer merged 1 commit into
mainfrom
add-test-coverage
May 28, 2026
Merged

test: raise coverage 71.7% -> 90.9% with httptest-driven fetchOnce#1
TeoSlayer merged 1 commit into
mainfrom
add-test-coverage

Conversation

@TeoSlayer
Copy link
Copy Markdown
Contributor

Summary

  • Adds zz_fetch_test.go covering the previously 0%-covered fetchOnce via an http.RoundTripper that rewrites the const defaultURL to a local httptest.NewServer — no real network.
  • Pins the iter-1 audit HIGH finding (no signature verification on runtime-fetched allowlist) as a regression-detection test: a malicious server serving structurally-valid JSON is currently accepted wholesale. The test will fail loudly the moment signature verification ships.
  • Drives Service.Stop's ctx.Done() branch (85.7% -> 100%).
  • Tracks zz_service_test.go which had been left untracked in the working tree.

Coverage delta

Function Before After
fetchOnce 0.0% 94.7%
Stop 85.7% 100%
Total 71.7% 90.9%

Ceiling lines — why each one stays uncovered without source changes

  • init malformed-embed branch (20%) — the only way to drive it is to ship a broken trusted-agents.json, which //go:embed and CI already prevent.
  • Run timer.C fetch arm (66.7%)fetchInterval = 1 * time.Hour and defaultURL are package consts; a second iteration can't be driven in test time without either modifying source or hitting the real GitHub URL.
  • fetchOnce http.NewRequestWithContext error branch (94.7%) — only fires on parse failure of the const defaultURL or a nil ctx (which panics inside NewRequestWithContext).
  • jitter rand.Reader failure branch (83.3%)crypto/rand.Reader is a package var the function references directly; not injectable without source change.

Test plan

  • go test -race -count=1 -timeout 180s ./... passes (2.7s, 0 failures)
  • go vet ./... clean
  • No new mutations to source files; only new *_test.go files
  • No real network calls — all HTTP routed through httptest

Audit note for reviewers

TestFetchOnce_AcceptsAnyJSON_NoSignatureCheck is intentionally a guard test for the missing signature-verification gap, not a passive coverage hit. If signature verification ships, that test will fail and should be updated alongside the trust-model change.

Adds zz_fetch_test.go covering the previously-untested fetchOnce path
via an http.RoundTripper that rewrites raw.githubusercontent.com
requests at a local httptest server. Also pins the iter-1 audit HIGH
finding (no signature verification on runtime-fetched allowlist) as a
regression-detection test, and drives the Service.Stop ctx-done branch.

Includes zz_service_test.go which had been left untracked.

Per-function coverage:
- fetchOnce      0.0% -> 94.7%
- Stop          85.7% -> 100%
- Total         71.7% -> 90.9%

Remaining ceiling lines (not fixable without source changes):
- init malformed-embed branch (//go:embed payload is valid by construction)
- Run timer.C fetch arm (fetchInterval=1h, defaultURL const = cannot drive a
  fast second iteration without real network)
- fetchOnce http.NewRequestWithContext error branch (defaultURL is a const,
  nil ctx panics inside NewRequestWithContext)
- jitter rand.Reader failure branch (rand.Reader is not injectable)
@codecov
Copy link
Copy Markdown

codecov Bot commented May 28, 2026

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

ℹ️ You can also turn on project coverage checks and project coverage reporting on Pull Request comment

Thanks for integrating Codecov - We've got you covered ☂️

@TeoSlayer TeoSlayer merged commit 7c71103 into main May 28, 2026
2 checks passed
@TeoSlayer TeoSlayer deleted the add-test-coverage branch May 28, 2026 00:30
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