Skip to content

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

Merged
lpcox merged 2 commits into
mainfrom
test-improver/tracing-parse-headers-coverage-1c42a33ee1f5fa0b
Jun 1, 2026
Merged

[test-improver] Improve tests for tracing package#6502
lpcox merged 2 commits into
mainfrom
test-improver/tracing-parse-headers-coverage-1c42a33ee1f5fa0b

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Test Improvements: parse_headers_test.go

File Analyzed

  • Test File: internal/tracing/parse_headers_test.go
  • Package: internal/tracing

Improvements Made

1. Increased Coverage

  • ✅ Added TestParseOTLPHeadersWithDecoder_DecodeValues — directly exercises parseOTLPHeadersWithDecoder with decodeValues=true, including the previously-uncovered url.PathUnescape error path (invalid percent-encoding such as %ZZ or lone % falls back to the raw value)

  • ✅ Added TestResolveHeaders_EnvVar_InvalidPercentEncoding — verifies the same fallback behaviour end-to-end via resolveHeaders when OTEL_EXPORTER_OTLP_HEADERS contains invalid percent-encoding

  • Previous Coverage: 96.6% (parseOTLPHeadersWithDecoder at 95.2%)

  • New Coverage: 97.3% (parseOTLPHeadersWithDecoder at 100%)

  • Improvement: +0.7% overall; parseOTLPHeadersWithDecoder fully covered

2. Better Testing Patterns

  • ✅ New tests follow the existing table-driven style in the file
  • ✅ Uses assert/require from testify, consistent with existing tests
  • ✅ Each case is self-describing with a name field

Test Execution

All tests pass:

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

Why These Changes?

parseOTLPHeadersWithDecoder is called with decodeValues=true when OTLP export headers come from the OTEL_EXPORTER_OTLP_HEADERS environment variable (W3C Baggage format). The function gracefully falls back to the raw string when url.PathUnescape fails, but this error path was never exercised by tests. The new tests confirm this defensive behaviour works correctly.


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

Generated by Test Improver · sonnet46 3.2M ·

Add tests for parseOTLPHeadersWithDecoder with decodeValues=true, covering:
- Valid percent-encoded header values (e.g. Bearer%20token → Bearer token)
- Invalid percent-encoding fallback to raw value (e.g. %ZZ stays as %ZZ)
- Lone percent sign (invalid) fallback to raw value

Also add TestResolveHeaders_EnvVar_InvalidPercentEncoding to verify the
same fallback behaviour when OTEL_EXPORTER_OTLP_HEADERS contains invalid
percent-encoding.

Coverage for parseOTLPHeadersWithDecoder improves from 95.2% → 100%,
and overall tracing package coverage improves from 96.6% → 97.3%.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@lpcox

lpcox commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

@copilot resolve the merge conflicts in this pull request

…-parse-headers-coverage-1c42a33ee1f5fa0b

# Conflicts:
#	internal/tracing/parse_headers_test.go

Copilot AI commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

Resolved the merge conflict in internal/tracing/parse_headers_test.go. The resolution keeps the comprehensive table-driven TestParseOTLPHeadersWithDecoder_DecodeValues and TestResolveHeaders_EnvVar_InvalidPercentEncoding tests from this branch, and incorporates TestParseOTLPHeadersWithDecoder_NoDecoding from main (which adds coverage for the decodeValues=false path). All tracing tests pass.

@lpcox lpcox marked this pull request as ready for review June 1, 2026 15:12
Copilot AI review requested due to automatic review settings June 1, 2026 15:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves test coverage for the internal/tracing header parsing logic, specifically exercising the decodeValues=true path used when reading OTLP export headers from OTEL_EXPORTER_OTLP_HEADERS.

Changes:

  • Replaces separate percent-encoding tests with a single table-driven TestParseOTLPHeadersWithDecoder_DecodeValues that covers valid decoding and invalid percent-encoding fallback behavior.
  • Adds an end-to-end test TestResolveHeaders_EnvVar_InvalidPercentEncoding to verify invalid percent-encoding fallback via resolveHeaders when headers come from the environment.
Show a summary per file
File Description
internal/tracing/parse_headers_test.go Adds/reshapes tests to cover decodeValues=true behavior and invalid percent-encoding fallback both directly and through resolveHeaders.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 1/1 changed files
  • Comments generated: 0

Copilot finished work on behalf of lpcox June 1, 2026 15:14
Copilot AI requested a review from lpcox June 1, 2026 15:14
@lpcox lpcox merged commit 36dcbc3 into main Jun 1, 2026
17 checks passed
@lpcox lpcox deleted the test-improver/tracing-parse-headers-coverage-1c42a33ee1f5fa0b branch June 1, 2026 15:30
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.

3 participants