Skip to content

Refactor codebase for testability and clean architecture#15

Merged
ChrisJBurns merged 1 commit intomainfrom
refactor-code
Jan 15, 2026
Merged

Refactor codebase for testability and clean architecture#15
ChrisJBurns merged 1 commit intomainfrom
refactor-code

Conversation

@ChrisJBurns
Copy link
Collaborator

Summary

This PR addresses critical architecture and code quality issues identified in a comprehensive code review. The changes improve testability, error handling, and code maintainability.

Critical Architecture Changes

  • Dependency Injection: Added Dependencies struct in main.go to enable testing of orchestration logic
  • Interface Abstractions:
    • PRCreator interface for GitHub client
    • FileReader interface for file operations in GitHub client
    • VersionReader, VersionWriter, YAMLUpdater interfaces for file operations

High Priority Code Quality Fixes

  • Error Handling: updateAllFiles now returns UpdateResult with collected errors instead of silently printing warnings
  • Library Side Effects: Removed fmt.Printf statements from internal/github/pr.go
  • Idiomatic Go: Added IsGreaterE(a, b string) (bool, error) and removed deprecated IsGreater function

Medium Priority Improvements

  • Maintainability: Consolidated regex patterns in yaml.go using replacementRule struct
  • Test Coverage: Added comprehensive unit tests for main.go orchestration

New Files

File Purpose
internal/files/interfaces.go File operation interfaces and default implementations
internal/github/interfaces.go FileReader interface for dependency injection
main_test.go Unit tests for Dependencies, UpdateResult, and orchestration functions

Test Coverage

Package Coverage Change
internal/version 100%
internal/files 80.3%
internal/github 42.6% ↑ from 35%
main 36.1% ↑ from 0%

Test plan

  • All existing tests pass
  • New tests pass
  • go build ./... succeeds
  • golangci-lint run ./... reports 0 issues
  • Manual testing of the GitHub Action (optional)

🤖 Generated with Claude Code

This commit addresses critical architecture and code quality issues identified
in the comprehensive code review:

**Critical Architecture Changes:**
- Add PRCreator interface for GitHub client abstraction
- Add FileReader interface for file operation abstraction
- Add VersionReader, VersionWriter, YAMLUpdater interfaces for file operations
- Implement dependency injection in main.go via Dependencies struct

**High Priority Code Quality Fixes:**
- Fix silent error handling in updateAllFiles - now returns UpdateResult with collected errors
- Remove fmt.Printf side effects from library code (internal/github/pr.go)
- Add proper error-returning IsGreaterE function, remove deprecated IsGreater

**Medium Priority Improvements:**
- Consolidate regex patterns in yaml.go using replacementRule struct
- Add comprehensive unit tests for main.go orchestration functions
- Add tests for WithFileReader option and interface compliance

**New Files:**
- internal/files/interfaces.go - File operation interfaces and default implementations
- internal/github/interfaces.go - FileReader interface for DI
- main_test.go - Unit tests for Dependencies, UpdateResult, and orchestration

**Test Coverage:**
- internal/version: 100%
- internal/files: 80.3%
- internal/github: 42.6% (up from 35%)
- main: 36.1% (up from 0%)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@ChrisJBurns ChrisJBurns merged commit 97baf61 into main Jan 15, 2026
3 checks passed
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.

1 participant