tests: push coverage 92.4% -> 99.4%, pin audit findings#1
Merged
Conversation
New zz_coverage_ceiling_test.go targets the remaining defensive
branches (urlPath HOME-error, MkdirAll error, non-IsNotExist Remove
error, startClientLocked nil-Events / nil-Identity / NodeID-call,
SetURL SavePersistedURL warn-path, post() cooldown==0 fallback).
Plus three regression pins for the iter-1 audit:
- TestAudit_BackoffIsPerEvent_NoCarryover — verifies a fresh Emit
starts at initialBackoff, NOT 4*initialBackoff where the previous
event's exponential doubling left off. Closes the timing-leak
fingerprint vector.
- TestAudit_ResponseBodyClosedOnEveryStatus — hammers a single
httptest.Server and asserts unique remote-port count stays tiny.
If resp.Body.Close() ever regresses on the 2xx/4xx paths, the
HTTP/1.1 pool stops reusing connections and the count explodes.
- TestAudit_ResponseBodyClosedFreesGoroutines — secondary guard;
asserts goroutine count returns to baseline after a 200-event
burst. A body-close leak would scale goroutines with request count.
Honest ceiling at 99.4%. Two lines remain uncovered:
- service.go:132-134 (`if s.client == nil { return }`): dead
defensive code — NewClient only returns nil for empty URL, but
startClientLocked already returns at line 122 for that case.
- webhook.go:183 (Emit's second `case <-wc.closed:`): race-only
branch that needs Close to fire in the gap between the first
closed-check and the channel send. Attempts to force it (16
concurrent emitters + slow server + race-during-close) destabilized
unrelated tests in the same `go test` process via socket
pressure; TestWebhookConcurrentEmitClose already drives this path
under the race detector.
Note: the audit also flagged an HMAC timing-attack vector. The
webhook plugin does not sign payloads (POSTs raw JSON, no shared
secret), so that finding doesn't apply to this code surface; no
test was added.
`go test -race -count=1 -timeout 180s ./...` green 3/3 runs.
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 ☂️ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
zz_coverage_ceiling_test.goadds 13 tests that cover the remaining defensive branches the existing suite missed (urlPathHOME-error,MkdirAllfailure, non-IsNotExistRemoveerror,startClientLockednil-Events / nil-Identity / NodeID-call / nil-Events,SetURLSavePersistedURL warn-path,post()cooldown==0fallback).Honest ceiling — what's left and why
service.go:132-134(if s.client == nil { return }afterNewClient)NewClientonly returns nil for empty URL, butstartClientLockedalready short-circuits at line 122 for that case. Reaching this branch requiresNewClientto return nil for a non-empty URL, which it never does.webhook.go:183(case <-wc.closed:inEmit's second select)Closeto fire in the narrow window between the first<-wc.closedcheck and the channel send. An attempt to force it (16 concurrent emitters + slow server + race-during-close) generated enough socket pressure to flake unrelated tests in the samego testprocess, so the test was removed.TestWebhookConcurrentEmitClosealready drives this path under-race.Audit note
The iter-1 audit also flagged an HMAC timing-attack vector. The webhook plugin POSTs raw JSON with no shared secret or signature header — there is no HMAC verification path in this code. No test was added for that finding because there is no surface to defend.
Test plan
go test -race -count=1 -timeout 180s ./...passes 3/3 runsgo tool cover -funcreports 99.4% totalzz_more_test.go'sfakeEventBus/fakeIdentityare distinct from newlocalBus/localIdent)-race