45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package pierre
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"git.schreifuchs.ch/schreifuchs/pierre-bot/internal/chatter"
|
|
)
|
|
|
|
type overlapChat struct{ callCount int }
|
|
|
|
func (m *overlapChat) GenerateStructured(ctx context.Context, msgs []chatter.Message, target interface{}) error {
|
|
m.callCount++
|
|
if cSlice, ok := target.(*[]Comment); ok {
|
|
// Return two comments with same file and line to test deduplication
|
|
*cSlice = []Comment{{File: "dup.go", Line: 10, Message: "first"}, {File: "dup.go", Line: 10, Message: "second"}}
|
|
return nil
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (m *overlapChat) GetProviderName() string { return "mock" }
|
|
|
|
func TestJudgePR_DeduplicationOverlap(t *testing.T) {
|
|
chat := &overlapChat{}
|
|
svc := &Service{
|
|
maxChunkSize: 1000,
|
|
guidelines: nil,
|
|
git: &mockGit{},
|
|
chat: chat,
|
|
}
|
|
diffReader, err := svc.git.GetDiff(context.Background(), "", "", 0)
|
|
if err != nil {
|
|
t.Fatalf("failed to get diff: %v", err)
|
|
}
|
|
defer diffReader.Close()
|
|
comments, err := svc.judgePR(context.Background(), diffReader)
|
|
if err != nil {
|
|
t.Fatalf("judgePR error: %v", err)
|
|
}
|
|
if len(comments) != 1 {
|
|
t.Fatalf("expected 1 deduplicated comment, got %d", len(comments))
|
|
}
|
|
}
|