summaryrefslogtreecommitdiff
path: root/internal/hexaicli
diff options
context:
space:
mode:
Diffstat (limited to 'internal/hexaicli')
-rw-r--r--internal/hexaicli/run_test.go3
-rw-r--r--internal/hexaicli/testhelpers_test.go75
2 files changed, 37 insertions, 41 deletions
diff --git a/internal/hexaicli/run_test.go b/internal/hexaicli/run_test.go
index f9c8443..377b224 100644
--- a/internal/hexaicli/run_test.go
+++ b/internal/hexaicli/run_test.go
@@ -1,5 +1,4 @@
// Summary: Unit tests for Hexai CLI helpers and run flow (input parsing, messages, streaming).
-// Not yet reviewed by a human
package hexaicli
import (
@@ -9,8 +8,6 @@ import (
"testing"
)
-// helpers moved to testhelpers_test.go
-
func TestReadInput_ArgsOnly(t *testing.T) {
restore, f := setStdin(t, "")
defer restore()
diff --git a/internal/hexaicli/testhelpers_test.go b/internal/hexaicli/testhelpers_test.go
index 4a25ff1..bd3c3dd 100644
--- a/internal/hexaicli/testhelpers_test.go
+++ b/internal/hexaicli/testhelpers_test.go
@@ -1,63 +1,62 @@
// Summary: Test helpers for Hexai CLI tests (stdin swapping and fake LLM clients/streamers).
-// Not yet reviewed by a human
package hexaicli
import (
- "context"
- "os"
- "path/filepath"
- "testing"
+ "context"
+ "os"
+ "path/filepath"
+ "testing"
- "hexai/internal/llm"
+ "hexai/internal/llm"
)
// setStdin sets os.Stdin from a string and returns a restore func and reader.
func setStdin(t *testing.T, content string) (func(), *os.File) {
- t.Helper()
- tmpDir := t.TempDir()
- fpath := filepath.Join(tmpDir, "stdin.txt")
- if err := os.WriteFile(fpath, []byte(content), 0o600); err != nil {
- t.Fatalf("write temp stdin: %v", err)
- }
- f, err := os.Open(fpath)
- if err != nil {
- t.Fatalf("open temp stdin: %v", err)
- }
- old := os.Stdin
- os.Stdin = f
- restore := func() {
- f.Close()
- os.Stdin = old
- }
- return restore, f
+ t.Helper()
+ tmpDir := t.TempDir()
+ fpath := filepath.Join(tmpDir, "stdin.txt")
+ if err := os.WriteFile(fpath, []byte(content), 0o600); err != nil {
+ t.Fatalf("write temp stdin: %v", err)
+ }
+ f, err := os.Open(fpath)
+ if err != nil {
+ t.Fatalf("open temp stdin: %v", err)
+ }
+ old := os.Stdin
+ os.Stdin = f
+ restore := func() {
+ f.Close()
+ os.Stdin = old
+ }
+ return restore, f
}
// fakeClient implements llm.Client for tests.
type fakeClient struct {
- name string
- model string
- resp string
- gotMsgs []llm.Message
+ name string
+ model string
+ resp string
+ gotMsgs []llm.Message
}
func (f *fakeClient) Chat(ctx context.Context, messages []llm.Message, opts ...llm.RequestOption) (string, error) {
- f.gotMsgs = append([]llm.Message{}, messages...)
- return f.resp, nil
+ f.gotMsgs = append([]llm.Message{}, messages...)
+ return f.resp, nil
}
-func (f fakeClient) Name() string { return f.name }
+func (f fakeClient) Name() string { return f.name }
func (f fakeClient) DefaultModel() string { return f.model }
// fakeStreamer implements llm.Streamer over fakeClient.
type fakeStreamer struct {
- fakeClient
- chunks []string
- sMsgs []llm.Message
+ fakeClient
+ chunks []string
+ sMsgs []llm.Message
}
func (s *fakeStreamer) ChatStream(ctx context.Context, messages []llm.Message, onDelta func(string), opts ...llm.RequestOption) error {
- s.sMsgs = append([]llm.Message{}, messages...)
- for _, c := range s.chunks {
- onDelta(c)
- }
- return nil
+ s.sMsgs = append([]llm.Message{}, messages...)
+ for _, c := range s.chunks {
+ onDelta(c)
+ }
+ return nil
}