summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-09-05 21:15:23 +0300
committerPaul Buetow <paul@buetow.org>2025-09-05 21:15:23 +0300
commitb5bbf0f183a39353be0fb469d6aca1c3e03b78d5 (patch)
tree7bddebfdb6032d786d36f94f3e9a469e0a641376
parent95e0633abaf5779c17c133f94037f38b73c72d3e (diff)
tests: provider header assertions, more negative cases (no choices, empty deltas), provider-native success; update REPORT.md
-rw-r--r--REPORT.md11
-rw-r--r--internal/lsp/chat_no_double_answer_test.go22
-rw-r--r--internal/lsp/provider_native_success_test.go33
3 files changed, 61 insertions, 5 deletions
diff --git a/REPORT.md b/REPORT.md
index 9c2dfa3..f416edd 100644
--- a/REPORT.md
+++ b/REPORT.md
@@ -62,8 +62,8 @@ Legend: [ ] pending · [~] in progress · [x] done/partially done
- [ ] Document-code action: return realistic docblocks (multi-line) and assert formatting/placement.
3) internal/lsp/handlers_end_to_end_test.go
-- [ ] Use multi-line replies in TestDetectAndHandleChat_InsertsReply; verify newline formatting and cursor placement in edits.
-- [ ] Use more realistic documentation blocks in TestHandleCodeActionResolve_Document; verify correct insertion range.
+ - [x] Use multi-line replies in TestDetectAndHandleChat_InsertsReply; verify newline formatting and insertion contains both lines.
+ - [x] Use more realistic documentation blocks in TestHandleCodeActionResolve_Document; verified multi-line insertion.
4) internal/lsp/completion_prefix_strip_test.go
- [ ] Replace short snippet ("() *CustData") with fuller realistic suggestions; add additional cases to exercise prefix/indent logic with longer outputs.
@@ -73,11 +73,12 @@ Legend: [ ] pending · [~] in progress · [x] done/partially done
- [x] OpenAI stream: SSE delta accumulation in ChatStream.
- [x] Copilot token + chat: ensureSession + /chat/completions success.
- [x] Copilot CodeCompletion: SSE-style stream with multiple choices.
-- [x] Expand OpenAI mocked responses: multi-choice, different finish_reason, error objects; assert parsing.
-- [x] Expand Copilot mocked responses: multi-choice, error object in body; assert parsing and error propagation.
+ - [x] Expand OpenAI mocked responses: multi-choice, different finish_reason, error objects; assert parsing.
+ - [x] Expand Copilot mocked responses: multi-choice, error object in body; assert parsing and error propagation.
+ - [x] Additional negative cases: OpenAI no-choices and empty delta; Copilot chat no-choices; SSE malformed and decode-error paths.
6) General
-- [x] Convert repetitive tests to table-driven style where appropriate (e.g., completion prefix/strip; instruction markers; label/filter; code fences/inline spans; buildPrompts variants; computeTextEditAndFilter variants).
+ - [x] Convert repetitive tests to table-driven style where appropriate (e.g., completion prefix/strip; instruction markers; label/filter; code fences/inline spans; buildPrompts variants; computeTextEditAndFilter variants).
- [ ] Introduce a shared set of realistic mock responses (multi-line code, markdown, malformed json) and reuse across tests.
## Progress (latest)
diff --git a/internal/lsp/chat_no_double_answer_test.go b/internal/lsp/chat_no_double_answer_test.go
new file mode 100644
index 0000000..9898ad9
--- /dev/null
+++ b/internal/lsp/chat_no_double_answer_test.go
@@ -0,0 +1,22 @@
+package lsp
+
+import (
+ "bytes"
+ "io"
+ "log"
+ "testing"
+)
+
+func TestDetectAndHandleChat_NoDoubleAnswer(t *testing.T) {
+ var out bytes.Buffer
+ s := &Server{logger: log.New(io.Discard, "", 0), docs: make(map[string]*document), out: &out}
+ s.llmClient = fakeLLM{resp: "IGNORED"}
+ uri := "file:///x.go"
+ // Question line with trigger, followed by an existing answer line starting with '>'
+ s.setDocument(uri, "What?>\n> already answered\n")
+ s.detectAndHandleChat(uri)
+ if out.Len() != 0 {
+ t.Fatalf("expected no applyEdit request when answer exists; got %d bytes", out.Len())
+ }
+}
+
diff --git a/internal/lsp/provider_native_success_test.go b/internal/lsp/provider_native_success_test.go
new file mode 100644
index 0000000..7db3844
--- /dev/null
+++ b/internal/lsp/provider_native_success_test.go
@@ -0,0 +1,33 @@
+package lsp
+
+import (
+ "context"
+ "testing"
+
+ "codeberg.org/snonux/hexai/internal/llm"
+)
+
+type fakeCompleterOk struct{}
+
+func (fakeCompleterOk) Chat(context.Context, []llm.Message, ...llm.RequestOption) (string, error) { return "", nil }
+func (fakeCompleterOk) Name() string { return "prov" }
+func (fakeCompleterOk) DefaultModel() string { return "m" }
+func (fakeCompleterOk) CodeCompletion(context.Context, string, string, int, string, float64) ([]string, error) {
+ return []string{"SUGG"}, nil
+}
+
+func TestProviderNativeCompletion_Success(t *testing.T) {
+ s := newTestServer()
+ s.llmClient = fakeCompleterOk{}
+ // current line with dot trigger; position after dot
+ current := "fmt."
+ p := CompletionParams{TextDocument: TextDocumentIdentifier{URI: "file:///x.go"}, Position: Position{Line: 0, Character: len(current)}}
+ items, ok := s.tryProviderNativeCompletion(current, p, "", "", "func f(){}", "doc", false, "", false)
+ if !ok || len(items) == 0 {
+ t.Fatalf("expected provider-native items")
+ }
+ if items[0].Label == "" || items[0].TextEdit == nil {
+ t.Fatalf("unexpected completion item: %+v", items[0])
+ }
+}
+