[test] Add tests for server.rate_limit, server.middleware_auth, and server.response_writer#9200
Draft
github-actions[bot] wants to merge 1 commit into
Draft
Conversation
Add comprehensive test coverage for three previously untested files in the server package: - rate_limit_test.go: Tests for isRateLimitText, extractRateLimitErrorText, and isRateLimitToolResult covering all rate-limit text patterns, non-map inputs, MCP content extraction, and reset-time parsing. - middleware_auth_test.go: Tests for authMiddleware, applyIfConfigured, and applyAuthIfConfigured covering valid keys, missing headers, wrong keys, malformed headers (null bytes), and the no-key passthrough path. - response_writer_test.go: Tests for newResponseWriter, WriteHeader, Write, multiple writes, body capture, header passthrough, and interface compliance. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Test Coverage Improvement
Functions Analyzed
internal/serverrate_limit.go,middleware_auth.go,response_writer.goWhy These Functions?
Three files in
internal/serverhad zero test coverage despite containing meaningful business logic:rate_limit.go— Detects GitHub API rate-limit errors from tool results, including text pattern matching and reset-time extractionmiddleware_auth.go— API key authentication middleware implementing spec section 7.1, including malformed header detectionresponse_writer.go— HTTP response wrapper that captures body and status code for loggingTests Added
rate_limit_test.goisRateLimitText— all known rate-limit patterns (case-insensitive), negative cases, partial matchesextractRateLimitErrorText— MCP content extraction, non-map inputs, empty content fallbackisRateLimitToolResult— error vs success results, reset-time parsing, secondary rate limits, too-many-requestsmiddleware_auth_test.goauthMiddleware— valid key, missing header (401), wrong key (401), malformed header with null byte (400)applyIfConfigured— middleware applied when key non-empty, passthrough when key emptyapplyAuthIfConfigured— end-to-end with and without API keyresponse_writer_test.gonewResponseWriter— initial state (zero status, empty body)WriteHeader— status code captured in wrapper and underlying recorderWrite— body captured in buffer and passed through to underlying writerhttp.ResponseWriter)Coverage Report
Generated by Test Coverage Improver
Warning
Firewall blocked 2 domains
The following domains were blocked by the firewall during workflow execution:
awmgmcpgproxy.golang.orgSee Network Configuration for more information.