test: improve internal/compact coverage from 17% to 82% (bd-thgk)
Add comprehensive unit tests for the compact package: - haiku.go: Mock API tests for SummarizeTier1, retry logic tests for callWithRetry (429/500 handling, exhaust retries, context timeout), expanded isRetryable tests for network timeouts and API error codes - git.go: Tests for GetCurrentCommitHash in various git states (in repo, outside repo, new repo, empty repo) - compactor.go: Unit tests for New(), CompactTier1(), CompactTier1Batch() with mock API server, config validation, error paths Small production change: NewHaikuClient now accepts variadic options for testing (option.WithBaseURL, option.WithMaxRetries). Coverage: 17.3% → 81.8% 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -38,7 +38,7 @@ type HaikuClient struct {
|
||||
}
|
||||
|
||||
// NewHaikuClient creates a new Haiku API client. Env var ANTHROPIC_API_KEY takes precedence over explicit apiKey.
|
||||
func NewHaikuClient(apiKey string) (*HaikuClient, error) {
|
||||
func NewHaikuClient(apiKey string, opts ...option.RequestOption) (*HaikuClient, error) {
|
||||
envKey := os.Getenv("ANTHROPIC_API_KEY")
|
||||
if envKey != "" {
|
||||
apiKey = envKey
|
||||
@@ -47,7 +47,10 @@ func NewHaikuClient(apiKey string) (*HaikuClient, error) {
|
||||
return nil, fmt.Errorf("%w: set ANTHROPIC_API_KEY environment variable or provide via config", ErrAPIKeyRequired)
|
||||
}
|
||||
|
||||
client := anthropic.NewClient(option.WithAPIKey(apiKey))
|
||||
// Build options: API key first, then any additional options (for testing)
|
||||
allOpts := []option.RequestOption{option.WithAPIKey(apiKey)}
|
||||
allOpts = append(allOpts, opts...)
|
||||
client := anthropic.NewClient(allOpts...)
|
||||
|
||||
tier1Tmpl, err := template.New("tier1").Parse(tier1PromptTemplate)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user