summaryrefslogtreecommitdiff
path: root/internal/hexaiaction/run_test.go
blob: 87fbfa83d81377ecd3013cd736724d3104b1e9e9 (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
44
45
46
47
48
49
50
51
package hexaiaction

import (
    "context"
    "strings"
    "testing"

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

type fakeDoer struct{ out string }

func (f fakeDoer) Chat(_ context.Context, _ []llm.Message, _ ...llm.RequestOption) (string, error) {
    return f.out, nil
}

func TestExecuteAction_Skip(t *testing.T) {
    cfg := appconfig.App{}
    parts := InputParts{Selection: "data"}
    out, err := executeAction(context.Background(), ActionSkip, parts, cfg, fakeDoer{"IGN"}, nil)
    if err != nil || out != "data" {
        t.Fatalf("skip failed: %q %v", out, err)
    }
}

func TestExecuteAction_Rewrite_Document_GoTest(t *testing.T) {
    cfg := appconfig.Load(nil) // defaults
    // Use fenced output to exercise StripFences
    client := fakeDoer{"```\nDONE\n```"}

    // rewrite with inline instruction
    sel := ";change;\ncode"
    out, err := executeAction(context.Background(), ActionRewrite, InputParts{Selection: sel}, cfg, client, nil)
    if err != nil || strings.TrimSpace(out) != "DONE" {
        t.Fatalf("rewrite failed: %q %v", out, err)
    }

    // document
    out, err = executeAction(context.Background(), ActionDocument, InputParts{Selection: "code"}, cfg, client, nil)
    if err != nil || strings.TrimSpace(out) != "DONE" {
        t.Fatalf("document failed: %q %v", out, err)
    }

    // go test
    out, err = executeAction(context.Background(), ActionGoTest, InputParts{Selection: "func A(){}"}, cfg, client, nil)
    if err != nil || strings.TrimSpace(out) != "DONE" {
        t.Fatalf("gotest failed: %q %v", out, err)
    }
}