Fix lint errors: handle errors, use fmt.Fprintf, apply De Morgan's law, use switch statements
Amp-Thread-ID: https://ampcode.com/threads/T-afcf56b0-a8bc-4310-bb59-1b63e1d70c89 Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
@@ -13,18 +13,21 @@ const (
|
||||
defaultConcurrency = 5
|
||||
)
|
||||
|
||||
// CompactConfig holds configuration for the compaction process.
|
||||
type CompactConfig struct {
|
||||
APIKey string
|
||||
Concurrency int
|
||||
DryRun bool
|
||||
}
|
||||
|
||||
// Compactor handles issue compaction using AI summarization.
|
||||
type Compactor struct {
|
||||
store *sqlite.SQLiteStorage
|
||||
haiku *HaikuClient
|
||||
config *CompactConfig
|
||||
}
|
||||
|
||||
// New creates a new Compactor instance with the given configuration.
|
||||
func New(store *sqlite.SQLiteStorage, apiKey string, config *CompactConfig) (*Compactor, error) {
|
||||
if config == nil {
|
||||
config = &CompactConfig{
|
||||
@@ -58,6 +61,7 @@ func New(store *sqlite.SQLiteStorage, apiKey string, config *CompactConfig) (*Co
|
||||
}, nil
|
||||
}
|
||||
|
||||
// CompactResult holds the outcome of a compaction operation.
|
||||
type CompactResult struct {
|
||||
IssueID string
|
||||
OriginalSize int
|
||||
@@ -65,6 +69,7 @@ type CompactResult struct {
|
||||
Err error
|
||||
}
|
||||
|
||||
// CompactTier1 performs tier-1 compaction on a single issue using AI summarization.
|
||||
func (c *Compactor) CompactTier1(ctx context.Context, issueID string) error {
|
||||
if ctx.Err() != nil {
|
||||
return ctx.Err()
|
||||
@@ -137,6 +142,7 @@ func (c *Compactor) CompactTier1(ctx context.Context, issueID string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// CompactTier1Batch performs tier-1 compaction on multiple issues in a single batch.
|
||||
func (c *Compactor) CompactTier1Batch(ctx context.Context, issueIDs []string) ([]*CompactResult, error) {
|
||||
if len(issueIDs) == 0 {
|
||||
return nil, nil
|
||||
|
||||
@@ -298,11 +298,12 @@ func TestCompactTier1Batch_WithIneligible(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, result := range results {
|
||||
if result.IssueID == openIssue.ID {
|
||||
switch result.IssueID {
|
||||
case openIssue.ID:
|
||||
if result.Err == nil {
|
||||
t.Error("expected error for ineligible issue")
|
||||
}
|
||||
} else if result.IssueID == closedIssue.ID {
|
||||
case closedIssue.ID:
|
||||
if result.Err != nil {
|
||||
t.Errorf("unexpected error for eligible issue: %v", result.Err)
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ const (
|
||||
initialBackoff = 1 * time.Second
|
||||
)
|
||||
|
||||
// ErrAPIKeyRequired is returned when an API key is needed but not provided.
|
||||
var ErrAPIKeyRequired = errors.New("API key required")
|
||||
|
||||
// HaikuClient wraps the Anthropic API for issue summarization.
|
||||
|
||||
@@ -193,7 +193,7 @@ func TestCallWithRetry_ContextCancellation(t *testing.T) {
|
||||
|
||||
_, err = client.callWithRetry(ctx, "test prompt")
|
||||
if err == nil {
|
||||
t.Fatal("expected error when context is cancelled")
|
||||
t.Fatal("expected error when context is canceled")
|
||||
}
|
||||
if err != context.Canceled {
|
||||
t.Errorf("expected context.Canceled error, got: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user