summaryrefslogtreecommitdiff
path: root/internal/lsp/codeaction_prompts_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-09-06 13:18:21 +0300
committerPaul Buetow <paul@buetow.org>2025-09-06 13:18:21 +0300
commit5e966f50111adf6e2cb2683fe588f6fe033fa931 (patch)
tree19ac2033483c2ac6147e8f44ac37f14e6a5c0cf7 /internal/lsp/codeaction_prompts_test.go
parent80e61812986573464cd24c4b3ffa605c4003146a (diff)
fix unit test coverage
Diffstat (limited to 'internal/lsp/codeaction_prompts_test.go')
-rw-r--r--internal/lsp/codeaction_prompts_test.go171
1 files changed, 85 insertions, 86 deletions
diff --git a/internal/lsp/codeaction_prompts_test.go b/internal/lsp/codeaction_prompts_test.go
index 6b2ce8c..bbfad10 100644
--- a/internal/lsp/codeaction_prompts_test.go
+++ b/internal/lsp/codeaction_prompts_test.go
@@ -1,102 +1,101 @@
package lsp
import (
- "encoding/json"
- "testing"
+ "encoding/json"
+ "testing"
)
func TestResolveCodeAction_UsesRewritePrompts(t *testing.T) {
- s := newTestServer()
- cap := &captureLLM{}
- s.llmClient = cap
- s.promptRewriteSystem = "RSYS"
- s.promptRewriteUser = "RUSER {{instruction}} {{selection}}"
- uri := "file:///x.go"
- s.setDocument(uri, "package p\nvar a=1\n")
- payload := struct {
- Type string `json:"type"`
- URI string `json:"uri"`
- Range Range `json:"range"`
- Instruction string `json:"instruction"`
- Selection string `json:"selection"`
- }{Type: "rewrite", URI: uri, Range: Range{Start: Position{Line: 1}, End: Position{Line: 1, Character: 5}}, Instruction: "do it", Selection: "var a"}
- raw, _ := json.Marshal(payload)
- ca := CodeAction{Title: "Hexai: rewrite selection", Data: raw}
- _, _ = s.resolveCodeAction(ca)
- if len(cap.msgs) < 2 {
- t.Fatalf("expected chat messages")
- }
- if cap.msgs[0].Content != "RSYS" || cap.msgs[1].Role != "user" || cap.msgs[1].Content != "RUSER do it var a" {
- t.Fatalf("unexpected rewrite prompts: %#v", cap.msgs)
- }
+ s := newTestServer()
+ cap := &captureLLM{}
+ s.llmClient = cap
+ s.promptRewriteSystem = "RSYS"
+ s.promptRewriteUser = "RUSER {{instruction}} {{selection}}"
+ uri := "file:///x.go"
+ s.setDocument(uri, "package p\nvar a=1\n")
+ payload := struct {
+ Type string `json:"type"`
+ URI string `json:"uri"`
+ Range Range `json:"range"`
+ Instruction string `json:"instruction"`
+ Selection string `json:"selection"`
+ }{Type: "rewrite", URI: uri, Range: Range{Start: Position{Line: 1}, End: Position{Line: 1, Character: 5}}, Instruction: "do it", Selection: "var a"}
+ raw, _ := json.Marshal(payload)
+ ca := CodeAction{Title: "Hexai: rewrite selection", Data: raw}
+ _, _ = s.resolveCodeAction(ca)
+ if len(cap.msgs) < 2 {
+ t.Fatalf("expected chat messages")
+ }
+ if cap.msgs[0].Content != "RSYS" || cap.msgs[1].Role != "user" || cap.msgs[1].Content != "RUSER do it var a" {
+ t.Fatalf("unexpected rewrite prompts: %#v", cap.msgs)
+ }
}
func TestResolveCodeAction_UsesDiagnosticsPrompts(t *testing.T) {
- s := newTestServer()
- cap := &captureLLM{}
- s.llmClient = cap
- s.promptDiagnosticsSystem = "DSYS"
- s.promptDiagnosticsUser = "DUSER {{diagnostics}} {{selection}}"
- uri := "file:///x.go"
- s.setDocument(uri, "package p\nvar a=1\n")
- payload := struct {
- Type string `json:"type"`
- URI string `json:"uri"`
- Range Range `json:"range"`
- Selection string `json:"selection"`
- Diagnostics []Diagnostic `json:"diagnostics"`
- }{Type: "diagnostics", URI: uri, Range: Range{Start: Position{Line: 1}}, Selection: "var a", Diagnostics: []Diagnostic{{Message: "oops1"}, {Message: "oops2"}}}
- raw, _ := json.Marshal(payload)
- ca := CodeAction{Title: "Hexai: resolve diagnostics", Data: raw}
- _, _ = s.resolveCodeAction(ca)
- if len(cap.msgs) < 2 {
- t.Fatalf("expected chat messages")
- }
- if cap.msgs[0].Content != "DSYS" || cap.msgs[1].Role != "user" {
- t.Fatalf("unexpected diagnostics prompts: %#v", cap.msgs)
- }
- if got := cap.msgs[1].Content; !(contains(got, "oops1") && contains(got, "oops2") && contains(got, "var a")) {
- t.Fatalf("diagnostics/user content mismatch: %q", got)
- }
+ s := newTestServer()
+ cap := &captureLLM{}
+ s.llmClient = cap
+ s.promptDiagnosticsSystem = "DSYS"
+ s.promptDiagnosticsUser = "DUSER {{diagnostics}} {{selection}}"
+ uri := "file:///x.go"
+ s.setDocument(uri, "package p\nvar a=1\n")
+ payload := struct {
+ Type string `json:"type"`
+ URI string `json:"uri"`
+ Range Range `json:"range"`
+ Selection string `json:"selection"`
+ Diagnostics []Diagnostic `json:"diagnostics"`
+ }{Type: "diagnostics", URI: uri, Range: Range{Start: Position{Line: 1}}, Selection: "var a", Diagnostics: []Diagnostic{{Message: "oops1"}, {Message: "oops2"}}}
+ raw, _ := json.Marshal(payload)
+ ca := CodeAction{Title: "Hexai: resolve diagnostics", Data: raw}
+ _, _ = s.resolveCodeAction(ca)
+ if len(cap.msgs) < 2 {
+ t.Fatalf("expected chat messages")
+ }
+ if cap.msgs[0].Content != "DSYS" || cap.msgs[1].Role != "user" {
+ t.Fatalf("unexpected diagnostics prompts: %#v", cap.msgs)
+ }
+ if got := cap.msgs[1].Content; !(contains(got, "oops1") && contains(got, "oops2") && contains(got, "var a")) {
+ t.Fatalf("diagnostics/user content mismatch: %q", got)
+ }
}
func TestResolveCodeAction_UsesDocumentPrompts(t *testing.T) {
- s := newTestServer()
- cap := &captureLLM{}
- s.llmClient = cap
- s.promptDocumentSystem = "DOCSYS"
- s.promptDocumentUser = "DOCUSER {{selection}}"
- uri := "file:///x.go"
- s.setDocument(uri, "package p\nvar a=1\n")
- payload := struct {
- Type string `json:"type"`
- URI string `json:"uri"`
- Range Range `json:"range"`
- Selection string `json:"selection"`
- }{Type: "document", URI: uri, Range: Range{Start: Position{Line: 1}}, Selection: "var a"}
- raw, _ := json.Marshal(payload)
- ca := CodeAction{Title: "Hexai: document selection", Data: raw}
- _, _ = s.resolveCodeAction(ca)
- if len(cap.msgs) < 2 {
- t.Fatalf("expected chat messages")
- }
- if cap.msgs[0].Content != "DOCSYS" || cap.msgs[1].Content != "DOCUSER var a" {
- t.Fatalf("unexpected document prompts: %#v", cap.msgs)
- }
+ s := newTestServer()
+ cap := &captureLLM{}
+ s.llmClient = cap
+ s.promptDocumentSystem = "DOCSYS"
+ s.promptDocumentUser = "DOCUSER {{selection}}"
+ uri := "file:///x.go"
+ s.setDocument(uri, "package p\nvar a=1\n")
+ payload := struct {
+ Type string `json:"type"`
+ URI string `json:"uri"`
+ Range Range `json:"range"`
+ Selection string `json:"selection"`
+ }{Type: "document", URI: uri, Range: Range{Start: Position{Line: 1}}, Selection: "var a"}
+ raw, _ := json.Marshal(payload)
+ ca := CodeAction{Title: "Hexai: document selection", Data: raw}
+ _, _ = s.resolveCodeAction(ca)
+ if len(cap.msgs) < 2 {
+ t.Fatalf("expected chat messages")
+ }
+ if cap.msgs[0].Content != "DOCSYS" || cap.msgs[1].Content != "DOCUSER var a" {
+ t.Fatalf("unexpected document prompts: %#v", cap.msgs)
+ }
}
func TestGenerateGoTest_UsesPrompts(t *testing.T) {
- s := newTestServer()
- cap := &captureLLM{}
- s.llmClient = cap
- s.promptGoTestSystem = "GTSYS"
- s.promptGoTestUser = "GTUSER {{function}}"
- _ = s.generateGoTestFunction("func Add(a,b int) int {return a+b}")
- if len(cap.msgs) < 2 {
- t.Fatalf("expected chat messages")
- }
- if cap.msgs[0].Content != "GTSYS" || !contains(cap.msgs[1].Content, "func Add") {
- t.Fatalf("unexpected gotest prompts: %#v", cap.msgs)
- }
+ s := newTestServer()
+ cap := &captureLLM{}
+ s.llmClient = cap
+ s.promptGoTestSystem = "GTSYS"
+ s.promptGoTestUser = "GTUSER {{function}}"
+ _ = s.generateGoTestFunction("func Add(a,b int) int {return a+b}")
+ if len(cap.msgs) < 2 {
+ t.Fatalf("expected chat messages")
+ }
+ if cap.msgs[0].Content != "GTSYS" || !contains(cap.msgs[1].Content, "func Add") {
+ t.Fatalf("unexpected gotest prompts: %#v", cap.msgs)
+ }
}
-