-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommands_chat_test.go
More file actions
127 lines (116 loc) · 2.92 KB
/
Copy pathcommands_chat_test.go
File metadata and controls
127 lines (116 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package main
import (
"strings"
"testing"
)
func TestResolveModel_FlagTakesPrecedence(t *testing.T) {
cfg := runtimeConfig{Model: "default-model"}
got := resolveModel("flag-model", cfg)
if got != "flag-model" {
t.Fatalf("expected flag-model, got %s", got)
}
}
func TestResolveModel_FallsBackToConfig(t *testing.T) {
cfg := runtimeConfig{Model: "config-model"}
got := resolveModel("", cfg)
if got != "config-model" {
t.Fatalf("expected config-model, got %s", got)
}
}
func TestResolveModel_EmptyWhenNoModelSet(t *testing.T) {
cfg := runtimeConfig{}
got := resolveModel("", cfg)
if got != "" {
t.Fatalf("expected empty string, got %s", got)
}
}
// buildFinalPrompt mirrors the prompt construction logic in runPrompt.
// Extracted here for testability.
func buildFinalPrompt(stdinText, argsPrompt string) string {
switch {
case stdinText != "" && strings.TrimSpace(argsPrompt) != "":
return stdinText + "\n\n" + argsPrompt
case stdinText != "":
return stdinText
default:
return argsPrompt
}
}
func TestBuildFinalPrompt_StdinAndArgs(t *testing.T) {
stdin := "This is the file content."
args := "summarize this"
got := buildFinalPrompt(stdin, args)
want := "This is the file content.\n\nsummarize this"
if got != want {
t.Fatalf("expected %q, got %q", want, got)
}
}
func TestBuildFinalPrompt_OnlyStdin(t *testing.T) {
stdin := "What is 2+2?"
got := buildFinalPrompt(stdin, "")
if got != stdin {
t.Fatalf("expected %q, got %q", stdin, got)
}
}
func TestBuildFinalPrompt_OnlyArgs(t *testing.T) {
args := "tell me a joke"
got := buildFinalPrompt("", args)
if got != args {
t.Fatalf("expected %q, got %q", args, got)
}
}
func TestBuildFinalPrompt_StdinWithWhitespaceOnlyArgs(t *testing.T) {
stdin := "What is the capital of France?"
got := buildFinalPrompt(stdin, " ")
// Whitespace-only args should be treated as no args
if got != stdin {
t.Fatalf("expected %q, got %q", stdin, got)
}
}
func TestUseStdinAsText_Conditions(t *testing.T) {
tests := []struct {
name string
stdinIsTTY bool
attachments []string
attachmentType string
attachStdin bool
want bool
}{
{
name: "stdin piped, no flags",
stdinIsTTY: false,
want: true,
},
{
name: "stdin is TTY",
stdinIsTTY: true,
want: false,
},
{
name: "explicit attachment",
stdinIsTTY: false,
attachments: []string{"file.pdf"},
want: false,
},
{
name: "attachment type set",
stdinIsTTY: false,
attachmentType: "image/png",
want: false,
},
{
name: "attachStdin flag",
stdinIsTTY: false,
attachStdin: true,
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := !tt.stdinIsTTY && len(tt.attachments) == 0 && tt.attachmentType == "" && !tt.attachStdin
if got != tt.want {
t.Fatalf("useStdinAsText: expected %v, got %v", tt.want, got)
}
})
}
}