diff options
| author | Paul Buetow <paul@buetow.org> | 2025-09-04 14:24:36 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-09-04 14:24:36 +0300 |
| commit | d68e5b3b188585fe234d0ce295ec7f054c8bad5f (patch) | |
| tree | 974e067d9894f0da38513acdc27b56729b0f06e4 /internal/lsp/chat_history_test.go | |
| parent | 3c322b7046669a77c276ce05469bfc2db0b446b2 (diff) | |
tests(lsp): push coverage over 80%\n- Add init/trigger, chat history, document handler, transport readMessage, and rewrite resolve tests\n- Cover deferShowDocument and shutdown reply\n- Now ~81.2% coverage for internal/lsp
Diffstat (limited to 'internal/lsp/chat_history_test.go')
| -rw-r--r-- | internal/lsp/chat_history_test.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/internal/lsp/chat_history_test.go b/internal/lsp/chat_history_test.go new file mode 100644 index 0000000..0e9fed5 --- /dev/null +++ b/internal/lsp/chat_history_test.go @@ -0,0 +1,27 @@ +package lsp + +import "testing" + +func TestStripTrailingTrigger(t *testing.T) { + if got := stripTrailingTrigger("what?"); got != "what" { t.Fatalf("should remove trailing ?") } + if got := stripTrailingTrigger("what?>"); got != "what?" { t.Fatalf("should drop trailing > when preceded by ?") } + if got := stripTrailingTrigger("ok!>"); got != "ok!" { t.Fatalf("should drop > after !") } + if got := stripTrailingTrigger("note:>"); got != "note:" { t.Fatalf("should drop > after :") } + if got := stripTrailingTrigger("go;>"); got != "go;" { t.Fatalf("should drop > after ;") } +} + +func TestBuildChatHistory_OrderAndLimit(t *testing.T) { + s := newTestServer() + uri := "file:///chat.txt" + // Conversation: q1, > a1, blank, q2, > a2 lines, then current prompt + doc := "q1\n> a1\n\nq2\n> a2\n\n" + s.setDocument(uri, doc) + msgs := s.buildChatHistory(uri, 5, "q3") + // Expect: user q1, assistant a1, user q2, assistant a2, user q3 + if len(msgs) != 5 || msgs[0].Role != "user" || msgs[1].Role != "assistant" || msgs[2].Role != "user" || msgs[3].Role != "assistant" || msgs[4].Role != "user" { + t.Fatalf("unexpected roles: %+v", msgs) + } + if msgs[0].Content != "q1" || msgs[1].Content != "a1" || msgs[2].Content != "q2" || msgs[3].Content != "a2" || msgs[4].Content != "q3" { + t.Fatalf("unexpected contents: %+v", msgs) + } +} |
