refactor: eliminate integrity-level duplication, relocate truncateCacheKeyForLog, extract jsonutil package#6911
Merged
Conversation
5 tasks
…extract jsonutil package - Finding 1: Add config.AllIntegrityLevels exported slice; update guard/wasm_validate.go to reference config constants instead of hardcoded strings; update guard_policy_validation.go to alias the exported slice. - Finding 2: Move truncateCacheKeyForLog from http_helpers.go to routed.go (its only call site), removing now-unused fmt/strings imports from http_helpers.go. - Finding 3: Create internal/jsonutil package with DeepCloneJSON; remove it from strutil/util.go; update proxy/response_transform.go and all proxy test files to use jsonutil.DeepCloneJSON.
Copilot
AI
changed the title
[WIP] Refactor integrity-level duplication and minor file organization
refactor: eliminate integrity-level duplication, relocate truncateCacheKeyForLog, extract jsonutil package
Jun 2, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors shared validation/utilities to reduce duplication and drift risk by centralizing integrity-level definitions, relocating a cache-key logging helper to its sole call site, and extracting JSON-cloning logic into a dedicated internal/jsonutil package.
Changes:
- Centralized integrity-level lists/constants via
config.AllIntegrityLevelsand updated guard/validation call sites. - Moved
truncateCacheKeyForLogfromhttp_helpers.gotorouted.goand cleaned up unused imports. - Extracted
DeepCloneJSONintointernal/jsonutil, migrated its unit tests, and updated proxy code/tests to use the new package.
Show a summary per file
| File | Description |
|---|---|
| internal/strutil/util.go | Removes DeepCloneJSON from strutil to keep the package focused on string helpers. |
| internal/strutil/util_test.go | Drops DeepCloneJSON unit tests now that cloning moved to jsonutil. |
| internal/server/routed.go | Adds truncateCacheKeyForLog at its only usage site (routed-mode cache logging). |
| internal/server/http_helpers.go | Removes now-unused truncateCacheKeyForLog and associated imports. |
| internal/proxy/response_transform.go | Switches deep-cloning to jsonutil.DeepCloneJSON. |
| internal/proxy/response_transform_test.go | Updates tests to reference jsonutil.DeepCloneJSON. |
| internal/proxy/response_transform_coverage_test.go | Updates coverage tests to reference jsonutil.DeepCloneJSON. |
| internal/proxy/proxy_test.go | Updates proxy tests to reference jsonutil.DeepCloneJSON. |
| internal/jsonutil/clone.go | Introduces jsonutil.DeepCloneJSON in a semantically appropriate package. |
| internal/jsonutil/clone_test.go | Adds unit tests for jsonutil.DeepCloneJSON. |
| internal/guard/wasm_validate.go | Replaces hardcoded integrity strings with config-derived values. |
| internal/config/guard_policy.go | Adds AllIntegrityLevels as a central integrity-level list. |
| internal/config/guard_policy_validation.go | Aliases allowed integrity-levels to AllIntegrityLevels for validation. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 13/13 changed files
- Comments generated: 2
Comment on lines
+10
to
+16
| // AllowedIntegrityLevels is derived from the canonical integrity constants in config. | ||
| var AllowedIntegrityLevels = []string{ | ||
| config.IntegrityNone, | ||
| config.IntegrityUnapproved, | ||
| config.IntegrityApproved, | ||
| config.IntegrityMerged, | ||
| } |
Comment on lines
+20
to
+21
| // AllIntegrityLevels is the canonical ordered list of all valid integrity-level values. | ||
| var AllIntegrityLevels = []string{IntegrityNone, IntegrityUnapproved, IntegrityApproved, IntegrityMerged} |
Collaborator
|
@copilot address review feedback |
Contributor
Author
Addressed in commit
|
Copilot stopped work on behalf of
lpcox due to an error
June 2, 2026 23:31
4 tasks
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 static-analysis findings where code lived in the wrong place or was independently redefined, creating silent drift risk and semantic confusion.
Finding 1 — Single source of truth for integrity levels
guard/wasm_validate.gohardcoded["none","unapproved","approved","merged"]independently of the identical constants already inconfig. Adding a new level required three edits.config.AllIntegrityLevels()as the canonical exported accessorconfigand return a defensive copy to prevent mutation driftguard.AllowedIntegrityLevelsnow derives fromconfig.AllIntegrityLevels()allowedGuardPolicyIntegrityLevelsinconfig/guard_policy_validation.gonow derives fromconfig.AllIntegrityLevels()Finding 2 — Move
truncateCacheKeyForLogto its only call siteThe function lived in
http_helpers.gobut was exclusively called fromrouted.go(3 call sites, all in cache eviction logging). Moved it there; removed the now-unusedfmtandstringsimports fromhttp_helpers.go.Finding 3 — Extract
DeepCloneJSONfromstrutilstrutilis a string-formatting package;DeepCloneJSONoperates on arbitraryinterface{}values and doesn't belong there. Createdinternal/jsonutilpackage, moved the function and its tests, updated the one production caller (proxy/response_transform.go) and three proxy test files.