Skip to content

tests: raise dataexchange coverage from 52% to 69%#1

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

tests: raise dataexchange coverage from 52% to 69%#1
TeoSlayer merged 1 commit into
mainfrom
add-test-coverage

Conversation

@TeoSlayer
Copy link
Copy Markdown
Contributor

Summary

Adds a single new test file (zz_coverage_test.go) covering the
lowest-covered branches in service.go. Coverage goes from 52.3% to
68.8%
(target was 55%+). No production code touched.

Function-level deltas

Function Before After
evictInboxOverflow 0.0% 92.3%
handleConn 51.5% 93.9%
saveInboxMessage 73.9% 82.6%
inboxDir / receivedDir 33.3% 83.3%
Stop (lifecycle) 88.9% 88.9% (now exercised via Start)

What's covered

  • evictInboxOverflow — happy-path trim, no-op below cap, cap=0 default
    (10000), readdir error on missing dir, subdirectory skip.
  • handleConn — every switch arm: TypeBinary, TypeJSON,
    TypeFile (with and without filename), TypeTrace (happy +
    parse-error), unknown type. Plus the saveErr -> ERR ACK branch.
  • saveInboxMessage — mkdir-failure path; writes enough messages to
    trip the periodic inboxEvictCheckEvery tick.
  • receivedDir / inboxDir — HOME-fallback branch via t.Setenv.
  • LifecycleStart -> Stop happy path with a fake listener.

Test plan

  • go test -race -count=1 -timeout 120s ./... passes locally
  • Coverage >= 55% (now 68.8%)
  • No production code modified — only zz_coverage_test.go added

Adds focused tests for the lowest-covered functions in service.go:

- evictInboxOverflow: 0% -> 92.3% (no-op below cap, default cap branch,
  readdir error, subdir-skip, oldest-first trim ordering)
- handleConn: 51.5% -> 93.9% (TypeBinary, TypeJSON, TypeFile, TypeFile
  with empty filename, TypeTrace happy path + parse-error branch,
  saveErr -> ERR ACK, unknown type)
- saveInboxMessage: 73.9% -> 82.6% (mkdir error path; trip the periodic
  eviction tick once seq crosses inboxEvictCheckEvery)
- receivedDir / inboxDir: 33.3% -> 83.3% (HOME-fallback branch via
  t.Setenv)
- Adds a Start -> Stop happy-path lifecycle test
@TeoSlayer TeoSlayer merged commit 3c3cf41 into main May 27, 2026
1 check passed
@TeoSlayer TeoSlayer deleted the add-test-coverage branch May 27, 2026 22:44
@codecov
Copy link
Copy Markdown

codecov Bot commented May 27, 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 added a commit that referenced this pull request May 28, 2026
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).

Co-authored-by: Teodor Calin <teodor@vulturelabs.io>
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