[test] Add tests for proxy.(*proxyHandler).handleWithDIFC - #13659
github-actions[bot] wants to merge 1 commit into
Conversation
- Add TestServeHTTP_GraphQLBodyReadError covering the io.ReadAll error path when reading a GraphQL POST body in ServeHTTP. - Add TestServeHTTP_GraphQLIntrospectionUpstreamFailure covering the resp==nil early return when the introspection forward fails. - Add TestHandleWithDIFC_LabelResponseError_EnclaveMode and TestHandleWithDIFC_Phase5Error_EnclaveMode covering the enclave-mode branches of the Phase 4/5 error handlers (writeEnclaveDenied instead of the coarse fallback). - Add TestHandleWithDIFC_Phase5Error_NonEnclave covering the non-enclave Phase 5 FilterAndConvertLabeledData error fallback to an empty response. - Add TestHandleWithDIFC_FinalMarshalError covering the final json.Marshal failure branch when serializing the filtered response. Coverage for proxy.(*proxyHandler).handleWithDIFC rose from 91.7% to 100.0% (gocyclo complexity 36, the highest-complexity under-95% function in the codebase after excluding already fully-tested heavy entrypoints). internal/proxy package coverage rose from 95.6% to 96.7%. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The network-dependent test must use a deterministic mocked transport before approval.
Get a fresh assessment by requesting another Copilot review.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Adds targeted tests for previously uncovered DIFC and GraphQL error paths.
Changes:
- Adds six error-path tests.
- Covers enclave behavior, upstream failures, and serialization errors.
- Adds deterministic DIFC test doubles.
| File | Summary | Review |
|---|---|---|
internal/proxy/handler_difc_coverage_test.go |
Adds focused proxy/DIFC coverage tests. | Moderate (3 votes): Replace the real TCP connection to port 1 with a mocked transport to deterministically exercise the resp == nil branch. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| s := newTestServer(t, "http://127.0.0.1:1") // connection refused | ||
| h := &proxyHandler{server: s} |
🔒 mcpg Read-Only Stress — defaultSurface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Overall: INCONCLUSIVE No write leaked. Gaps: (1) Part B — the
|
🔒 mcpg Read-Only Stress — gvisorSurface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Overall: INCONCLUSIVE No write leaked through any surface in this run. The INCONCLUSIVE marks reflect known methodology gaps, not enforcement failures:
Consistent with the
|

Test Coverage Improvement: handleWithDIFC
Function Analyzed
internal/proxy(*proxyHandler).handleWithDIFCcmd.run,cmd.runProxy,config.LoadFromFile,middleware.wrapToolHandler,server.callBackendTool,config.validateGatewayConfigWithAgentRequirement,guard.buildStrictLabelAgentPayload)Why This Function?
handleWithDIFCruns the 6-phase DIFC (Decentralized Information Flow Control) enforcement pipeline for every proxied GitHub API request — it's one of the most security-critical, branch-heavy functions in the gateway. Several error/enclave-mode branches were never exercised by existing tests, including how Phase 4/5 failures are handled differently in enclave mode vs. normal mode, and the final JSON serialization failure path.Tests Added
New file
internal/proxy/handler_difc_coverage_test.go(6 tests):TestServeHTTP_GraphQLBodyReadError—io.ReadAllfailure while reading a GraphQL POST body inServeHTTPTestServeHTTP_GraphQLIntrospectionUpstreamFailure— introspection query forwarding to an unreachable upstream (resp == nilearly return)TestHandleWithDIFC_LabelResponseError_EnclaveMode— Phase 4LabelResponseerror in enclave mode →writeEnclaveDeniedinstead of the coarse-result fallbackTestHandleWithDIFC_Phase5Error_NonEnclave— Phase 5FilterAndConvertLabeledDataerror, non-enclave mode → falls back to an empty responseTestHandleWithDIFC_Phase5Error_EnclaveMode— same Phase 5 error, enclave mode →writeEnclaveDeniedTestHandleWithDIFC_FinalMarshalError— finaljson.Marshal(finalData)failure when serializing the filtered response (unmarshalablechan intpayload)All new tests use the existing
stubGuard/newTestServerWithStub/mockUpstreamtest helpers already present in the package, plus a small newerrorToResultLabeledDatatest double (adifc.LabeledDatawhoseToResult()always errors) to deterministically drive the Phase 5 error path.Coverage Report
Test Execution
make agent-finishedresults: Go format ✅, build ✅, unit tests ✅ (all packages), integration tests ✅.golangci-lintwas skipped (not installed in this sandbox — consistent with prior coverage-improver runs). The Rust guard unit test step failed only due to a sandbox network block oncrates.io(pre-existing environment limitation unrelated to this change, consistent with all prior runs of this workflow).Generated by Test Coverage Improver
Next run will target the next most complex under-tested function (candidates recorded in cache-memory progress notes)
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.