refactor: extract shared httputil, remove trivial wrappers in mcp and cmd#2794
Merged
refactor: extract shared httputil, remove trivial wrappers in mcp and cmd#2794
Conversation
4 tasks
- Create internal/httputil package with shared WriteJSONResponse function - Update server/http_helpers.go to delegate to httputil.WriteJSONResponse - Update proxy/handler.go to use httputil.WriteJSONResponse, remove local copy - Remove getAgentTagsSnapshotFromContext private wrapper from mcp/connection.go - Update its call-site to call GetAgentTagsSnapshotFromContext directly - Inline ValidateDIFCMode in cmd/root.go and cmd/proxy.go via difc.ParseEnforcementMode - Remove ValidateDIFCMode wrapper from cmd/flags_difc.go - Update tests in flags_difc_test.go to use difc.ParseEnforcementMode directly Agent-Logs-Url: https://github.com/github/gh-aw-mcpg/sessions/7a2a0dee-be9a-4cff-84c6-793489ae1996 Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Refactor duplicate function writeJSONResponse in Go source files
refactor: extract shared httputil, remove trivial wrappers in mcp and cmd
Mar 29, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors internal packages to remove dead indirection and consolidate duplicated HTTP/JSON response logic, reducing maintenance overhead across server/proxy/cmd/mcp.
Changes:
- Introduces
internal/httputil.WriteJSONResponseand updates server/proxy to use it (server keeps a local shim). - Removes trivial wrapper
getAgentTagsSnapshotFromContextininternal/mcp. - Removes unused exported
ValidateDIFCModewrapper ininternal/cmdand updates call sites/tests to usedifc.ParseEnforcementMode.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| internal/server/http_helpers.go | Replaces duplicated JSON response writer implementation with a shim calling internal/httputil. |
| internal/proxy/handler.go | Switches JSON responses to httputil.WriteJSONResponse and removes local helper. |
| internal/mcp/connection.go | Drops redundant private wrapper and calls exported context helper directly. |
| internal/httputil/httputil.go | Adds shared JSON response writer helper for HTTP-facing packages. |
| internal/cmd/root.go | Inlines DIFC mode validation via difc.ParseEnforcementMode. |
| internal/cmd/proxy.go | Inlines DIFC mode validation and adds difc import. |
| internal/cmd/flags_difc_test.go | Updates tests to validate modes via difc.ParseEnforcementMode. |
| internal/cmd/flags_difc.go | Removes unused exported ValidateDIFCMode wrapper. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
61
to
66
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| err := ValidateDIFCMode(tt.mode) | ||
| _, err := difc.ParseEnforcementMode(tt.mode) | ||
| if tt.wantErr { | ||
| assert.Error(t, err, "expected error for mode %q", tt.mode) | ||
| } else { |
There was a problem hiding this comment.
This test now validates difc.ParseEnforcementMode directly, but the test function name still references the removed ValidateDIFCMode helper. Renaming the test (and any related descriptions) will keep intent clear and avoid confusion when searching for ValidateDIFCMode usages.
This was referenced Mar 29, 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.
Three categories of dead indirection identified across
internal/: one exact cross-package duplicate, one private wrapper delegating to the public function three lines below it, and one exported wrapper used only within its own package.Changes
internal/httputil(new package)WriteJSONResponse— previously copy-pasted byte-for-byte in bothserver/http_helpers.goandproxy/handler.goserverkeeps a package-local shim for internal callers;proxycall-sites updated directlyinternal/mcp/connection.gogetAgentTagsSnapshotFromContext— a one-liner wrappingGetAgentTagsSnapshotFromContextwith no added valueinternal/cmd/flags_difc.goValidateDIFCMode— never called outsidecmd, was a one-liner overdifc.ParseEnforcementModeroot.go,proxy.go) inlined todifc.ParseEnforcementMode;proxy.gogains thedifcimportdifc.ParseEnforcementModedirectlyWarning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
example.com/tmp/go-build502407326/b336/launcher.test /tmp/go-build502407326/b336/launcher.test -test.testlogfile=/tmp/go-build502407326/b336/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build502407326/b252/vet.cfg 64/src/runtime/cgo main x_amd64/vet(dns block)invalid-host-that-does-not-exist-12345.com/tmp/go-build502407326/b320/config.test /tmp/go-build502407326/b320/config.test -test.testlogfile=/tmp/go-build502407326/b320/testlog.txt -test.paniconexit0 -test.timeout=10m0s 64/s�� go edprintable/reader.go x_amd64/compile(dns block)nonexistent.local/tmp/go-build502407326/b336/launcher.test /tmp/go-build502407326/b336/launcher.test -test.testlogfile=/tmp/go-build502407326/b336/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build502407326/b252/vet.cfg 64/src/runtime/cgo main x_amd64/vet(dns block)slow.example.com/tmp/go-build502407326/b336/launcher.test /tmp/go-build502407326/b336/launcher.test -test.testlogfile=/tmp/go-build502407326/b336/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build502407326/b252/vet.cfg 64/src/runtime/cgo main x_amd64/vet(dns block)this-host-does-not-exist-12345.com/tmp/go-build502407326/b345/mcp.test /tmp/go-build502407326/b345/mcp.test -test.testlogfile=/tmp/go-build502407326/b345/testlog.txt -test.paniconexit0 -test.timeout=10m0s --no�� _.a(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.