[Repo Assist] refactor: move TruncateSessionID from auth to strutil#6704
Conversation
TruncateSessionID is a string-formatting utility, not an authentication concern. Moving it to internal/strutil/truncate.go gives strutil a single home for all string-shaping utilities and removes an awkward cross-package import from server files that had no other auth logic. Changes: - Add TruncateSessionID to internal/strutil/truncate.go - Remove TruncateSessionID from internal/auth/header.go - Move TestTruncateSessionID from auth to strutil (with full test cases) - Update all call sites in internal/server/ to use strutil.TruncateSessionID - Remove auth import from routed.go, http_helpers.go, session_auto_init.go (these files had no other auth logic) Closes #6499 (Priority 1 recommendation) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR refactors session-ID log formatting by moving TruncateSessionID out of internal/auth and into internal/strutil, reducing unnecessary auth imports in server code and keeping string-shaping utilities co-located.
Changes:
- Added
strutil.TruncateSessionIDand updated server call sites to use it. - Removed
auth.TruncateSessionIDand its tests frominternal/auth. - Updated imports across several
internal/serverfiles to dropauthwhere it was only used for truncation.
Show a summary per file
| File | Description |
|---|---|
| internal/strutil/truncate.go | Adds TruncateSessionID to the shared string utility package. |
| internal/strutil/truncate_test.go | Adds tests for TruncateSessionID (but currently introduces a compile-breaking change in TestTruncateRunes). |
| internal/auth/header.go | Removes TruncateSessionID from auth. |
| internal/auth/header_test.go | Removes TestTruncateSessionID from auth tests. |
| internal/server/session.go | Switches logging from auth.TruncateSessionID to strutil.TruncateSessionID. |
| internal/server/session_auto_init.go | Drops auth import and switches to strutil.TruncateSessionID. |
| internal/server/routed.go | Drops auth import and switches to strutil.TruncateSessionID. |
| internal/server/middleware.go | Adds strutil import and switches to strutil.TruncateSessionID. |
| internal/server/http_helpers.go | Drops auth import and switches to strutil.TruncateSessionID. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 9/9 changed files
- Comments generated: 3
| func TestTruncateRunes(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| input string | ||
| maxRunes int | ||
| expected string | ||
| }{ |
| { | ||
| name: "exactly 8 chars returned as-is", | ||
| sessionID: "abcd1234", | ||
| expected: "abcd1234", | ||
| }, | ||
| { | ||
| name: "long session ID truncated to 8 chars with ellipsis", | ||
| sessionID: "abcdefgh-1234-5678-abcd-ef1234567890", | ||
| expected: "abcdefgh...", | ||
| }, | ||
| } |
| // TruncateSessionID returns a truncated session ID for safe logging (first 8 chars). | ||
| // Returns "(none)" for empty session IDs, and appends "..." for truncated values. | ||
| // This is useful for logging session IDs without exposing sensitive information. |
|
@copilot address review feedback and fix failing ci check https://github.com/github/gh-aw-mcpg/actions/runs/26641339403/job/78520638558?pr=6704 |
Addressed in e66f206. Fixed the malformed |
🤖 This PR was created by Repo Assist, an automated AI assistant.
Moves
TruncateSessionIDfrominternal/auth/header.gotointernal/strutil/truncate.go, where all string-shaping utilities belong.This addresses the Priority 1 refactoring recommendation in #6499.
Root Cause
TruncateSessionIDis a string-formatting utility (first 8 chars +...) that was living insideinternal/auth/header.go. It has no authentication logic — it exists solely for safe log output of session IDs. This causedserverpackage files that only needed this formatting function to unnecessarily import theauthpackage.Changes
internal/strutil/truncate.go— addedTruncateSessionIDinternal/auth/header.go— removedTruncateSessionID(strutil import still needed forRandomHex)internal/auth/header_test.go— removedTestTruncateSessionID(now lives in strutil)internal/strutil/truncate_test.go— added comprehensiveTestTruncateSessionID(ported from auth tests)internal/server/routed.go— auth import removed (only used TruncateSessionID)internal/server/http_helpers.go— auth import removed (only used TruncateSessionID)internal/server/session_auto_init.go— auth import removed (only used TruncateSessionID)internal/server/session.go— auth import kept (still usesExtractSessionID); strutil addedinternal/server/middleware.go— auth import kept (still usesExtractSessionID); strutil addedImpact
authimport entirelystrutilTest Status
go testis blocked in this sandbox (network firewall prevents module downloads). Code was verified via:gofmt -l— no formatting issuesauth.TruncateSessionIDreferences confirmed replacedCloses #6499 (Priority 1 recommendation)
Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
proxy.golang.orgSee Network Configuration for more information.
Add this agentic workflows to your repo
To install this agentic workflow, run