Open
refactor: semantic function clustering — TLS relocation, util consolidation, and documentation#9205
Conversation
6 tasks
- Move configureTLSTrustEnvironment + tlsTrustEnvKeys from cmd/proxy.go to httputil/tls.go as ConfigureTLSTrustEnvironment + TLSTrustEnvKeys - Add cross-package TLS comments in httputil/tls.go and proxy/tls.go - Document statusResponseWriter in tracing/http.go as pure BaseResponseWriter embed - Merge util/session.go (FormatSessionIDForLog) into util/format_duration.go, delete util/session.go and util/session_test.go - Add layering comment to config/config_env.go explaining intentional envutil layering - Flag atomicWriteFile in logger/fileutil.go as future export candidate - Update cmd/proxy_test.go to use httputil.ConfigureTLSTrustEnvironment/TLSTrustEnvKeys - Add tests for ConfigureTLSTrustEnvironment in httputil/tls_test.go
Copilot
AI
changed the title
[WIP] Refactor semantic function clustering analysis
refactor: semantic function clustering — TLS relocation, util consolidation, and documentation
Jul 12, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors shared TLS and formatting utilities while improving architectural documentation.
Changes:
- Relocates TLS trust environment configuration into
httputil. - Consolidates session formatting and its tests.
- Documents TLS ownership, response-writer embedding, environment layering, and future file utility extraction.
Show a summary per file
| File | Description |
|---|---|
internal/util/session.go |
Removes consolidated helper file. |
internal/util/session_test.go |
Removes consolidated test file. |
internal/util/format_duration.go |
Adds session ID formatting helper. |
internal/util/format_duration_test.go |
Moves session formatting tests. |
internal/tracing/http.go |
Documents response-writer embedding. |
internal/proxy/tls.go |
Documents TLS package responsibilities. |
internal/logger/fileutil.go |
Notes potential atomic-write relocation. |
internal/httputil/tls.go |
Adds shared TLS trust configuration. |
internal/httputil/tls_test.go |
Tests TLS trust configuration. |
internal/config/config_env.go |
Documents environment-helper layering. |
internal/cmd/proxy.go |
Uses the relocated TLS helper. |
internal/cmd/proxy_test.go |
Updates tests for the relocated helper. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 12/12 changed files
- Comments generated: 3
- Review effort level: Medium
| // HTTP/TLS clients (Node.js, curl, git, Python requests) to a CA bundle. | ||
| // ConfigureTLSTrustEnvironment sets all of them to the path of the generated | ||
| // CA certificate so that child processes automatically trust the self-signed cert. | ||
| var TLSTrustEnvKeys = []string{ |
Comment on lines
+15
to
+17
| // New MCP_GATEWAY_* environment variables should be added here rather than | ||
| // in envutil, unless the accessor would be genuinely reusable outside the | ||
| // gateway (e.g., a generic typed getter with no domain knowledge). |
| } | ||
|
|
||
| err := configureTLSTrustEnvironment(caPath) | ||
| err := httputil.ConfigureTLSTrustEnvironment(caPath) |
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.
Six housekeeping items from the semantic function clustering analysis: misplaced TLS helper, scattered TLS documentation, undocumented ResponseWriter embed pattern, single-function util file, missing layering comment, and an unexported-but-relocatable atomic write helper.
Priority 1 — Move
configureTLSTrustEnvironmenttohttputilconfigureTLSTrustEnvironmentandtlsTrustEnvKeyswere buried incmd/proxy.godespite being reusable TLS infrastructure. Now exported frominternal/httputil:Priority 1 — Cross-package TLS comments
Both
httputil/tls.goandproxy/tls.gonow carry package-level doc comments explaining the split:httputilowns protocol-level TLS helpers (version policy, config constructors, trust env);proxyowns cert generation (GenerateSelfSignedTLS).Priority 2 — Document
statusResponseWriteras pure embedtracing.statusResponseWriteris a struct with no methods of its own — all behaviour comes fromhttputil.BaseResponseWriter. The doc comment now makes this explicit and cross-references the body-bufferingserver.responseWritervariant.Priority 3 — Consolidate
util/session.gointoutil/format_duration.gosession.gocontained exactly one function (FormatSessionIDForLog). Merged intoformat_duration.go(renamed to "String and time/duration formatting helpers") and deletedsession.go+session_test.go.Priority 3 — Layering comment in
config/config_env.goAdded a package-level comment explaining why
config_env.gowrapsenvutilrather than callingos.Getenvdirectly:envutilprovides generic typed accessors; this file adds gateway-specific validation policy on top.Priority 3 — Flag
atomicWriteFilefor future relocationAdded a
TODOcomment noting thatlogger.atomicWriteFileshould be exported tointernal/utilor a newinternal/fileutilpackage once a second consumer outsideloggerappears.