fix QoL and Ai integration
This commit is contained in:
51
ai_test.go
51
ai_test.go
@@ -399,7 +399,7 @@ func TestExistingLocalAIFindingCanGainSuggestion(t *testing.T) {
|
||||
}},
|
||||
}
|
||||
added, _ := state.Apply(
|
||||
PRDetails{}, aiOutput{Findings: []aiFinding{finding}}, "fake", "model", "",
|
||||
PRDetails{}, aiOutput{Findings: []aiFinding{finding}}, "fake", "model", "", "",
|
||||
map[string]map[int]bool{"main.go": {2: true}}, nil, nil,
|
||||
)
|
||||
if added != 0 {
|
||||
@@ -432,7 +432,9 @@ func TestAIStoreSkipsUnchangedWrites(t *testing.T) {
|
||||
func TestWithoutLocalAIDoesNotMutateVisibleDetails(t *testing.T) {
|
||||
remote := ReviewThread{
|
||||
ID: "remote", Comments: []ReviewComment{
|
||||
{ID: "github"}, {ID: "local", Origin: reviewOriginLocalAI},
|
||||
{ID: "github"},
|
||||
{ID: "local", Origin: reviewOriginLocalAI},
|
||||
{ID: "local-user", Origin: reviewOriginLocalAIUser},
|
||||
},
|
||||
}
|
||||
local := ReviewThread{ID: "local-thread", Origin: reviewOriginLocalAI}
|
||||
@@ -441,11 +443,54 @@ func TestWithoutLocalAIDoesNotMutateVisibleDetails(t *testing.T) {
|
||||
if len(clean.Threads) != 1 || len(clean.Threads[0].Comments) != 1 {
|
||||
t.Fatalf("clean details = %#v", clean.Threads)
|
||||
}
|
||||
if len(pr.Threads) != 2 || len(pr.Threads[0].Comments) != 2 {
|
||||
if len(pr.Threads) != 2 || len(pr.Threads[0].Comments) != 3 {
|
||||
t.Fatal("filter mutated the visible PR details")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAIDiscussionStoresUserMessageBeforeProviderResponse(t *testing.T) {
|
||||
state := &aiStoredState{
|
||||
Version: 1, Annotations: make(map[string][]ReviewComment),
|
||||
}
|
||||
pr := PRDetails{Threads: []ReviewThread{{ID: "thread-1"}}}
|
||||
output := aiOutput{ThreadComments: []struct {
|
||||
ThreadID string `json:"thread_id"`
|
||||
Body string `json:"body"`
|
||||
}{{ThreadID: "thread-1", Body: "Provider response"}}}
|
||||
|
||||
_, added := state.Apply(
|
||||
pr, output, "codex", "model", "thread-1", "User follow-up", nil, nil, nil,
|
||||
)
|
||||
comments := state.Annotations["thread-1"]
|
||||
if added != 1 || len(comments) != 2 {
|
||||
t.Fatalf("added=%d comments=%#v", added, comments)
|
||||
}
|
||||
if comments[0].Origin != reviewOriginLocalAIUser ||
|
||||
comments[0].Author != "you" || comments[0].Body != "User follow-up" {
|
||||
t.Fatalf("user message = %#v", comments[0])
|
||||
}
|
||||
if comments[1].Origin != reviewOriginLocalAI ||
|
||||
comments[1].Body != "Provider response" {
|
||||
t.Fatalf("provider response = %#v", comments[1])
|
||||
}
|
||||
}
|
||||
|
||||
func TestAIDiscussionUsesViewerGitHubLogin(t *testing.T) {
|
||||
state := &aiStoredState{
|
||||
Version: 1, Annotations: make(map[string][]ReviewComment),
|
||||
}
|
||||
pr := PRDetails{
|
||||
ViewerLogin: "pablu",
|
||||
Threads: []ReviewThread{{ID: "thread-1"}},
|
||||
}
|
||||
state.Apply(pr, aiOutput{}, "codex", "model", "thread-1", "Follow-up", nil, nil, nil)
|
||||
comments := state.Annotations["thread-1"]
|
||||
if len(comments) != 1 || comments[0].Author != "pablu" ||
|
||||
comments[0].Origin != reviewOriginLocalAIUser {
|
||||
t.Fatalf("local user comment = %#v", comments)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReplyOnLocalAIThreadStartsInlineDiscussion(t *testing.T) {
|
||||
config := defaultAIConfig()
|
||||
config.Enabled = true
|
||||
|
||||
Reference in New Issue
Block a user