summaryrefslogtreecommitdiff
path: root/internal/hexaiaction/custom_action_test.go
blob: 7bda0adeb478e9d3b4a858f559714ecf031c58de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package hexaiaction

import (
	"bytes"
	"context"
	"testing"

	"codeberg.org/snonux/hexai/internal/appconfig"
	"codeberg.org/snonux/hexai/internal/llm"
)

type llmFake2 struct{}

func (llmFake2) Chat(_ context.Context, _ []llm.Message, _ ...llm.RequestOption) (string, error) {
	return "DONE", nil
}
func (llmFake2) Name() string         { return "fake" }
func (llmFake2) DefaultModel() string { return "m" }

func TestActionCustom_UsesEditorPrompt(t *testing.T) {
	// Isolate from user config that might enable custom menu/TUI.
	t.Setenv("XDG_CONFIG_HOME", t.TempDir())
	// Seam: choose custom, fake client, and fake editor.
	runner := NewRunner()
	runner.chooseAction = func(_ appconfig.App) (actionChoice, error) {
		return actionChoice{kind: ActionCustomPrompt}, nil
	}
	runner.newClient = func(_ appconfig.App) (actionClient, error) { return llmFake2{}, nil }

	runner.openEditor = func(context.Context, []byte) (string, error) {
		return "make it done", nil
	}

	in := bytes.NewBufferString("some code")
	var out bytes.Buffer
	var errb bytes.Buffer
	if err := runner.Run(context.Background(), in, &out, &errb); err != nil {
		t.Fatalf("Run: %v", err)
	}
	if out.String() == "" {
		t.Fatalf("expected output")
	}
}