From 04f290dbeeee8a6fcbc70fed253a968336bcb2ab Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 6 Sep 2025 13:19:01 +0300 Subject: more tests --- internal/hexaicli/run_more_test.go | 44 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 internal/hexaicli/run_more_test.go (limited to 'internal/hexaicli') diff --git a/internal/hexaicli/run_more_test.go b/internal/hexaicli/run_more_test.go new file mode 100644 index 0000000..ae29563 --- /dev/null +++ b/internal/hexaicli/run_more_test.go @@ -0,0 +1,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) } +} + -- cgit v1.2.3