summaryrefslogtreecommitdiff
path: root/internal/hexaicli/run_more_test.go
blob: ae2956346f0b44be448dc7b7d9c44cf8f88399cd (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
package hexaicli

import (
    "bytes"
    "context"
    "testing"

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

type streamClient struct{}

func (streamClient) Chat(ctx context.Context, msgs []llm.Message, opts ...llm.RequestOption) (string, error) {
    return "X", nil
}
func (streamClient) Name() string         { return "fake" }
func (streamClient) DefaultModel() string { return "m" }
func (streamClient) ChatStream(ctx context.Context, msgs []llm.Message, onDelta func(string), opts ...llm.RequestOption) error {
    onDelta("A")
    onDelta("B")
    return nil
}

func TestRunChat_Streaming(t *testing.T) {
    var out, errw bytes.Buffer
    input := "hello"
    msgs := []llm.Message{{Role: "user", Content: input}}
    if err := runChat(context.Background(), streamClient{}, msgs, input, &out, &errw); err != nil {
        t.Fatalf("runChat failed: %v", err)
    }
    if out.String() != "AB" {
        t.Fatalf("unexpected stream output: %q", out.String())
    }
}

func TestBuildMessagesFromConfig(t *testing.T) {
    cfg := appconfig.App{PromptCLIDefaultSystem: "DEF", PromptCLIExplainSystem: "EXP"}
    msgs := buildMessagesFromConfig(cfg, "tell me")
    if msgs[0].Content != "DEF" { t.Fatalf("default system wrong: %q", msgs[0].Content) }
    msgs = buildMessagesFromConfig(cfg, "please explain")
    if msgs[0].Content != "EXP" { t.Fatalf("explain system wrong: %q", msgs[0].Content) }
}