Repository navigation
[test-improver] Improve tests for middleware jqschema - #16558
Conversation
Replace weak conditional assertions in applyJqSchema context tests with deterministic checks. applyJqSchema checks ctx.Err() before inference, so cancelled and expired contexts always fail; the tests previously passed whether or not an error was returned. - Use require.ErrorIs for context.Canceled / context.DeadlineExceeded - Assert the nil result on failure - Replace manual t.Fatalf in payloadMetadataToMap with require.True Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are present, and the test-only changes strengthen deterministic coverage without altering production behavior.
No open issues 🎉
What changed in this PR
This test-only PR strengthens applyJqSchema middleware tests by replacing conditional assertions with deterministic checks for context cancellation, expired deadlines, and payload metadata validation. It improves regression detection without changing production behavior.
Changes:
- Asserts
context.Canceledandcontext.DeadlineExceededwith nil results. - Replaces the race-prone 1 ns timeout with an already-expired deadline.
- Uses
require.Truefor payload metadata type validation.
| File | Description |
|---|---|
| internal/middleware/jqschema_test.go | Strengthens context cancellation and deadline assertions and simplifies payload metadata type validation in middleware tests. |
Review effort: Lite (dynamic)
This comment has been minimized.
This comment has been minimized.
|
@copilot address review feedback and fix linting errors https://github.com/github/gh-aw-mcpg/actions/runs/43655468686/job/132687909750?pr=16558 |
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Fixed the lint error by switching to |
🔒 mcpg Read-Only Stress — defaultSurface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Overall: INCONCLUSIVE No write leaked in any probe (reads all succeeded, writes all refused/unavailable). Part B is
|
File analyzed
internal/middleware/jqschema_test.go(implementation:internal/middleware/jqschema.go)Improvements
Several
applyJqSchemacontext tests used conditional assertions (if err != nil { assert... }). They passed whether or not an error was returned, so they verified almost nothing.applyJqSchemachecksctx.Err()before inferring, so a cancelled or expired context always fails deterministically. The tests now assert that:handles context cancellation(TestApplyJqSchema_ErrorCases):require.ErrorIs(err, context.Canceled)and a nil result.respects short context timeoutrenamed torespects an expired context deadline(TestApplyJqSchema_TimeoutBehavior): uses a deadline already in the past, so the outcome is deterministic. Assertscontext.DeadlineExceededand a nil result. The previous 1ns timeout was racy.canceled context returns error(TestApplyJqSchema_ContextTimeout):require.ErrorIs(err, context.Canceled), theschema inference failedprefix, and a nil result.payloadMetadataToMap: manualif !ok { t.Fatalf(...) }replaced withrequire.True.Test-only change. No implementation changes.
Coverage
internal/middlewarestatement coverage: 97.2% before and after. The gain is in assertion strength, not line count.Verification
gofmt -l internal/middleware/: cleango vet ./internal/middleware/: cleango test -count=3 ./internal/middleware/: passgo test -race -count=1 ./internal/middleware/: passmake agent-finished: Go format, build, vet, and all unit and integration packages pass. It stopped at the Rust guard step (test-rust), which could not fetch crates from crates.io in this sandbox (TLS certificate mismatch). The Rust step is unrelated to this change. golangci-lint was not installed, so lint was skipped.Notes
I also reviewed
internal/proxy/enclave_test.go. It hast.Fatalfinside HTTP handler goroutines, but baseline proxy coverage is already 96.7%, and the two uncovered enclave blocks are unreachable dead code, so I did not change it.Warning
Firewall blocked 4 domains
The following domains were blocked by the firewall during workflow execution:
example.comnonexistent.localslow.example.comthishostdoesnotexist12345.comTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.