refactor: consolidate map utilities, deep clone, and logger constant#7156
Merged
Conversation
4 tasks
…eanup - Move GetStringFromMap from strutil/truncate.go to strutil/maputil.go and upgrade to variadic keys with first-non-empty semantics - Remove getFilteredItemStringField from server/difc_log.go; replace its 3 call sites with strutil.GetStringFromMap - Move DeepCloneJSON from internal/jsonutil/ to internal/strutil/; delete the now-empty jsonutil package - Collapse logTimestampLayout alias in logger/jsonl_logger.go to a single jsonTimestampLayout constant
Copilot
AI
changed the title
[WIP] Refactor semantic function clustering analysis: outliers and near-duplicates
refactor: consolidate map utilities, deep clone, and logger constant
Jun 7, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors internal utilities by consolidating JSON deep-cloning and untyped map string extraction into internal/strutil, removing a now-redundant helper in server, deleting the single-function jsonutil package, and simplifying a logger timestamp constant.
Changes:
- Moved and generalized
GetStringFromMapintointernal/strutil/maputil.go(variadic keys, first non-empty semantics) and replacedserver’s private helper usage. - Moved
DeepCloneJSONintointernal/strutiland updated proxy code/tests to usestrutil.DeepCloneJSON; removed theinternal/jsonutilpackage tests. - Removed the unused
logTimestampLayoutalias ininternal/logger/jsonl_logger.go.
Show a summary per file
| File | Description |
|---|---|
| internal/strutil/util_test.go | Expanded GetStringFromMap unit tests to cover new variadic semantics. |
| internal/strutil/truncate.go | Removed misplaced GetStringFromMap from truncation utilities. |
| internal/strutil/maputil.go | Introduced consolidated GetStringFromMap (variadic keys, first non-empty). |
| internal/strutil/deepclone.go | Relocated DeepCloneJSON into strutil. |
| internal/server/difc_log.go | Replaced local string-field helper with strutil.GetStringFromMap. |
| internal/server/difc_log_helpers_test.go | Removed tests for deleted helper; retained other helper tests. |
| internal/proxy/response_transform.go | Switched deep-clone call from jsonutil to strutil. |
| internal/proxy/response_transform_test.go | Updated deep-clone tests to use strutil.DeepCloneJSON. |
| internal/proxy/response_transform_coverage_test.go | Updated coverage tests to use strutil.DeepCloneJSON. |
| internal/proxy/proxy_test.go | Updated deep-clone test to use strutil.DeepCloneJSON. |
| internal/logger/jsonl_logger.go | Simplified timestamp layout constant definition. |
| internal/jsonutil/clone_test.go | Removed tests as internal/jsonutil package is deleted. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 12/12 changed files
- Comments generated: 2
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.
Four concrete code quality issues found via semantic function clustering: a misplaced utility, a near-duplicate private helper, a single-function package, and a dead constant alias.
Finding 1+2 —
GetStringFromMaprelocated and generalized;getFilteredItemStringFieldremovedGetStringFromMapwas living instrutil/truncate.gowith no relation to truncation. Moved to newstrutil/maputil.goand upgraded to variadic keys with first-non-empty semantics — which exactly matches whatserver/difc_log.go's privategetFilteredItemStringFieldwas doing:Single-key callers in
proxy/are unaffected (identical behaviour for the non-empty case).Finding 3 —
internal/jsonutil/package deletedjsonutil.DeepCloneJSONwas the only function in the package and had exactly one production caller (proxy/response_transform.go). Moved tointernal/strutil/deepclone.goalongside the other general-purpose utilities. Import updated inresponse_transform.goand the three proxy test files.Finding 4 — Dead
logTimestampLayoutalias removed