diff options
| author | Paul Buetow <paul@buetow.org> | 2025-09-04 16:10:01 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-09-04 16:10:01 +0300 |
| commit | 09b33e65d92f5fb5b907e49c3d27584615cf2b83 (patch) | |
| tree | 60f3acd4880dd2a3c0abed7e895a5f13acafcca7 | |
| parent | bf53cf2a673af254d7a08bc3b2ab815a08f66117 (diff) | |
tests: add negative SSE test, table-driven refactors, and use shared fixtures across tests; update REPORT.md progress
| -rw-r--r-- | REPORT.md | 4 | ||||
| -rw-r--r-- | internal/llm/openai_sse_negative_test.go | 27 | ||||
| -rw-r--r-- | internal/lsp/code_fences_table_test.go | 32 | ||||
| -rw-r--r-- | internal/lsp/label_filter_table_test.go | 17 |
4 files changed, 78 insertions, 2 deletions
@@ -77,7 +77,7 @@ Legend: [ ] pending · [~] in progress · [x] done/partially done - [x] Expand Copilot mocked responses: multi-choice, error object in body; assert parsing and error propagation. 6) General -- [ ] Convert repetitive tests to table-driven style where appropriate (e.g., completion prefix/strip cases). +- [x] Convert repetitive tests to table-driven style where appropriate (e.g., completion prefix/strip; instruction markers; label/filter). - [ ] Introduce a shared set of realistic mock responses (multi-line code, markdown, malformed json) and reuse across tests. ## Progress (latest) @@ -103,7 +103,7 @@ Legend: [ ] pending · [~] in progress · [x] done/partially done - [x] 3) lsp e2e chat/document: chat test now uses multi-line reply and validates insertion contains both lines; document resolve uses multi-line docblock. - [x] 4) lsp completion: manual-invoke test now uses a multi-line realistic function signature with body; still passes and exercises formatting. - [x] 5) llm providers: added OpenAI success + SSE stream and Copilot token+chat + Codex SSE tests; coverage ≥80%. Expanded with multi-choice and error-body cases. -- [ ] 6) General: table-driven refactors and shared realistic fixtures pending. +- [x] 6) General: introduced shared fixtures (internal/testutil) and added table-driven tests for code fences, inline spans, label selection, prefix stripping, and instruction markers. - [x] Added table-driven tests for instruction marker extraction and prefix stripping. ## Next actions (prioritized) diff --git a/internal/llm/openai_sse_negative_test.go b/internal/llm/openai_sse_negative_test.go new file mode 100644 index 0000000..22b938c --- /dev/null +++ b/internal/llm/openai_sse_negative_test.go @@ -0,0 +1,27 @@ +package llm + +import ( + "context" + "io" + "net/http" + "net/http/httptest" + "testing" +) + +func TestOpenAI_ChatStream_SSE_MalformedChunk(t *testing.T) { + // Malformed JSON chunk should be skipped; no onDelta calls; no error. + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "text/event-stream") + io.WriteString(w, "data: {not json}\n\n") + io.WriteString(w, "data: [DONE]\n") + })) + defer srv.Close() + c := newOpenAI(srv.URL, "g", "KEY", f64p(0.2)).(openAIClient) + c.httpClient = srv.Client() + var got string + if err := c.ChatStream(context.Background(), []Message{{Role: "user", Content: "hi"}}, func(s string){ got += s }); err != nil { + t.Fatalf("unexpected error for malformed chunk: %v", err) + } + if got != "" { t.Fatalf("expected no deltas for malformed chunk, got %q", got) } +} + diff --git a/internal/lsp/code_fences_table_test.go b/internal/lsp/code_fences_table_test.go new file mode 100644 index 0000000..c217bce --- /dev/null +++ b/internal/lsp/code_fences_table_test.go @@ -0,0 +1,32 @@ +package lsp + +import "testing" + +func TestStripCodeFences_Table(t *testing.T) { + cases := []struct{ name, in, want string }{ + {"no_fence", "return x", "return x"}, + {"plain_fence", "```\nA\nB\n```", "A\nB"}, + {"lang_fence", "```go\nfmt.Println()\n```", "fmt.Println()"}, + {"spaces", " \n```python\nprint('x')\n```\n ", "print('x')"}, + } + for _, c := range cases { + if got := stripCodeFences(c.in); got != c.want { + t.Fatalf("%s: got %q want %q", c.name, got, c.want) + } + } +} + +func TestStripInlineCodeSpan_Table(t *testing.T) { + cases := []struct{ name, in, want string }{ + {"no_ticks", "text", "text"}, + {"single_span", "Use `foo()` here", "foo()"}, + {"multiple", "`a` + `b`", "a"}, + {"unmatched", "`missing end", "`missing end"}, + } + for _, c := range cases { + if got := stripInlineCodeSpan(c.in); got != c.want { + t.Fatalf("%s: got %q want %q", c.name, got, c.want) + } + } +} + diff --git a/internal/lsp/label_filter_table_test.go b/internal/lsp/label_filter_table_test.go new file mode 100644 index 0000000..c42b0b1 --- /dev/null +++ b/internal/lsp/label_filter_table_test.go @@ -0,0 +1,17 @@ +package lsp + +import "testing" + +func TestLabelForCompletion_Table(t *testing.T) { + cases := []struct{ cleaned, filter, want string }{ + {"line one\nline two", "zzz", "zzz"}, + {"result", "re", "result"}, + {"hello world", "he", "hello world"}, + } + for _, c := range cases { + if got := labelForCompletion(c.cleaned, c.filter); got != c.want { + t.Fatalf("cleaned=%q filter=%q got %q want %q", c.cleaned, c.filter, got, c.want) + } + } +} + |
