Skip to content

refactor: Phase 5 code cleanliness improvements#77

Merged
rianjs merged 3 commits intomainfrom
refactor/phase5-cleanliness
Jan 26, 2026
Merged

refactor: Phase 5 code cleanliness improvements#77
rianjs merged 3 commits intomainfrom
refactor/phase5-cleanliness

Conversation

@rianjs
Copy link
Copy Markdown
Contributor

@rianjs rianjs commented Jan 26, 2026

Summary

This PR implements Phase 5 code cleanliness improvements from the codebase simplification plan:

Test plan

  • All existing tests pass (make test)
  • Linting passes (make lint)
  • New internal/format package has comprehensive tests
  • File permission constants are documented

Closes #46, #47, #48, #49

🤖 Generated with Claude Code

rianjs and others added 3 commits January 25, 2026 19:20
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>
@rianjs
Copy link
Copy Markdown
Contributor Author

rianjs commented Jan 26, 2026

Test Coverage Assessment

Summary

The test coverage for this PR is adequate. The refactoring consolidates duplicate code into shared packages with appropriate test coverage.

Analysis by Change Category

1. New internal/format Package

Coverage: 100% - Excellent

The new format.Truncate() and format.Size() functions have comprehensive tests covering:

  • Edge cases (zero, empty string)
  • Boundary conditions (exact length, minimum truncation)
  • Various size units (B, KB, MB, GB, TB)
  • Small maxLen handling (minimum enforced to 4)

Note: The new Truncate implementation differs slightly from the old one - when maxLen < 4, it now enforces a minimum of 4 rather than returning just "...". This is actually an improvement in behavior consistency and the tests document this.

2. Permission Constants (internal/config)

Coverage: Indirect - Acceptable

The new constants (DirPerm, TokenPerm, OutputDirPerm, OutputFilePerm) are simple values (0700, 0600, 0755, 0644). The existing test at line 47 already verifies the directory is created with 0700 permissions:

assert.Equal(t, os.FileMode(0700), info.Mode().Perm())

Direct unit tests for constants are low-value - the constants are self-documenting and usage is validated through integration.

3. Documented Ignored Errors

Coverage: N/A - Comment-only changes

Files modified:

  • internal/auth/auth.go: Added comment for ignored file close error
  • internal/cmd/drive/list.go: Added comment for ignored write errors
  • internal/zip/extract.go: Added comment for best-effort cleanup

These are documentation improvements, not behavioral changes. No tests needed.

4. Code Using New Utilities

The following files now use the centralized format package instead of local implementations:

  • internal/cmd/drive/download.go
  • internal/cmd/drive/get.go
  • internal/cmd/drive/list.go
  • internal/cmd/mail/attachments_download.go
  • internal/cmd/mail/attachments_list.go
  • internal/cmd/mail/labels.go

These are import swaps - the underlying formatting logic is now tested in the centralized location.

Test Migration Verification

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/format package has comprehensive tests
  • File permission constants are documented

@rianjs rianjs merged commit e57d8b0 into main Jan 26, 2026
2 checks passed
@rianjs rianjs deleted the refactor/phase5-cleanliness branch January 26, 2026 00:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: standardize error message formatting across codebase

1 participant