From bef02f9f9908c65fea5472f04e534a5fba577502 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Thu, 4 Sep 2025 08:21:18 +0300 Subject: tests: quick wins to raise coverage - internal/logging >90% - internal/hexaicli >90% - keep next targets: internal/lsp, internal/llm --- internal/hexaicli/testhelpers_test.go | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'internal/hexaicli/testhelpers_test.go') diff --git a/internal/hexaicli/testhelpers_test.go b/internal/hexaicli/testhelpers_test.go index 97b531d..1f75916 100644 --- a/internal/hexaicli/testhelpers_test.go +++ b/internal/hexaicli/testhelpers_test.go @@ -2,12 +2,13 @@ package hexaicli import ( - "context" - "os" - "path/filepath" - "testing" + "context" + "encoding/json" + "os" + "path/filepath" + "testing" - "codeberg.org/snonux/hexai/internal/llm" + "codeberg.org/snonux/hexai/internal/llm" ) // setStdin sets os.Stdin from a string and returns a restore func and reader. @@ -54,9 +55,21 @@ type fakeStreamer struct { } 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 +} + +// small JSON writer for tests +func writeJSON(t *testing.T, path string, v any) { + t.Helper() + if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil { t.Fatalf("mkdir: %v", err) } + f, err := os.Create(path) + if err != nil { t.Fatalf("create: %v", err) } + defer f.Close() + if err := json.NewEncoder(f).Encode(v); err != nil { t.Fatalf("encode: %v", err) } } + +func testingTempDir(t *testing.T) string { t.Helper(); return t.TempDir() } -- cgit v1.2.3