Skip to content

test: cover reachable coverage gaps - #515

Merged
retr0h merged 1 commit into
mainfrom
test/cover-reachable-blocks
Sep 18, 2026
Merged

retr0h merged 1 commit into
mainfrom
test/cover-reachable-blocks

Conversation

@retr0h

@retr0h retr0h commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator

Closes the four coverage gaps that are actually reachable. Zero-count statement blocks: 12 → 8.

The remaining 8 are deliberate and stay untouched — four defence-in-depth validation.Struct() calls that CONTRIBUTING tells contributors to keep, and four branches the code itself documents as unreachable (process/debian.go "gopsutil always succeeds", agent/seed.go "default body untestable", tracing/tracer.go the empty no-exporter case). 8 is the floor unless those conventions change.

What was covered

  • internal/validation — the account_name validator closure, via validation.Var rows for valid names, digits, hyphen, underscore, trailing $, exactly 32 characters, 33 characters, uppercase, leading digit, leading hyphen, slash, space and empty; plus its customHints entry, by triggering a failure and asserting the message carries the pattern and the maximum.
  • internal/telemetry/process — the memory-info error branch.
  • internal/agent/handler.go — the ErrJobEnvelopeMissing arm of the signature error switch. Its siblings (bad signature, not enrolled) were already covered; this one was not.

One production change, and why

self.go needed more than a test. gopsutil's MemoryInfo() does not fail in practice, and the existing SetMemoryInfoFn seam replaces the whole closure, so it can never exercise the real one. The raw call now sits behind its own procMemoryInfoFn, matching the cpuPercentFn style beside it, and the default is a named defaultMemoryInfoFn so ResetMemoryInfoFn restores that exact function rather than a duplicate closure — Go tracks coverage per source position, so a duplicate left the block looking uncovered. Behaviour is unchanged.

Context: main was at 99.8% and failing its gate after two security fixes added untested guards; #514 restored it, and this closes what remains reachable.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FuKUsHFG1EqZXamffh9M2c

Adds tests for four reachable statement blocks that just-test's
filtered coverage profile flagged as uncovered:

- internal/validation/validation.go: the account_name validator
  closure (length and pattern checks) and its customHints entry,
  exercised via validation.Var/Struct.
- internal/telemetry/process/self.go: the error branch inside
  memoryInfoFn when the underlying MemoryInfo call fails. gopsutil
  never returns an error from MemoryInfo() on any platform this runs
  on, so the raw call is now wrapped in its own injectable
  (procMemoryInfoFn) the same way cpuPercentFn already is, and the
  default memoryInfoFn is a named function so export_test.go's
  Reset restores the exact same function rather than a duplicate
  closure at a different source location.
- internal/agent/handler.go: the "missing or malformed job signature"
  reason, hit when PKI is enabled and job data is not a signed
  envelope, alongside the existing bad-signature and not-enrolled
  cases.

The remaining 8 zero-coverage blocks are deliberate and untouched:
four defense-in-depth validation.Struct() calls (file_upload.go,
reboot_post.go, shutdown_post.go, container_remove.go,
container_image_remove.go) and three documented-unreachable branches
(process/debian.go, agent/seed.go, tracing/tracer.go).

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@codecov

codecov Bot commented Sep 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #515      +/-   ##
==========================================
+ Coverage   99.90%   99.95%   +0.04%     
==========================================
  Files         489      489              
  Lines       23179    23180       +1     
==========================================
+ Hits        23157    23169      +12     
+ Misses         22       11      -11     
Files with missing lines Coverage Δ
internal/telemetry/process/self.go 100.00% <100.00%> (+5.00%) ⬆️

... and 2 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f00dca6...42bb157. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@retr0h
retr0h merged commit 7f8d1f2 into main Sep 18, 2026
12 checks passed
@retr0h
retr0h deleted the test/cover-reachable-blocks branch September 18, 2026 02:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant