summaryrefslogtreecommitdiff
path: root/internal/hexaiaction/run_more_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/hexaiaction/run_more_test.go')
-rw-r--r--internal/hexaiaction/run_more_test.go79
1 files changed, 79 insertions, 0 deletions
diff --git a/internal/hexaiaction/run_more_test.go b/internal/hexaiaction/run_more_test.go
index 1c0eb51..a3e7f25 100644
--- a/internal/hexaiaction/run_more_test.go
+++ b/internal/hexaiaction/run_more_test.go
@@ -4,7 +4,11 @@ import (
"bytes"
"context"
"os"
+ "strings"
"testing"
+
+ "codeberg.org/snonux/hexai/internal/appconfig"
+ "codeberg.org/snonux/hexai/internal/llm"
)
// Covers the early error path in Run when no API key is available for the default provider.
@@ -23,3 +27,78 @@ func TestRun_MissingAPIKey(t *testing.T) {
}
_ = os.Stderr
}
+
+type stubChatDoer struct {
+ calls int
+ msgs [][]llm.Message
+}
+
+func (s *stubChatDoer) Chat(ctx context.Context, msgs []llm.Message, opts ...llm.RequestOption) (string, error) {
+ s.calls++
+ s.msgs = append(s.msgs, msgs)
+ return "ok", nil
+}
+
+func (s *stubChatDoer) DefaultModel() string { return "stub" }
+
+func TestHandleDiagnosticsActionInvokesLLM(t *testing.T) {
+ t.Setenv("HEXAI_TMUX_STATUS", "0")
+ parts := InputParts{Diagnostics: []string{"warn1"}, Selection: "code"}
+ client := &stubChatDoer{}
+ cfg := appconfig.Load(nil)
+ if _, err := handleDiagnosticsAction(context.Background(), parts, cfg, client); err != nil {
+ t.Fatalf("handleDiagnosticsAction: %v", err)
+ }
+ if client.calls != 1 {
+ t.Fatalf("expected 1 chat call, got %d", client.calls)
+ }
+ found := false
+ for _, msg := range client.msgs[0] {
+ if msg.Role == "user" && strings.Contains(msg.Content, "warn1") {
+ found = true
+ }
+ }
+ if !found {
+ t.Fatalf("expected diagnostics content in message: %#v", client.msgs[0])
+ }
+}
+
+func TestHandleSimplifyActionPassesSelection(t *testing.T) {
+ t.Setenv("HEXAI_TMUX_STATUS", "0")
+ parts := InputParts{Selection: "value := 1"}
+ client := &stubChatDoer{}
+ cfg := appconfig.Load(nil)
+ if _, err := handleSimplifyAction(context.Background(), parts, cfg, client); err != nil {
+ t.Fatalf("handleSimplifyAction: %v", err)
+ }
+ if client.calls != 1 {
+ t.Fatalf("expected single chat invocation, got %d", client.calls)
+ }
+ seen := false
+ for _, msg := range client.msgs[0] {
+ if msg.Role == "user" && strings.Contains(msg.Content, "value := 1") {
+ seen = true
+ }
+ }
+ if !seen {
+ t.Fatalf("expected selection echoed in prompt: %#v", client.msgs[0])
+ }
+}
+
+func TestHandleCustomActionUsesSelectedCustom(t *testing.T) {
+ t.Setenv("HEXAI_TMUX_STATUS", "0")
+ sel := appconfig.CustomAction{ID: "custom", Title: "Do", Instruction: "do it"}
+ selectedCustom = &sel
+ parts := InputParts{Selection: "text"}
+ client := &stubChatDoer{}
+ cfg := appconfig.Load(nil)
+ if _, err := handleCustomAction(context.Background(), parts, cfg, client); err != nil {
+ t.Fatalf("handleCustomAction: %v", err)
+ }
+ if client.calls != 1 {
+ t.Fatalf("expected custom action to invoke chat, got %d calls", client.calls)
+ }
+ if selectedCustom != nil {
+ t.Fatal("expected selectedCustom to be cleared")
+ }
+}