test: cover reachable coverage gaps - #515
Merged
Merged
Conversation
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 Report✅ All modified and coverable lines are covered by tests. @@ 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
... and 2 files with indirect coverage changes Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
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.
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.gothe empty no-exporter case). 8 is the floor unless those conventions change.What was covered
internal/validation— theaccount_namevalidator closure, viavalidation.Varrows for valid names, digits, hyphen, underscore, trailing$, exactly 32 characters, 33 characters, uppercase, leading digit, leading hyphen, slash, space and empty; plus itscustomHintsentry, 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— theErrJobEnvelopeMissingarm of the signature error switch. Its siblings (bad signature, not enrolled) were already covered; this one was not.One production change, and why
self.goneeded more than a test.gopsutil'sMemoryInfo()does not fail in practice, and the existingSetMemoryInfoFnseam replaces the whole closure, so it can never exercise the real one. The raw call now sits behind its ownprocMemoryInfoFn, matching thecpuPercentFnstyle beside it, and the default is a nameddefaultMemoryInfoFnsoResetMemoryInfoFnrestores 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