Skip to content

[test-improver] Improve tests for httputil package (endpoint helpers)#7286

Open
github-actions[bot] wants to merge 1 commit into
mainfrom
test-improver/httputil-endpoint-helpers-809b29faffbde23f
Open

[test-improver] Improve tests for httputil package (endpoint helpers)#7286
github-actions[bot] wants to merge 1 commit into
mainfrom
test-improver/httputil-endpoint-helpers-809b29faffbde23f

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Test Improvements: httputil_test.go

File Analyzed

  • Test File: internal/httputil/httputil_test.go
  • Package: internal/httputil
  • Lines of Code: 427 → 484 (+57 lines)

Improvements Made

1. Increased Coverage

  • ✅ Added TestWriteSimpleHealthResponse — covers WriteSimpleHealthResponse (was 0%)
  • ✅ Added TestWriteReflectResponse with 3 subtests — covers WriteReflectResponse (was 0%)
  • Previous Coverage: 96.6%
  • New Coverage: 100.0%
  • Improvement: +3.4%

2. Better Testing Patterns

  • ✅ Used t.Run() subtests for the reflect response scenarios
  • ✅ Used require.NoError before assertions that depend on successful decode
  • ✅ Descriptive subtest names that document expected behaviour
  • ✅ RFC3339 timestamp validation via time.Parse

3. Coverage Scenarios Added

Subtest What it verifies
TestWriteSimpleHealthResponse Status 200, application/json Content-Type, {"status":"ok"} body with exactly one field
TestWriteReflectResponse/empty_components_returns_valid_response_shape Non-nil Agents map and non-empty Timestamp for a zero-value DIFCComponents
TestWriteReflectResponse/strict_mode_is_reflected_in_response_body mode:"strict" propagated from difc.NewComponents through the response
TestWriteReflectResponse/timestamp_is_an_RFC3339_string Timestamp field parses as a valid RFC3339 string

Test Execution

All tests pass:

=== RUN   TestWriteSimpleHealthResponse
--- PASS: TestWriteSimpleHealthResponse (0.00s)
=== RUN   TestWriteReflectResponse
=== RUN   TestWriteReflectResponse/empty_components_returns_valid_response_shape
=== RUN   TestWriteReflectResponse/strict_mode_is_reflected_in_response_body
=== RUN   TestWriteReflectResponse/timestamp_is_an_RFC3339_string
--- PASS: TestWriteReflectResponse (0.00s)
PASS
coverage: 100.0% of statements
ok  github.com/github/gh-aw-mcpg/internal/httputil  0.008s  coverage: 100.0% of statements

Why These Changes?

WriteSimpleHealthResponse and WriteReflectResponse in endpoint_helpers.go are shared helpers used by both the server and proxy packages to ensure consistent health and DIFC reflect endpoint responses. Despite being production-critical shared utilities, they had 0% test coverage. The new tests confirm correct HTTP status codes, Content-Type headers, response body shapes, and DIFC mode/timestamp fields.


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 3.1M ·

Add tests for WriteSimpleHealthResponse and WriteReflectResponse,
which had 0% coverage. Coverage improves from 96.6% to 100.0%.

- TestWriteSimpleHealthResponse: verifies status 200, application/json
  Content-Type, and {"status":"ok"} body shape
- TestWriteReflectResponse: three subtests verifying valid response shape,
  mode propagation (strict), and RFC3339 timestamp format

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

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 unit test coverage for shared internal/httputil endpoint helper functions that generate JSON responses used by both the server and proxy.

Changes:

  • Add TestWriteSimpleHealthResponse to validate status code, Content-Type, and minimal JSON body shape.
  • Add TestWriteReflectResponse subtests to validate /reflect response shape, mode propagation, and RFC3339 timestamp formatting.
  • Introduce a new internal/difc test dependency to construct/validate reflect response types.
Show a summary per file
File Description
internal/httputil/httputil_test.go Adds new tests to cover WriteSimpleHealthResponse and WriteReflectResponse, exercising response headers/body shape and DIFC reflect fields.

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

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