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
|
package lsp
import (
"context"
"testing"
"codeberg.org/snonux/hexai/internal/appconfig"
"codeberg.org/snonux/hexai/internal/llm"
"codeberg.org/snonux/hexai/internal/runtimeconfig"
)
func TestPromptSetUsesConfigStoreSnapshot(t *testing.T) {
s := newTestServer()
initial := appconfig.App{CoreConfig: appconfig.CoreConfig{MaxTokens: 77}}
store := runtimeconfig.New(initial)
s.configStore = store
got := s.promptSet()
if got.MaxTokens != 77 {
t.Fatalf("expected initial snapshot, got %+v", got)
}
updated := initial
updated.MaxTokens = 42
store.Set(updated)
got = s.promptSet()
if got.MaxTokens != 42 {
t.Fatalf("expected updated snapshot, got %+v", got)
}
}
func TestChatConfigRespectsExplicitEmptySuffix(t *testing.T) {
s := newTestServer()
cfg := s.cfg
cfg.ChatSuffix = ""
cfg.ChatPrefixes = []string{"#"}
s.cfg = cfg
suffix, prefixes, suffixChar := s.chatConfig()
if suffix != "" {
t.Fatalf("expected explicit empty suffix, got %q", suffix)
}
if len(prefixes) == 0 || prefixes[0] != "#" {
t.Fatalf("expected custom prefixes, got %v", prefixes)
}
if suffixChar != '>' {
t.Fatalf("expected default suffix char fallback, got %q", suffixChar)
}
}
func TestChatConfigTrimsWhitespaceSuffix(t *testing.T) {
s := newTestServer()
cfg := s.cfg
cfg.ChatSuffix = " >> "
s.cfg = cfg
suffix, _, suffixChar := s.chatConfig()
if suffix != ">>" {
t.Fatalf("expected trimmed suffix '>>', got %q", suffix)
}
if suffixChar != '>' {
t.Fatalf("expected suffixChar to use trimmed value, got %q", suffixChar)
}
}
type stubLLMClient struct{}
func (stubLLMClient) Chat(context.Context, []llm.Message, ...llm.RequestOption) (string, error) {
return "", nil
}
func (stubLLMClient) Name() string { return "stub" }
func (stubLLMClient) DefaultModel() string { return "stub-model" }
func TestServerApplyOptions(t *testing.T) {
s := newTestServer()
client := stubLLMClient{}
cfg := appconfig.App{CoreConfig: appconfig.CoreConfig{MaxTokens: 88}}
opts := ServerOptions{Config: &cfg, Client: client}
s.ApplyOptions(opts)
if s.currentLLMClient() != client {
t.Fatalf("expected client to be replaced")
}
if got := s.currentConfig().MaxTokens; got != 88 {
t.Fatalf("expected config to update, got %d", got)
}
}
func TestServerStoreAndTakePendingCompletion(t *testing.T) {
s := newTestServer()
items := []CompletionItem{{Label: "foo"}}
s.storePendingCompletion("key", items)
if len(s.pendingCompletions) != 1 {
t.Fatalf("expected pending map to be populated")
}
items[0].Label = "bar" // ensure copy stored
got := s.takePendingCompletion("key")
if len(got) != 1 || got[0].Label != "foo" {
t.Fatalf("expected preserved copy of completion, got %+v", got)
}
if len(s.pendingCompletions) != 0 {
t.Fatalf("expected pending map to be cleared after take")
}
}
|