Skip to content

[test-improver] Improve tests for tracing package#6716

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
test-improver/tracing-coverage-b59aa1a9a55d3c7c
Draft

[test-improver] Improve tests for tracing package#6716
github-actions[bot] wants to merge 1 commit into
mainfrom
test-improver/tracing-coverage-b59aa1a9a55d3c7c

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

Test Improvements: tracing package

Files Analyzed

  • Test Files: internal/tracing/parse_headers_test.go, internal/tracing/http_test.go
  • Package: internal/tracing

Improvements Made

1. Increased Coverage

  • ✅ Added TestParseOTLPHeadersWithDecoder_InvalidPercentEncoding — exercises the url.PathUnescape error branch in parseOTLPHeadersWithDecoder (previously uncovered). Verifies the raw value is preserved when percent-decoding fails (e.g. %GZ is not valid percent-encoding).

  • ✅ Added TestParseOTLPHeadersWithDecoder_ValidPercentEncoding — documents and verifies that well-formed percent-encoded values are decoded when decodeValues=true.

  • ✅ Added TestParseOTLPHeadersWithDecoder_NoDecoding — documents and verifies that percent-encoded values are preserved as-is when decodeValues=false.

  • ✅ Added TestWrapHTTPHandler_PatternMethodMismatch_ClearsRoute — exercises the else { route = "" } branch in WrapHTTPHandler (previously uncovered). This path is triggered when r.Pattern contains a method prefix that differs from the actual request method.

  • Previous Coverage: 96.4%

  • New Coverage: 97.6%

  • Improvement: +1.2%

2. Better Testing Patterns

  • ✅ New tests use table-driven style where multiple variants are needed
  • ✅ Tests include descriptive names following Test<Func>_<Scenario> convention
  • ✅ Tests are independent with no side effects

Test Execution

All tests pass:

ok  	github.com/github/gh-aw-mcpg/internal/tracing	0.017s	coverage: 97.6% of statements

All other Go tests continue to pass (make test-all).

Why These Changes?

The internal/tracing package had two meaningful uncovered branches:

  1. parseOTLPHeadersWithDecoder — The url.PathUnescape error path was untested. This is a real defensive code path that protects against invalid percent-encoded OTLP header values arriving via the OTEL_EXPORTER_OTLP_HEADERS environment variable.

  2. WrapHTTPHandler — The route = "" else-branch when the pattern's HTTP method doesn't match the request method was untested. While this rarely occurs in normal mux routing, it is a defensive code path worth covering.


Generated by Test Improver Workflow
Focuses on better patterns, increased coverage, and more stable tests

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • index.crates.io

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "index.crates.io"

See Network Configuration for more information.

Generated by Test Improver · sonnet46 4.9M ·

Add missing coverage for:
- parseOTLPHeadersWithDecoder: test invalid percent-encoding error path
  (url.PathUnescape failure → raw value preserved)
- WrapHTTPHandler: test route cleared when pattern method mismatches
  request method (exercises else-branch setting route = "")
- Additional tests for explicit decode/no-decode behaviour in
  parseOTLPHeadersWithDecoder

Coverage: 96.4% → 97.6%

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

0 participants