@@ -2,7 +2,6 @@ package tools_test
22
33import (
44 "net/http"
5- "strings"
65 "testing"
76
87 "github.com/modelcontextprotocol/go-sdk/mcp"
@@ -64,17 +63,7 @@ func Test_SearchChanges(t *testing.T) {
6463
6564 out := callTool (t , cs , "search_changes" , map [string ]any {"query" : "status:open owner:self" })
6665
67- for _ , part := range []string {
68- `<changes query="status:open owner:self"` ,
69- `count="2"` ,
70- `more="true"` ,
71- `<change number="1"` ,
72- `owner="Alice (alice)"` ,
73- `>First</change>` ,
74- `status="MERGED"` ,
75- } {
76- assert .Contains (t , out , part )
77- }
66+ golden (t , "search-changes" , out )
7867
7968 assert .Contains (t , * lastURL , "q=status" )
8069 assert .Contains (t , * lastURL , "n=25" , "default limit applies" )
@@ -95,21 +84,9 @@ func Test_ListChangeFiles(t *testing.T) {
9584
9685 out := callTool (t , cs , "list_change_files" , map [string ]any {"change" : "123" })
9786
98- for _ , part := range []string {
99- `<files change="123" revision="current" count="4">` ,
100- `<file path="/COMMIT_MSG" status="A"` ,
101- `<file path="core/scanner.go" status="M" insertions="5" deletions="2"/>` ,
102- `binary="true"` ,
103- `old_path="core/old.go"` ,
104- } {
105- assert .Contains (t , out , part )
106- }
87+ golden (t , "list-change-files" , out )
10788
10889 assert .Contains (t , * lastURL , "/a/changes/123/revisions/current/files" )
109-
110- logoIdx := strings .Index (out , "assets/logo.png" )
111- scannerIdx := strings .Index (out , "core/scanner.go" )
112- assert .Less (t , logoIdx , scannerIdx , "files sorted by path" )
11390}
11491
11592func Test_GetFileDiff (t * testing.T ) {
@@ -135,16 +112,7 @@ func Test_GetFileDiff(t *testing.T) {
135112 "change" : "123" , "file" : "core/scanner.go" , "revision" : "2" ,
136113 })
137114
138- for _ , part := range []string {
139- `<diff change="123" revision="2" file="core/scanner.go" change_type="MODIFIED">` ,
140- "... 40 common lines skipped ..." ,
141- " func scan() {" ,
142- "-\t old := 1" ,
143- "+\t new := 2" ,
144- "+\t extra := 3" ,
145- } {
146- assert .Contains (t , out , part )
147- }
115+ golden (t , "file-diff-text" , out )
148116
149117 assert .Contains (t , * lastURL , "/a/changes/123/revisions/2/files/core%2Fscanner.go/diff" )
150118 })
@@ -158,8 +126,7 @@ func Test_GetFileDiff(t *testing.T) {
158126
159127 out := callTool (t , cs , "get_file_diff" , map [string ]any {"change" : "123" , "file" : "logo.png" })
160128
161- assert .Contains (t , out , `binary="true"` )
162- assert .Contains (t , out , "/>" )
129+ golden (t , "file-diff-binary" , out )
163130 })
164131}
165132
@@ -194,24 +161,9 @@ func Test_GetChangeComments(t *testing.T) {
194161
195162 out := callTool (t , cs , "get_change_comments" , map [string ]any {"change" : "123" })
196163
197- for _ , part := range []string {
198- `<comments change="123" filter="all" threads="3">` ,
199- `<thread resolved="true">` ,
200- `<thread resolved="false">` ,
201- `<comment id="c1"` ,
202- `in_reply_to="c1"` ,
203- `lines="20-25"` ,
204- "Is this nil-safe?" ,
205- "Orphan reply" ,
206- } {
207- assert .Contains (t , out , part )
208- }
164+ golden (t , "change-comments-all" , out )
209165
210166 assert .Contains (t , * lastURL , "/a/changes/123/comments" )
211-
212- c1 := strings .Index (out , `<comment id="c1"` )
213- c2 := strings .Index (out , `<comment id="c2"` )
214- assert .Less (t , c1 , c2 , "replies follow their root chronologically" )
215167 })
216168
217169 t .Run ("unresolved filter drops resolved threads" , func (t * testing.T ) {
@@ -221,10 +173,7 @@ func Test_GetChangeComments(t *testing.T) {
221173
222174 out := callTool (t , cs , "get_change_comments" , map [string ]any {"change" : "123" , "status" : "unresolved" })
223175
224- assert .Contains (t , out , `threads="1"` )
225- assert .Contains (t , out , "This block races" )
226- assert .NotContains (t , out , "Is this nil-safe?" )
227- assert .NotContains (t , out , "Orphan reply" )
176+ golden (t , "change-comments-unresolved" , out )
228177 })
229178
230179 t .Run ("invalid filter is an error" , func (t * testing.T ) {
0 commit comments