[test] Add tests for server.registerToolsFromBackendContext - #13601
Conversation
Cover the previously under-tested tool-call handler closure and jq response-filter wiring inside registerToolsFromBackendContext: - malformed-argument parse-error branch under an enclave session (redacted logging path) - successful tool call under an enclave session (redacted request/response logging) - backend tools/call error under both an enclave session and a plain session (redacted vs non-redacted error logging) - successful tool call with the process-wide payload redaction flag enabled - ToolResponseFilters wiring: registering a server with a non-empty per-tool jq filter now exercises the middleware.WrapToolHandlerWithFilter branch instead of the plain middleware.WrapToolHandler branch Coverage for registerToolsFromBackendContext rose from 85.4% to 95.1%. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The tests do not verify redacted logs or filtered output, and one test incorrectly restores global state.
Get a fresh assessment by requesting another Copilot review.
Review effort: Balanced
Findings: 2
Open (3)
What changed in this PR
Adds targeted coverage for backend tool registration, redaction paths, error handling, and response-filter wiring.
Changes:
- Tests enclave and global payload-redaction paths.
- Tests successful and failed backend calls.
- Exercises per-tool jq response filtering.
| File | Description |
|---|---|
internal/server/register_tools_handler_redaction_test.go |
Adds handler redaction and response-filter tests. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| result, data, err := echoTool.Handler(ctx, req, nil) | ||
| require.NoError(err) | ||
| require.NotNil(result) | ||
| assert.False(result.IsError) | ||
| assert.NotNil(data) |
| sanitize.SetPayloadRedaction(true) | ||
| t.Cleanup(func() { sanitize.SetPayloadRedaction(false) }) |
| // TestRegisterToolsFromBackend_HandlerInvocation_Redaction exercises the | ||
| // argument-parse-error, request-log, requireSession-failure, and | ||
| // response-log branches of the tool handler closure created inside |
|
@copilot address review feedback |
This comment has been minimized.
This comment has been minimized.
…c comment Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Addressed in aa6c080/9be1edb/a83e32b: tests now capture actual log output (via |
🔒 mcpg Read-Only Stress — default AWF (normal container isolation)Surface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Overall: INCONCLUSIVE Notes:
|


Test Coverage Improvement: registerToolsFromBackendContext
Function Analyzed
internal/server(*UnifiedServer).registerToolsFromBackendContextWhy This Function?
Ranked functions in
internal/server,internal/config,internal/proxy, and related packages by cyclomatic complexity (viagocyclo) combined with inverse test coverage fromgo tool cover -func. The two highest-complexity/lowest-coverage candidates (cmd.runProxy,proxy.New) were already covered by earlier test-coverage-improver runs (tracked in cache memory). The next-highest-ranked untested candidate wasregisterToolsFromBackendContext, which registers backend MCP tools and builds a per-tool handler closure responsible for argument parsing, session validation, payload-redaction-aware logging, and jq response-filter middleware wiring — a security- and observability-relevant code path that was only 85.4% covered.Tests Added
New file:
internal/server/register_tools_handler_redaction_test.gotools/callerror under an enclave session (redacted error-log branch)tools/callerror under a plain (non-enclave) session (non-redacted error-log branch)ToolResponseFilterswiring: a server configured with a non-empty per-tool jq filter now exercisesmiddleware.WrapToolHandlerWithFilterinstead of the plainmiddleware.WrapToolHandlerbranchCoverage Report
Remaining uncovered lines in the function are either genuinely unreachable defensive code (the
requireSessionerror path can never trigger becauseNewSessionnever returns an error) or already exercised indirectly by other existing tests for sibling functions (registerAllToolsDIFC branch,ensureToolsRegisteredretry races,fetchBackendListcallback variants,registerPromptsFromBackendinner error branches).Test Execution
All new tests pass, along with the full existing suite:
make agent-finishedwas run: Go format, build, and all unit + integration tests passed (golangci-lint was skipped locally since it isn't installed in this sandbox). The Rust guard unit-test step failed only due to a sandbox network block oncrates.io(pre-existing/unrelated to this change, also observed in prior test-coverage-improver runs).Generated by Test Coverage Improver
Next run will target the next most complex under-tested function
Warning
Firewall blocked 6 domains
The following domains were blocked by the firewall during workflow execution:
api.github.comexample.comindex.crates.iononexistent.localslow.example.comthishostdoesnotexist12345.com[!TIP]
api.github.comis blocked because GitHub API access uses the built-in GitHub tools by default. Instead of addingapi.github.comtonetwork.allowed, usetools.github.mode: gh-proxyfor direct pre-authenticated GitHub CLI access without requiring network access toapi.github.com:See GitHub Tools for more information on
gh-proxymode.To allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.