Repository navigation
[test-improver] Improve tests for Middleware (jq schema benchmark fix and testify assertions) - #16489
Conversation
BenchmarkCompileVsParse/parse_and_compile failed with 'function not defined: walk_schema/0' because it compiled the schema filter without the native walk_schema registration that init() uses. Move the registration into walkSchemaCompileOpts so production and the benchmark share one definition, use it in the benchmark, convert the manual b.Fatalf checks to testify require, and add a regression test asserting the filter compiles with the shared options. Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported, and the changes include shared compiler configuration plus regression coverage for compilation and schema output.
No open issues 🎉
What changed in this PR
This pull request fixes the middleware schema benchmark by centralizing walk_schema compiler registration and reusing the same options as production, while adding regression coverage for compilation and schema output.
Changes:
- Extracted shared
walk_schemacompiler options and reused them during initialization and benchmarking. - Fixed the parse-and-compile benchmark registration.
- Updated benchmark error handling and added a regression test for compilation and output.
| File | Description |
|---|---|
| internal/middleware/jqschema.go | Defines shared compiler options for registering the native walk_schema function and uses them during production initialization. |
| internal/middleware/jqschema_bench_test.go | Fixes the compile benchmark, updates benchmark assertions, and adds regression coverage for the shared compiler options. |
Review effort: Lite (dynamic)
🔒 mcpg Read-Only Stress — defaultSurface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Overall: INCONCLUSIVE No write of any kind leaked through in this run. Part B is INCONCLUSIVE because all 7 write tool names were entirely absent from the gateway-exposed catalog (23 read-only tools only), which per the test methodology only proves backend/toolset config, not the gateway's own DIFC/guard blocking layer. Parts D/E are INCONCLUSIVE because
|
File analyzed
internal/middleware/jqschema_bench_test.go(the only test file in the repo that did not import testify and used manualif err != nilchecks), plus the production helper it depends on ininternal/middleware/jqschema.go.Problem
BenchmarkCompileVsParse/parse_and_compilewas broken. It compiled thewalk_schemafilter with no options, but the filter calls a native function that is only registered ininit(). Before this change the benchmark failed:Benchmarks don't run under
go test, so this went unnoticed.Improvements
walk_schemaregistration intowalkSchemaCompileOpts()injqschema.go.init()and the benchmark now use the same definition, so they cannot drift.parse_and_compilecompiles with those options and runs successfully (~2.8 μs/op).b.Fatalfchecks withrequire.NoError(b, ...).TestWalkSchemaCompileOpts_CompilesFilter, which asserts the filter compiles with the shared options and matchesinferSchemaoutput.No behavior change to the production filter path;
init()only calls the extracted helper.Coverage
internal/middlewarestatement coverage: 97.2% before and after.Test output
go test -count=3 ./internal/middleware/→okgo test -run TestWalkSchemaCompileOpts_CompilesFilter -v→PASSgo test -run '^$' -bench . -benchtime=1x ./internal/middleware/→ all benchmarks pass (previouslyFAIL)go vet ./internal/middleware/andgofmt -l→ cleangolangci-lint v2.13.2 run ./internal/middleware/...→0 issuesmake agent-finished: format, build, lint, and all Go unit and integration tests pass. The final Rust guard step fails in this sandbox becausecargocannot reach crates.io (TLS/SNI mismatch with the network proxy). This is unrelated to the Go change.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.