summaryrefslogtreecommitdiff
path: root/internal/executor/gemini_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/executor/gemini_test.go')
-rw-r--r--internal/executor/gemini_test.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/internal/executor/gemini_test.go b/internal/executor/gemini_test.go
index 073525c..4b0339e 100644
--- a/internal/executor/gemini_test.go
+++ b/internal/executor/gemini_test.go
@@ -1,6 +1,7 @@
package executor
import (
+ "bytes"
"context"
"io"
"log/slog"
@@ -144,3 +145,35 @@ func TestGeminiRunner_BinaryPath_Custom(t *testing.T) {
t.Errorf("want custom path, got %q", r.binaryPath())
}
}
+
+
+func TestParseGeminiStream_ParsesStructuredOutput(t *testing.T) {
+ // Simulate a stream-json input with various message types, including a result with error and cost.
+ input := streamLine(`{"type":"content_block_start","content_block":{"text":"Hello,"}}`) +
+ streamLine(`{"type":"content_block_delta","content_block":{"text":" World!"}}`) +
+ streamLine(`{"type":"content_block_end"}`) +
+ streamLine(`{"type":"result","subtype":"error_during_execution","is_error":true,"result":"something went wrong","total_cost_usd":0.123}`)
+
+ reader := strings.NewReader(input)
+ var writer bytes.Buffer // To capture what's written to the output log
+ logger := slog.New(slog.NewTextHandler(io.Discard, nil))
+
+ cost, err := parseGeminiStream(reader, &writer, logger)
+
+ if err == nil {
+ t.Errorf("expected an error, got nil")
+ }
+ if !strings.Contains(err.Error(), "something went wrong") {
+ t.Errorf("expected error message to contain 'something went wrong', got: %v", err)
+ }
+
+ if cost != 0.123 {
+ t.Errorf("expected cost 0.123, got %f", cost)
+ }
+
+ // Verify that the writer received the content (even if parseGeminiStream isn't fully parsing it yet)
+ expectedWriterContent := input
+ if writer.String() != expectedWriterContent {
+ t.Errorf("writer content mismatch:\nwant:\n%s\ngot:\n%s", expectedWriterContent, writer.String())
+ }
+}