-
Notifications
You must be signed in to change notification settings - Fork 1
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
Summary
Every Drive testable function repeats a 6-line block to resolve the service, extract file_id, validate it's non-empty, and call ExtractGoogleResourceID. This block appears 8 times. Additionally, TestableDriveDownload is 99 lines with an inline readLimited closure and complex MIME type branching that should be decomposed.
Location
- File:
internal/drive/drive_tools_testable.go - Repeated block: L57-66, L78-87, L334-343, L378-387, L419-428, L448-457, L475-484, L522-531 (8 instances)
- Long function:
TestableDriveDownloadL77-175 (99 lines) - Inline closure:
readLimitedL102-112 - Google Workspace MIME mapping: L118-151 (inline magic strings)
Category
Type: DRY Violation / Long Function
Severity: High
Evidence
Repeated 6-line block (8x):
srv, errResult, ok := ResolveDriveServiceOrError(ctx, request, deps)
if !ok { return errResult, nil }
fileID := common.ParseStringArg(request.Params.Arguments, "file_id", "")
if fileID == "" { return mcp.NewToolResultError("file_id parameter is required"), nil }
fileID = common.ExtractGoogleResourceID(fileID)Magic MIME strings (inline):
"application/vnd.google-apps.document"
"application/vnd.google-apps.spreadsheet"
"application/vnd.google-apps.presentation"
"application/vnd.google-apps.folder"Suggested Refactoring
- Extract
resolveFileID(ctx, request, deps) (DriveService, string, *mcp.CallToolResult, bool)helper - Extract
readLimitedas a package-level orcommon/function - Extract Google Workspace MIME-to-export mapping as a constant map
- Split
TestableDriveDownloadinto separate export and download paths
Effort Estimate
- Size: Medium (1-4 hours)
- Risk: Low (internal refactoring only)
- Tests Required: Yes (existing tests must pass)
Acceptance Criteria
-
resolveFileIDhelper eliminates 8 repeated blocks (~40 lines saved) -
readLimitedextracted to reusable function - MIME type mapping extracted to named constant
-
TestableDriveDownloaddecomposed to <50 lines - All existing tests pass
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request