tests: raise dataexchange coverage from 69% to 80% (package 95%)#5
Merged
Conversation
Round 2 follows the round-1 PR (#1) and lifts the test surface from the 69% post-round-1 baseline (./...) to 80%, with the dataexchange package itself moving from 82.5% to 95.3% of statements. New files: - zz_client_test.go — fake daemon (unix socket + IPC framer) plus end-to-end coverage for every Client method (Dial, SendText, SendJSON, SendBinary, SendFile, SendTrace, Recv, Close — all 0% → 100%). Also covers server.go ListenAndServe (0% → 90%) by pushing cmdAccept + cmdRecv at the driver and asserting the handler fires. - zz_service_errors_test.go — error-path drilling for service.go: saveReceivedFile EACCES + Events.Publish branches, saveInboxMessage Events.Publish branch, WriteFrame header/payload write errors, handleConn ACK-write-failure exit, Stop() ctx-cancelled branch, handleConn IncludeBase64=true branch. Includes two regression tests for PILOT-183 (evictInboxOverflow miscounts when subdirs are mixed with regular files) that pin the current behaviour and document the comment to remove once the fix lands. Per-function notable jumps: - client.go: 0% → 100% across all eight functions - server.go: ListenAndServe 0% → 90% - service.go: handleConn 93.9% → 97.0%, Stop 88.9% → 100%, evictInboxOverflow 92.3% → 96.2%, saveReceivedFile 72.7% → 90.9%, saveInboxMessage 82.6% → 87.0% Test fixtures: - fakeDaemon serialises all writes to the unix socket via writeMu — without it, daemon replies (cmdBindOK/cmdDialOK) interleave with test thread pushes (cmdAccept/cmdRecv) and corrupt the wire, surfacing as flaky "daemon disconnected" errors under -race. - waitForCompleteFrame polls the daemon's captured cmdSend stream until a full data-exchange Frame can be decoded — needed because driver.Conn.Write splits WriteFrame's header + payload writes into separate cmdSend IPC messages. Run: `go test -race -count=1 -timeout 180s ./...` — passes (12s, 0 flake across 20-iter stress).
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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
Round-2 coverage push following PR #1.
./...): 69.2% → 79.9%github.com/pilot-protocol/dataexchange): 82.5% → 95.3%The remaining gap to 100% in the total is entirely
examples/main.go(3 funcs at 0%) — a daemon-dialling CLI program that isn't worth wrapping in tests.What's new
Two new test files, no production code touched:
zz_client_test.go— adds afakeDaemon(unix-socket IPC peer that mimics enough of the Pilot daemon's wire protocol to satisfydriver.Driver) and covers every previously-zero function inclient.go:Dial,SendText,SendJSON,SendBinary,SendFile,SendTrace,Recv,Close— all 0% → 100%server.go:ListenAndServe0% → 90% via cmdAccept/cmdRecv push from the daemon sidezz_service_errors_test.go— drills the still-uncovered error paths inservice.go:saveReceivedFileEACCES (chmod 0500, skip-as-root) andfile.receivedevent branchsaveInboxMessagemessage.receivedevent branchWriteFrameheader-write + payload-write error brancheshandleConnACK-write-failure exit branchStop()ctx-cancelled branch (hanging listener forces<-ctx.Done())handleConnwithIncludeBase64=trueso the b64 branch insaveInboxMessageis exercised end-to-endevictInboxOverflow's subdir-miscount behaviour, with comments markedREMOVE WHEN PILOT-183 LANDSPer-function deltas
client.Dialclient.SendText/SendJSON/SendBinary/SendFile/SendTraceclient.Recv/Closeserver.ListenAndServeservice.handleConnservice.Stopservice.evictInboxOverflowservice.saveReceivedFileservice.saveInboxMessage¹ Dial shows 75% because one error branch (
d.DialAddrfailing) requires either a cmdError reply path (not covered by the happy-path daemon) or driver internals we can't reach from a test module — leaving it as the one stub.Flake hardening
Two stress-only failure modes surfaced under
-race -count=20, both fixed in the test harness (no production change):safeWriteunderwriteMu.driver.Conn.WritesplitsWriteFrame's 8-byte header and the payload into separate cmdSend IPC messages. The first version of the tests waited for "at least one cmdSend" before decoding, sometimes capturing only the header. Fixed bywaitForCompleteFramepolling until the byte stream decodes as a complete data-exchange Frame.Test plan
go test -race -count=1 -timeout 180s ./...passes (~12s)go test -race -count=20 -timeout 180s -run 'TestClient_|TestServer_' .passes (no flake)go vet ./...cleangofmt -lclean on new files