{{ message }}
refactor: semantic function clustering improvements (Finding 1–4)#8507
Merged
Conversation
4 tasks
Finding 1: Refactor PositiveInteger to delegate to TimeoutMinimum, preserving message/suggestion text by overriding after delegation. Finding 2: Rename internal/strutil package to internal/util to better reflect its general-purpose nature (not purely string utilities). Update all ~26 import sites across production code, tests, and documentation. Finding 3: Inline setup*/handle*Error named functions into logger factory var declarations for file, markdown, jsonl, tools, and observed-url-domains loggers. Update tests to call factory.setup/factory.onError instead. Finding 4: Add string constants (argOwner, argRepo, argPullNumber, etc.) in internal/proxy/router.go, replacing ~20 repeated bare string literals. Closes #8499
Copilot
AI
changed the title
[WIP] Refactor semantic function clustering analysis for code organization
refactor: semantic function clustering improvements (Finding 1–4)
Jul 2, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors several small areas identified by semantic analysis to reduce duplication, improve naming/discoverability, and tighten up routing/logging internals without changing overall gateway behavior.
Changes:
- Refactors
PositiveIntegerto delegate toTimeoutMinimumwhile preserving its specific error message/suggestion wording. - Renames
internal/strutiltointernal/utiland updates imports/usages across the codebase. - Inlines single-use logger factory helpers and centralizes proxy router arg keys as constants.
Show a summary per file
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 46/46 changed files
- Comments generated: 9
- Review effort level: Low
Comment on lines
+11
to
+15
| @@ -12,7 +12,7 @@ func TestHandleFileLoggerError_UsesFallback(t *testing.T) { | |||
| var logger *FileLogger | |||
| var err error | |||
| _ = captureStdLog(t, func() { | |||
| logger, err = handleFileLoggerError(assert.AnError, "/tmp/logs", "test.log") | |||
| logger, err = fileLoggerFactory.onError(assert.AnError, "/tmp/logs", "test.log") | |||
Comment on lines
+25
to
+29
| @@ -26,7 +26,7 @@ func TestHandleMarkdownLoggerError_UsesFallback(t *testing.T) { | |||
| var logger *MarkdownLogger | |||
| var err error | |||
| _ = captureStdLog(t, func() { | |||
| logger, err = handleMarkdownLoggerError(assert.AnError, "/tmp/logs", "test.md") | |||
| logger, err = markdownLoggerFactory.onError(assert.AnError, "/tmp/logs", "test.md") | |||
Comment on lines
+38
to
+42
| @@ -39,7 +39,7 @@ func TestHandleToolsLoggerError_UsesFallback(t *testing.T) { | |||
| var logger *ToolsLogger | |||
| var err error | |||
| _ = captureStdLog(t, func() { | |||
| logger, err = handleToolsLoggerError(assert.AnError, "/tmp/logs", "tools.json") | |||
| logger, err = toolsLoggerFactory.onError(assert.AnError, "/tmp/logs", "tools.json") | |||
Comment on lines
+74
to
+78
| @@ -75,7 +75,7 @@ func TestMarkdownLogger_Close_FooterWriteError(t *testing.T) { | |||
| // Close() should return nil. | |||
| func TestMarkdownLogger_Close_NilLogFile(t *testing.T) { | |||
| tmpDir := t.TempDir() | |||
| ml, err := handleMarkdownLoggerError(os.ErrNotExist, tmpDir, "test.md") | |||
| ml, err := markdownLoggerFactory.onError(os.ErrNotExist, tmpDir, "test.md") | |||
Comment on lines
370
to
+374
| // Create a directory at the target file path so atomicWriteFile's Rename fails. | ||
| targetDir := filepath.Join(tmpDir, observedURLDomainsFileName) | ||
| require.NoError(t, os.MkdirAll(targetDir, 0755)) | ||
|
|
||
| l, err := setupObservedURLDomainsLogger(nil, tmpDir, observedURLDomainsFileName) | ||
| l, err := observedURLDomainsLoggerFactory.setup(nil, tmpDir, observedURLDomainsFileName) |
| - `internal/sanitize/` - Sensitive data redaction utilities (`SanitizeString`, `SanitizeJSON`, `TruncateSecret`) for safe log output | ||
| - `internal/server/` - HTTP server (routed/unified modes) | ||
| - `internal/strutil/` - String and formatting utilities | ||
| - `internal/util/` - String and formatting utilities |
| ├── sanitize/ # Sensitive data redaction utilities for logging | ||
| ├── server/ # HTTP server (routed/unified modes) | ||
| ├── strutil/ # String and formatting utility helpers (deduplication, trimming, duration formatting, JSON deep-clone) | ||
| ├── util/ # String and formatting utility helpers (deduplication, trimming, duration formatting, JSON deep-clone) |
| - **`internal/sanitize/`** - Sensitive data redaction utilities (`SanitizeString`, `SanitizeJSON`, `TruncateSecret`) for safe log output | ||
| - **`internal/server/`** - HTTP server with routed and unified modes | ||
| - **`internal/strutil/`** - String and formatting utility helpers (deduplication, trimming, duration formatting, JSON deep-clone) | ||
| - **`internal/util/`** - String and formatting utility helpers (deduplication, trimming, duration formatting, JSON deep-clone) |
Collaborator
|
@copilot address review feedback |
Contributor
Author
Done in the latest commit. Changes made:
|
Collaborator
|
@copilot resolve the merge conflicts in this pull request |
…ntic-function-clustering # Conflicts: # internal/config/validation_rules.go
Contributor
Author
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.

Addresses all 4 actionable findings from the automated semantic analysis of 146 non-test Go source files (#8499).
Finding 1 —
PositiveIntegerdelegates toTimeoutMinimuminternal/config/validation_rules.go— eliminates duplicated< 1guard; matches the pattern already used byTimeoutPositive. ErrorMessageandSuggestiontext preserved via override:Finding 2 —
internal/strutil→internal/utilPackage renamed to
util: the package contains duration formatting, cryptographic randomness, JSON deep-clone, and collection utilities — none of which are string-specific. All ~26 import sites updated (production, tests, AGENTS.md, CONTRIBUTING.md).Finding 3 — Logger factory functions inlined
file_logger.go,markdown_logger.go,jsonl_logger.go,tools_logger.go,observed_url_domains_logger.go— 10 named functions (setupX/handleXError, 2 per logger × 5 loggers) that were each referenced exactly once as struct field values are inlined as anonymous functions directly in theirloggerFactoryvar declarations. Tests updated to usefactory.setup(...)/factory.onError(...).Finding 4 — Route arg-key constants in
proxy/router.goSeven constants (
argOwner,argRepo,argPullNumber,argIssueNumber,argMethod,argResourceID,argDiscussionNumber) replace ~20 scattered bare string literals across the route table andMatchRoute, providing a single source of truth and typo protection.