Skip to content

refactor: extract testable packages and increase coverage to 70%#19

Merged
tawanorg merged 5 commits intomainfrom
feat/increase-test-coverage
Apr 1, 2026
Merged

refactor: extract testable packages and increase coverage to 70%#19
tawanorg merged 5 commits intomainfrom
feat/increase-test-coverage

Conversation

@tawanorg
Copy link
Copy Markdown
Owner

@tawanorg tawanorg commented Mar 31, 2026

Summary

Refactors cmd/claude-sync/main.go to extract testable business logic and adds comprehensive tests to reach 70.7% coverage on library packages (up from ~24%).

Changes

  • Extract helpers to internal/util/TruncatePath, FormatSize, CompareVersions, GetBinaryName moved from monolithic main.go to a focused, 96.4% covered package
  • Add NewSyncerWith constructor — dependency-injected Syncer for testing without cloud credentials
  • Add 15+ Syncer operation tests — Push, Pull, Status, GetState, HasState, SetProgressFunc, PushMCP, PullMCP, MCPStatus, gzip round-trip
  • Update CI coverage check — measures library packages only (excludes cloud provider adapters that need real credentials), 60% threshold

Coverage Results

Package Before After
internal/util (new) N/A 96.4%
internal/storage 87.5% 87.5%
internal/crypto 78.9% 78.9%
internal/config 74.6% 74.6%
internal/sync 51.5% 67.4%
Library total ~57% 70.7%

Commits

  1. test: increase test coverage from 21.6% to 24.3% — initial config/state tests
  2. refactor: extract helpers to internal/util package — move pure functions out of main.go
  3. feat: add NewSyncerWith for dependency-injected testing — testable Syncer constructor
  4. test: add comprehensive Syncer operation tests — Push/Pull/Status/MCP/gzip tests
  5. ci: add coverage threshold check on library packages — CI enforcement at 60%

@tawanorg tawanorg changed the title test: increase test coverage from 21.6% to 24.3% refactor: extract testable packages and increase coverage to 70% Mar 31, 2026
tawanorg added 5 commits April 1, 2026 10:19
Add unit tests for previously uncovered functions:

- cmd/claude-sync: truncatePath, formatSize, compareVersions, getBinaryName
- internal/config: ClaudeJSONPath, GetStorageConfig, IsLegacyConfig
- internal/sync/state: IsEmpty, GetMCPBaseline, SetMCPBaseline, Save/Load
Move truncatePath, formatSize, compareVersions, and getBinaryName from
cmd/claude-sync/main.go to internal/util/format.go as exported functions.
Add comprehensive table-driven tests in internal/util/format_test.go.
Add tests for Push, Pull, Status, State, MCP sync, and gzip operations
covering Tasks 3-7 of the test coverage initiative.
Measure coverage on internal/ packages (excluding cloud provider
adapters that require real credentials). Set 60% threshold with
current coverage at 70.7%.
@tawanorg tawanorg force-pushed the feat/increase-test-coverage branch from 1b3899b to 1d5742b Compare March 31, 2026 23:20
@tawanorg tawanorg merged commit b2bff7f into main Apr 1, 2026
2 checks passed
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 1, 2026

🎉 This PR is included in version 1.8.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant