Refactor: Move TruncateSessionID to sanitize package#776
Closed
Refactor: Move TruncateSessionID to sanitize package#776
Conversation
…DockerInspect - Moved TruncateSessionID() from internal/auth/header.go to internal/logger/sanitize/sanitize.go - Added comprehensive tests for TruncateSessionID in sanitize_test.go (8 test cases) - Updated all imports in internal/server/sdk_logging.go (7 occurrences) - Added documentation to runDockerInspect explaining its intentional placement - Updated package documentation in sanitize.go to mention TruncateSessionID - All tests passing, build successful Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Refactor semantic function clustering analysis
Refactor: Move TruncateSessionID to sanitize package
Feb 7, 2026
Collaborator
|
@copilot fix these linting errors make lint github.com/github/gh-aw-mcpg/internal/auth[github.com/github/gh-aw-mcpg/internal/auth]Error: vet: internal/auth/header_test.go:441:11: undefined: TruncateSessionID |
…uncateSessionID The test was added in main branch but was calling the function directly from the auth package. Since the function was moved to sanitize package, the test now correctly calls sanitize.TruncateSessionID. Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Contributor
Author
Collaborator
|
@copilot please fix these linting errors make lint github.com/github/gh-aw-mcpg/internal/auth[github.com/github/gh-aw-mcpg/internal/auth]Error: vet: internal/auth/header_test.go:447:6: TestTruncateSessionID redeclared in this block |
…teSessionID The main branch was updated with TestTruncateSessionID that calls TruncateSessionID directly. This caused a redeclaration error when CI merged main into this PR branch. Updated the file to match main branch's format and style while using sanitize.TruncateSessionID. Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
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.
Refactoring Plan
High Priority (Issue #1) ✅
TruncateSessionID()frominternal/auth/header.gotointernal/logger/sanitize/sanitize.goTruncateSessionID()insanitize_test.gointernal/server/sdk_logging.gofromauth.TruncateSessionIDtosanitize.TruncateSessionIDTestTruncateSessionIDinheader_test.goto callsanitize.TruncateSessionIDheader_test.gowith main branch format to prevent merge conflictsMedium Priority (Issue #2) ✅
runDockerInspect()explaining it's intentionally placed in validation packageVerification ✅
make test-unitto verify all tests passmake buildto ensure compilation worksmake lintto verify code qualityOriginal prompt
This section details on the original issue you should resolve
<issue_title>[refactor] Semantic Function Clustering - High-Priority Refactoring Opportunities</issue_title>
<issue_description># 🔧 Semantic Function Clustering Analysis
Analysis performed on repository: github/gh-aw-mcpg
Analysis date: 2026-02-05
Total Go files analyzed: 62 files (39 non-test files)
Executive Summary
The codebase demonstrates excellent overall organization with clear package boundaries and minimal code duplication. The analysis identified 2 high-priority refactoring opportunities and several minor organizational improvements. Most patterns follow Go idioms and domain-driven design principles.
Key Findings:
TruncateSessionIDin auth package (used only by logger)runDockerInspectin validation package (Docker operation)Function Inventory Summary
Packages Analyzed
internal/authinternal/cmdinternal/configinternal/difcinternal/guardinternal/launcherinternal/loggerinternal/mcpinternal/middlewareinternal/serverinternal/sysinternal/testutilinternal/timeutilinternal/ttyinternal/versionTotal Functions Cataloged: ~350 functions and methods
Semantic Clusters Identified: 9 major patterns
High-Priority Issues Found: 2
Duplicates Detected: 0 (all similar functions serve different domains)
Identified Issues
1.⚠️ Misplaced Function: TruncateSessionID
Priority: 🔴 HIGH
Impact: Medium - Code organization and discoverability
Problem
TruncateSessionID()function is defined ininternal/auth/header.gobut is exclusively used by the logger package (internal/server/sdk_logging.go, 7 occurrences). This violates the principle of placing functions close to their usage.Current Location
Usage Analysis
All 7 calls are in
internal/server/sdk_logging.go:Evidence
Recommendation
Move
TruncateSessionIDtointernal/logger/sanitize/sanitize.goBenefits:
TruncateSecret()(same purpose, different length)Implementation Steps:
internal/auth/header.gotointernal/logger/sanitize/sanitize.gointernal/server/sdk_logging.go:auth.TruncateSessionID→sanitize.TruncateSessionID💡 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.