[test-improver] Improve tests for middleware package#4719
Merged
Conversation
…st cases Add tests for uncovered branches in WrapToolHandler: - TestWrapToolHandler_NilResult: nil result passthrough - TestWrapToolHandler_IsErrorResultWithData: IsError=true passthrough without Go error - TestWrapToolHandler_PreviewUTF8Boundary: UTF-8 boundary cutPoint-- branch Coverage: internal/middleware 73.3% → 75.3% WrapToolHandler: 79.3% → 82.9% Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves branch coverage for the internal/middleware jq-schema middleware by adding focused unit tests around WrapToolHandler edge paths, including UTF-8-safe preview truncation.
Changes:
- Add tests covering early-return behavior when the wrapped handler returns a nil
*sdk.CallToolResultor anIsError=trueresult (no disk writes in both cases). - Add a test that verifies the payload preview truncation logic backs up to a valid UTF-8 rune boundary when the cut-point lands on a continuation byte.
- Add
unicode/utf8import to support UTF-8 boundary assertions.
Show a summary per file
| File | Description |
|---|---|
internal/middleware/jqschema_test.go |
Adds three targeted WrapToolHandler tests (nil result, error result passthrough, UTF-8 boundary truncation) and imports unicode/utf8. |
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
This was referenced Apr 28, 2026
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 Improvements:
jqschema_test.goFile Analyzed
internal/middleware/jqschema_test.gointernal/middlewareunicode/utf8import)Improvements Made
1. Increased Coverage
Three targeted tests added to cover previously uncovered branches in
WrapToolHandler:TestWrapToolHandler_NilResult— covers the early-return path when the upstream handler returns(nil, data, nil); previously thisif result == nilbranch was untested.TestWrapToolHandler_IsErrorResultWithData— covers the early-return path when the handler returnsIsError: truewith non-nil data and no Go error; confirms error results are passed through unchanged without writing to disk.TestWrapToolHandler_PreviewUTF8Boundary— covers thecutPoint--loop that backs up over a multi-byte UTF-8 character when the preview cut-point lands on a continuation byte. The test deliberately engineerspayloadJSON[500]to be0xA9(continuation byte ofé) and verifies the returned preview is valid UTF-8.internal/middlewaretotalWrapToolHandlerfunction2. Cleaner Tests
PayloadPreviewSizeis actually a continuation byte) so the test documents why it exercises a specific branch and will fail loudly if the test data construction ever becomes invalid.t.TempDir()for automatic cleanup.Test Execution
Full suite (
make test) passes for all packages (pre-existing unrelated failure inTestFetchAndFixSchema_NetworkErrorininternal/configis present onmainbefore this change).Why These Changes?
internal/middlewarehad the lowest coverage (73.3%) among packages without OS-level-only gaps. The three uncoveredWrapToolHandlerbranches were all reachable with normal test inputs — they just hadn't been exercised. The UTF-8 boundary test in particular covers a subtle correctness guarantee (no garbled preview output) that was completely absent from the existing test suite.Generated by Test Improver Workflow
Focuses on better patterns, increased coverage, and more stable tests
Warning
The following domain was blocked by the firewall during workflow execution:
invalidhostthatdoesnotexist12345.comTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.