[test] Add tests for middleware.applyJqSchema, savePayload, and WrapToolHandler uncovered paths#1704
Draft
github-actions[bot] wants to merge 1 commit intomainfrom
Conversation
…ler uncovered paths Improves test coverage of internal/middleware package from 75.2% to 88.3%. Changes: - applyJqSchema: 70% -> 100% (added tests for no-results, HaltError nil/non-nil, generic jq errors) - savePayload: 77.3% -> 95.5% (added tests for dir creation failure and file write failure) - WrapToolHandler: 80.5% -> 90.9% (added tests for nil result, IsError=true, save failure, schema failure) New test functions: - TestApplyJqSchema_UncoveredPaths: tests all error branches in applyJqSchema by injecting custom jq programs (empty, halt, halt_error, type errors) - TestSavePayload_ErrorCases: tests filesystem error paths using read-only directories - TestWrapToolHandler_NilAndErrorResultCases: tests nil result and IsError=true pass-through - TestWrapToolHandler_SavePayloadFailure: tests graceful handling when payload save fails - TestWrapToolHandler_SchemaExtractionFailure: tests fallback when jq schema extraction fails 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:
internal/middlewarepackageFunction Analyzed
internal/middlewareapplyJqSchema,savePayload,WrapToolHandlerWhy These Functions?
Coverage analysis identified
applyJqSchema(70%),savePayload(77.3%), andWrapToolHandler(80.5%) as the most complex under-tested functions in the middleware package. These functions handle critical error paths—jq execution failures, filesystem errors, and tool call result handling—that were completely untested.Tests Added
TestApplyJqSchema_UncoveredPathsemptyprogram produces zero outputs)halt— clean halt with no message)halt_error— halt with error message)Tests inject custom-compiled jq programs by saving/restoring
jqSchemaCodeto precisely trigger each error branch.TestSavePayload_ErrorCasesMkdirAllsucceeds)TestWrapToolHandler_NilAndErrorResultCasesIsError=truewith no Go error (pass-through of MCP error result)TestWrapToolHandler_SavePayloadFailureTestWrapToolHandler_SchemaExtractionFailureCoverage Report
Generated by Test Coverage Improver
Next run will target the next most complex under-tested function
Warning
The following domains were blocked by the firewall during workflow execution:
go.yaml.ingolang.orggopkg.ingoproxy.cngoproxy.ioinvalidhostthatdoesnotexist12345.comproxy.golang.orgsum.golang.org