refactor: Phase 5 code cleanliness improvements#77
Conversation
Create internal/format package with shared formatting utilities: - Truncate(s, maxLen): shorten strings with ellipsis - Size(bytes): human-readable file sizes (KB, MB, GB, etc.) Updated consumers: - internal/cmd/mail/labels.go (truncate → format.Truncate) - internal/cmd/mail/attachments_list.go (formatSize → format.Size) - internal/cmd/mail/attachments_download.go (formatSize → format.Size) - internal/cmd/drive/list.go (formatSize → format.Size) - internal/cmd/drive/download.go (formatSize → formatpkg.Size) - internal/cmd/drive/get.go (formatSize → format.Size) Closes #49 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add file and directory permission constants to internal/config: - DirPerm (0700): config directories - TokenPerm (0600): token files - OutputDirPerm (0755): output directories - OutputFilePerm (0644): output files Updated consumers: - internal/config/config.go (uses DirPerm) - internal/keychain/keychain.go (uses DirPerm, TokenPerm) Closes #48 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add clarifying comments for intentionally ignored errors: - internal/auth/auth.go: Close error on read operation - internal/zip/extract.go: Best-effort cleanup on size limit violation - internal/cmd/drive/list.go: Write errors to stdout (func comment) Note: keychain.go already had comments explaining its ignored errors. Closes #47 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Test Coverage AssessmentSummaryThe test coverage for this PR is adequate. The refactoring consolidates duplicate code into shared packages with appropriate test coverage. Analysis by Change Category1. New
|
| Old Location | Old Tests | New Location | New Tests |
|---|---|---|---|
mail/attachments_test.go |
8 size cases | format/format_test.go |
8 size cases |
drive/list_test.go |
8 size cases | format/format_test.go |
8 size cases |
mail/labels_test.go |
4 truncate cases | format/format_test.go |
6 truncate cases |
The new tests cover all previously tested scenarios plus additional edge cases.
Verdict
Approve - Test coverage is appropriate for a refactoring PR:
- New code has 100% coverage
- Behavioral equivalence is maintained (with minor improvement to
Truncate) - All tests pass
- No gaps in critical paths
The test plan items from the PR description are satisfied:
- All existing tests pass
- Linting passes
- New
internal/formatpackage has comprehensive tests - File permission constants are documented
Summary
This PR implements Phase 5 code cleanliness improvements from the codebase simplification plan:
Shared format utilities (refactor: move utility functions to shared package for reuse #49): Create
internal/formatpackage withTruncate()andSize()functions, consolidating 4 duplicate implementations across mail and drive packages.File permission constants (refactor: consolidate scattered hard-coded constants #48): Add
DirPerm,TokenPerm,OutputDirPerm,OutputFilePermconstants tointernal/configpackage for consistent file permissions.Documented ignored errors (fix: document or handle intentionally ignored errors #47): Add clarifying comments for intentionally ignored errors (file close on read, best-effort cleanup).
Error message audit (fix: standardize error message formatting across codebase #46): Audited all
fmt.Errorfcalls - messages already comply with Go conventions (lowercase, no trailing punctuation). The embedded instructions in auth error messages ("please run 'gro init' first") are appropriate for CLI UX.Test plan
make test)make lint)internal/formatpackage has comprehensive testsCloses #46, #47, #48, #49
🤖 Generated with Claude Code