fix: AI discussions going back instead of preparing
This commit is contained in:
55
tui_test.go
55
tui_test.go
@@ -856,6 +856,61 @@ func TestVimModeAppliesToEveryTextInput(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestVimAIDiscussionSubmitDuringRefreshPreservesDraft(t *testing.T) {
|
||||
config := defaultAIConfig()
|
||||
config.Enabled = true
|
||||
settings := defaultAppSettings()
|
||||
settings.AI = &AIController{config: config}
|
||||
m := NewAppWithSettings(nil, "o", "r", false, 50, time.Second, settings)
|
||||
m.screen, m.loading, m.width, m.height = threadScreen, true, 80, 24
|
||||
m.details = PRDetails{
|
||||
HeadOID: "head",
|
||||
Threads: []ReviewThread{{ID: "thread", Path: "main.go"}},
|
||||
}
|
||||
m.aiMode, m.writeThreadID, m.aiInput = aiDiscussion, "thread", "Keep this question"
|
||||
m.resetInputEditor(&m.aiInputEditor, m.aiInput)
|
||||
|
||||
updated, command, handled := m.updateAI(tea.KeyMsg{Type: tea.KeyCtrlS})
|
||||
m = updated.(App)
|
||||
if !handled || command == nil || m.aiMode != aiPreparing {
|
||||
t.Fatalf("submit handled=%v command=%v mode=%v", handled, command, m.aiMode)
|
||||
}
|
||||
if m.aiInput != "Keep this question" || m.aiInputEditor.Text != m.aiInput {
|
||||
t.Fatalf("AI discussion draft changed during submit: input=%q editor=%q",
|
||||
m.aiInput, m.aiInputEditor.Text)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAIDiscussionPreparationFailurePreservesDraft(t *testing.T) {
|
||||
m := NewApp(nil, "o", "r", false, 50, time.Second)
|
||||
m.aiMode, m.writeThreadID, m.aiInput = aiPreparing, "thread", "Keep this question"
|
||||
m.resetInputEditor(&m.aiInputEditor, m.aiInput)
|
||||
|
||||
updated, command, handled := m.updateAI(aiPreparedMsg{
|
||||
threadID: "thread", err: errors.New("prepare failed"),
|
||||
})
|
||||
m = updated.(App)
|
||||
if !handled || command != nil || m.aiMode != aiDiscussion || m.err == nil {
|
||||
t.Fatalf("failure handled=%v command=%v mode=%v err=%v",
|
||||
handled, command, m.aiMode, m.err)
|
||||
}
|
||||
if m.aiInput != "Keep this question" || m.aiInputEditor.Text != m.aiInput {
|
||||
t.Fatalf("AI discussion draft lost after failure: input=%q editor=%q",
|
||||
m.aiInput, m.aiInputEditor.Text)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPullRequestAIPreparationFailureIgnoresOldDiscussionThread(t *testing.T) {
|
||||
m := NewApp(nil, "o", "r", false, 50, time.Second)
|
||||
m.aiMode, m.writeThreadID = aiPreparing, "old-thread"
|
||||
|
||||
updated, _, _ := m.updateAI(aiPreparedMsg{err: errors.New("prepare failed")})
|
||||
m = updated.(App)
|
||||
if m.aiMode != aiMenu {
|
||||
t.Fatalf("pull-request preparation failure returned to mode %v, want AI menu", m.aiMode)
|
||||
}
|
||||
}
|
||||
|
||||
func TestVimModeUsesGlobalFooterBar(t *testing.T) {
|
||||
m := NewApp(nil, "o", "r", false, 50, time.Second)
|
||||
m.width, m.height = 80, 10
|
||||
|
||||
Reference in New Issue
Block a user