summaryrefslogtreecommitdiff
path: root/internal/hexaicli
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-09-06 13:19:01 +0300
committerPaul Buetow <paul@buetow.org>2025-09-06 13:19:01 +0300
commit04f290dbeeee8a6fcbc70fed253a968336bcb2ab (patch)
tree3ee23a4ac4bcc5b43b43697cfb0e905735fc6331 /internal/hexaicli
parent5e966f50111adf6e2cb2683fe588f6fe033fa931 (diff)
more tests
Diffstat (limited to 'internal/hexaicli')
-rw-r--r--internal/hexaicli/run_more_test.go44
1 files changed, 44 insertions, 0 deletions
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) }
+}
+