diff options
| author | Paul Buetow <paul@buetow.org> | 2025-09-06 11:57:45 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-09-06 11:57:45 +0300 |
| commit | a48079fae6bb19d7c931f275901670cd5839ab5c (patch) | |
| tree | 5788a3e8cac34ffca9d39b0c4b5df720e869b578 /internal/lsp/codeaction_prompts_test.go | |
| parent | fb267966f7840df222338f57023273a993a73c9a (diff) | |
chore(version): bump to 0.6.0; configurable prompts via config + testsv0.6.0
Diffstat (limited to 'internal/lsp/codeaction_prompts_test.go')
| -rw-r--r-- | internal/lsp/codeaction_prompts_test.go | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/internal/lsp/codeaction_prompts_test.go b/internal/lsp/codeaction_prompts_test.go new file mode 100644 index 0000000..6b2ce8c --- /dev/null +++ b/internal/lsp/codeaction_prompts_test.go @@ -0,0 +1,102 @@ +package lsp + +import ( + "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) + } +} + +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) + } +} + +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) + } +} + +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) + } +} + |
