Debian Codegraph @

internal/providers/openairesponses/openairesponses_test.go

raw
1 package openairesponses_test
2
3 import (
4 "context"
5 "encoding/json"
6 "errors"
7 "io"
8 "net/http"
9 "net/http/httptest"
10 "strings"
11 "testing"
12
13 "github.com/clnkr-ai/clnkr"
14 "github.com/clnkr-ai/clnkr/internal/providers/openairesponses"
15 )
16
17 const (
18 checkEvidence = "go test ./... passed and ls output showed current directory entries for completion"
19 canonicalDone = `{"type":"done","summary":"canonical transcript","verification":{"status":"verified","checks":[{"command":"go test ./...","outcome":"passed","evidence":"` + checkEvidence + `"}]},"known_risks":[]}`
20 providerDone = `{"turn":{"type":"done","bash":null,"question":null,"summary":"canonical transcript","verification":{"status":"verified","checks":[{"command":"go test ./...","outcome":"passed","evidence":"` + checkEvidence + `"}]},"known_risks":[],"reasoning":null}}`
21 )
22
23 func TestModelQueryUsesResponsesStructuredRequest(t *testing.T) {
24 var gotBody map[string]any
25 var gotPath string
26 server := captureServer(t, &gotBody, func(w http.ResponseWriter, r *http.Request) {
27 gotPath = r.URL.Path
28 writeJSON(
29 t,
30 w,
31 responseWithText(
32 11,
33 7,
34 `{"turn":{"type":"done","summary":"hello`,
35 ` back","verification":{"status":"verified","checks":[{"command":"go test ./...","outcome":"passed","evidence":"`+checkEvidence+`"}]},"known_risks":[],"reasoning":null}}`,
36 ),
37 )
38 })
39 defer server.Close()
40
41 model := openairesponses.NewModel(server.URL+"/v1", "test-key", "gpt-5", "sys prompt")
42 resp, err := model.Query(
43 context.Background(),
44 []clnkr.Message{{Role: "user", Content: "hello"}},
45 )
46 if err != nil {
47 t.Fatalf("Query: %v", err)
48 }
49
50 if gotPath != "/v1/responses" {
51 t.Fatalf("path = %q, want %q", gotPath, "/v1/responses")
52 }
53 assertNoDefaultOptions(t, gotBody)
54 if got, want := gotBody["instructions"], "sys prompt"; got != want {
55 t.Fatalf("instructions = %#v, want %q", got, want)
56 }
57 assertUserInput(t, inputAt(t, gotBody, 0), "hello")
58 assertStructuredFormat(t, gotBody)
59 if got, want := mustCanonicalTurn(
60 t,
61 resp.Turn,
62 ), canonicalDoneWithSummary(
63 "hello back",
64 ); got != want {
65 t.Fatalf("canonical turn = %q, want %q", got, want)
66 }
67 if resp.ProtocolErr != nil {
68 t.Fatalf("ProtocolErr = %v, want nil", resp.ProtocolErr)
69 }
70 if resp.Usage.InputTokens != 11 || resp.Usage.OutputTokens != 7 {
71 t.Fatalf("usage = %+v, want 11/7", resp.Usage)
72 }
73 }
74
75 func TestModelQueryRetriesTransientServerError(t *testing.T) {
76 attempts := 0
77 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
78 attempts++
79 if attempts == 1 {
80 w.Header().Set("Retry-After", "0")
81 w.WriteHeader(http.StatusBadGateway)
82 writeJSON(
83 t,
84 w,
85 map[string]any{"error": map[string]any{"message": "context deadline exceeded"}},
86 )
87 return
88 }
89 writeJSON(t, w, responseWithText(3, 4, doneTurn("ok")))
90 }))
91 defer server.Close()
92
93 model := openairesponses.NewModel(server.URL, "test-key", "gpt-test", "system")
94 resp, err := model.Query(
95 context.Background(),
96 []clnkr.Message{{Role: "user", Content: "finish"}},
97 )
98 if err != nil {
99 t.Fatalf("Query: %v", err)
100 }
101 if attempts != 2 {
102 t.Fatalf("attempts = %d, want 2", attempts)
103 }
104 if got, want := mustCanonicalTurn(t, resp.Turn), canonicalDoneWithSummary("ok"); got != want {
105 t.Fatalf("canonical turn = %q, want %q", got, want)
106 }
107 }
108
109 func TestModelQueryDoesNotRetryBadRequest(t *testing.T) {
110 attempts := 0
111 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
112 attempts++
113 w.WriteHeader(http.StatusBadRequest)
114 writeJSON(t, w, map[string]any{"error": map[string]any{"message": "bad request"}})
115 }))
116 defer server.Close()
117
118 model := openairesponses.NewModel(server.URL, "test-key", "gpt-test", "system")
119 _, err := model.Query(context.Background(), []clnkr.Message{{Role: "user", Content: "finish"}})
120 if err == nil {
121 t.Fatal("Query succeeded, want bad request error")
122 }
123 if attempts != 1 {
124 t.Fatalf("attempts = %d, want 1", attempts)
125 }
126 if got, want := err.Error(), "api error (status 400): bad request"; got != want {
127 t.Fatalf("error = %q, want %q", got, want)
128 }
129 }
130
131 func TestModelClassifiesContextLengthErrors(t *testing.T) {
132 tests := []struct {
133 name string
134 message string
135 }{
136 {
137 name: "context length exceeded code",
138 message: "context_length_exceeded",
139 },
140 {
141 name: "maximum context length",
142 message: "This model's maximum context length is 128000 tokens. However, your messages resulted in 130000 tokens.",
143 },
144 {
145 name: "context length",
146 message: "Request exceeds context length.",
147 },
148 }
149
150 for _, tt := range tests {
151 t.Run(tt.name, func(t *testing.T) {
152 server := httptest.NewServer(
153 http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
154 w.WriteHeader(http.StatusBadRequest)
155 writeJSON(t, w, map[string]any{
156 "error": map[string]any{"message": tt.message},
157 })
158 }),
159 )
160 defer server.Close()
161
162 model := openairesponses.NewModel(server.URL, "test-key", "gpt-test", "sys")
163 _, err := model.Query(
164 context.Background(),
165 []clnkr.Message{{Role: "user", Content: "hi"}},
166 )
167 if !errors.Is(err, clnkr.ErrContextLengthExceeded) {
168 t.Fatalf("Query error = %v, want ErrContextLengthExceeded", err)
169 }
170 if err == nil || !strings.Contains(err.Error(), tt.message) {
171 t.Fatalf("Query error = %v, want provider message %q", err, tt.message)
172 }
173 })
174 }
175 }
176
177 func TestModelClassifiesContextLengthErrorCodeWithoutMessage(t *testing.T) {
178 server := httptest.NewServer(
179 http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
180 w.WriteHeader(http.StatusBadRequest)
181 writeJSON(t, w, map[string]any{
182 "error": map[string]any{"code": "context_length_exceeded"},
183 })
184 }),
185 )
186 defer server.Close()
187
188 model := openairesponses.NewModel(server.URL, "test-key", "gpt-test", "sys")
189 _, err := model.Query(context.Background(), []clnkr.Message{{Role: "user", Content: "hi"}})
190 if !errors.Is(err, clnkr.ErrContextLengthExceeded) {
191 t.Fatalf("Query error = %v, want ErrContextLengthExceeded", err)
192 }
193 if err == nil || !strings.Contains(err.Error(), "context_length_exceeded") {
194 t.Fatalf("Query error = %v, want error code", err)
195 }
196 }
197
198 func TestModelClassifiesFailedResponseContextLengthError(t *testing.T) {
199 server := httptest.NewServer(
200 http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
201 writeJSON(t, w, map[string]any{
202 "status": "failed",
203 "error": map[string]any{
204 "code": "context_length_exceeded",
205 "message": "Your input exceeds the context window of this model.",
206 },
207 })
208 }),
209 )
210 defer server.Close()
211
212 model := openairesponses.NewModel(server.URL, "test-key", "gpt-test", "sys")
213 _, err := model.Query(context.Background(), []clnkr.Message{{Role: "user", Content: "hi"}})
214 if !errors.Is(err, clnkr.ErrContextLengthExceeded) {
215 t.Fatalf("Query error = %v, want ErrContextLengthExceeded", err)
216 }
217 if err == nil || !strings.Contains(err.Error(), "context_length_exceeded") {
218 t.Fatalf("Query error = %v, want error code", err)
219 }
220 }
221
222 func TestModelQueryJoinsBaseURLPath(t *testing.T) {
223 tests := []struct {
224 name string
225 baseURLSuffix string
226 wantPath string
227 wantRawQuery string
228 wantEscapedPath string
229 }{
230 {name: "trailing slash", baseURLSuffix: "/v1/", wantPath: "/v1/responses"},
231 {
232 name: "preserves internal repeated slashes",
233 baseURLSuffix: "/proxy//v1/",
234 wantPath: "/proxy//v1/responses",
235 },
236 {
237 name: "keeps query on base URL",
238 baseURLSuffix: "/v1/?token=abc",
239 wantPath: "/v1/responses",
240 wantRawQuery: "token=abc",
241 },
242 {
243 name: "preserves escaped slash",
244 baseURLSuffix: "/proxy%2Fv1/",
245 wantPath: "/proxy/v1/responses",
246 wantEscapedPath: "/proxy%2Fv1/responses",
247 },
248 }
249
250 for _, tt := range tests {
251 t.Run(tt.name, func(t *testing.T) {
252 var gotPath, gotRawQuery, gotEscapedPath string
253 server := httptest.NewServer(
254 http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
255 gotPath = r.URL.Path
256 gotRawQuery = r.URL.RawQuery
257 gotEscapedPath = r.URL.EscapedPath()
258 writeJSON(t, w, responseWithText(0, 0, doneTurn("ok")))
259 }),
260 )
261 defer server.Close()
262
263 model := openairesponses.NewModel(
264 server.URL+tt.baseURLSuffix,
265 "test-key",
266 "gpt-5",
267 "sys prompt",
268 )
269 if _, err := model.Query(
270 context.Background(),
271 []clnkr.Message{{Role: "user", Content: "hello"}},
272 ); err != nil {
273 t.Fatalf("Query: %v", err)
274 }
275 if gotPath != tt.wantPath {
276 t.Fatalf("path = %q, want %q", gotPath, tt.wantPath)
277 }
278 if gotRawQuery != tt.wantRawQuery {
279 t.Fatalf("raw query = %q, want %q", gotRawQuery, tt.wantRawQuery)
280 }
281 if tt.wantEscapedPath != "" && gotEscapedPath != tt.wantEscapedPath {
282 t.Fatalf("escaped path = %q, want %q", gotEscapedPath, tt.wantEscapedPath)
283 }
284 })
285 }
286 }
287
288 func TestModelQuerySerializesProviderRequestOptions(t *testing.T) {
289 var gotBody map[string]any
290 server := captureServer(t, &gotBody, func(w http.ResponseWriter, r *http.Request) {
291 writeJSON(t, w, responseWithText(0, 0, doneTurn("ok")))
292 })
293 defer server.Close()
294
295 model := openairesponses.NewModelWithOptions(
296 server.URL,
297 "test-key",
298 "gpt-5.1",
299 "sys",
300 openairesponses.Options{
301 ReasoningEffort: "high",
302 MaxOutputTokens: 8000,
303 HasMaxOutputTokens: true,
304 },
305 )
306 if _, err := model.Query(
307 context.Background(),
308 []clnkr.Message{{Role: "user", Content: "hi"}},
309 ); err != nil {
310 t.Fatalf("Query: %v", err)
311 }
312
313 reasoning, ok := gotBody["reasoning"].(map[string]any)
314 if !ok {
315 t.Fatalf("reasoning = %#v, want object", gotBody["reasoning"])
316 }
317 if got, want := reasoning["effort"], "high"; got != want {
318 t.Fatalf("reasoning.effort = %#v, want %q", got, want)
319 }
320 if got, want := gotBody["max_output_tokens"], float64(8000); got != want {
321 t.Fatalf("max_output_tokens = %#v, want %v", got, want)
322 }
323 }
324
325 func TestModelQueryRejectsContradictoryStructuredTurn(t *testing.T) {
326 content := `{"turn":{"type":"done","bash":{"commands":[{"command":"rm -rf tmp","workdir":null}]},"question":null,"summary":"done","reasoning":null}}`
327 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
328 writeJSON(t, w, responseWithText(11, 7, content))
329 }))
330 defer server.Close()
331
332 model := openairesponses.NewModel(server.URL, "test-key", "gpt-test", "sys")
333 resp, err := model.Query(
334 context.Background(),
335 []clnkr.Message{{Role: "user", Content: "hello"}},
336 )
337 if err != nil {
338 t.Fatalf("Query: %v", err)
339 }
340 if resp.Raw != content {
341 t.Fatalf("Raw = %q, want %q", resp.Raw, content)
342 }
343 if !errors.Is(resp.ProtocolErr, clnkr.ErrInvalidJSON) {
344 t.Fatalf("ProtocolErr = %v, want ErrInvalidJSON", resp.ProtocolErr)
345 }
346 }
347
348 func TestModelQueriesNormalizeAssistantHistory(t *testing.T) {
349 history := []clnkr.Message{
350 {Role: "user", Content: "first task"},
351 {Role: "assistant", Content: canonicalDone},
352 }
353 tests := []struct {
354 name string
355 query func(*openairesponses.Model) error
356 want string
357 }{
358 {
359 name: "structured",
360 query: func(model *openairesponses.Model) error {
361 _, err := model.Query(context.Background(), history)
362 return err
363 },
364 want: doneTurn("ok"),
365 },
366 {
367 name: "text",
368 query: func(model *openairesponses.Model) error {
369 summary, err := model.QueryText(context.Background(), history)
370 if summary != "Older work summarized." {
371 t.Fatalf("summary = %q, want %q", summary, "Older work summarized.")
372 }
373 return err
374 },
375 want: "Older work summarized.",
376 },
377 }
378
379 for _, tt := range tests {
380 t.Run(tt.name, func(t *testing.T) {
381 var gotBody map[string]any
382 server := captureServer(t, &gotBody, func(w http.ResponseWriter, r *http.Request) {
383 writeJSON(t, w, responseWithText(9, 4, tt.want))
384 })
385 defer server.Close()
386
387 model := openairesponses.NewModel(server.URL, "test-key", "gpt-5", "sys prompt")
388 if err := tt.query(model); err != nil {
389 t.Fatalf("query: %v", err)
390 }
391 if tt.name == "text" {
392 if _, ok := gotBody["text"]; ok {
393 t.Fatalf("text should be omitted for QueryText, got %#v", gotBody["text"])
394 }
395 assertNoDefaultOptions(t, gotBody)
396 }
397 assertUserInput(t, inputAt(t, gotBody, 0), "first task")
398 assertAssistantInput(t, inputAt(t, gotBody, 1), "msg_prev_1")
399 })
400 }
401 }
402
403 func TestModelQueriesReturnRefusalError(t *testing.T) {
404 tests := []struct {
405 name string
406 query func(*openairesponses.Model) error
407 wantError string
408 }{
409 {
410 name: "structured",
411 query: func(model *openairesponses.Model) error {
412 _, err := model.Query(
413 context.Background(),
414 []clnkr.Message{{Role: "user", Content: "hello"}},
415 )
416 return err
417 },
418 wantError: "structured output refusal: refused",
419 },
420 {
421 name: "text",
422 query: func(model *openairesponses.Model) error {
423 _, err := model.QueryText(
424 context.Background(),
425 []clnkr.Message{{Role: "user", Content: "hello"}},
426 )
427 return err
428 },
429 wantError: "free-form refusal: refused",
430 },
431 }
432
433 for _, tt := range tests {
434 t.Run(tt.name, func(t *testing.T) {
435 server := httptest.NewServer(
436 http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
437 writeJSON(t, w, responseWithRefusal("refused"))
438 }),
439 )
440 defer server.Close()
441
442 model := openairesponses.NewModel(server.URL, "test-key", "gpt-5", "sys prompt")
443 err := tt.query(model)
444 if err == nil {
445 t.Fatal("expected refusal error")
446 }
447 if !strings.Contains(err.Error(), tt.wantError) {
448 t.Fatalf("error = %q, want %q", err.Error(), tt.wantError)
449 }
450 })
451 }
452 }
453
454 func TestModelQueryErrorsOnMissingOutputText(t *testing.T) {
455 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
456 writeJSON(
457 t,
458 w,
459 map[string]any{
460 "output": []map[string]any{
461 {"type": "message", "role": "assistant", "content": []map[string]any{}},
462 },
463 },
464 )
465 }))
466 defer server.Close()
467
468 model := openairesponses.NewModel(server.URL, "test-key", "gpt-5", "sys prompt")
469 _, err := model.Query(context.Background(), []clnkr.Message{{Role: "user", Content: "hello"}})
470 if err == nil {
471 t.Fatal("expected missing output_text error")
472 }
473 if err.Error() != "no usable output_text in response" {
474 t.Fatalf("error = %q, want %q", err.Error(), "no usable output_text in response")
475 }
476 }
477
478 func captureServer(
479 t *testing.T,
480 gotBody *map[string]any,
481 handler func(http.ResponseWriter, *http.Request),
482 ) *httptest.Server {
483 t.Helper()
484 return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
485 body, err := io.ReadAll(r.Body)
486 if err != nil {
487 t.Fatalf("ReadAll: %v", err)
488 }
489 if err := json.Unmarshal(body, gotBody); err != nil {
490 t.Fatalf("Unmarshal request: %v", err)
491 }
492 handler(w, r)
493 }))
494 }
495
496 func writeJSON(t *testing.T, w http.ResponseWriter, v any) {
497 t.Helper()
498 if err := json.NewEncoder(w).Encode(v); err != nil {
499 t.Fatalf("Encode response: %v", err)
500 }
501 }
502
503 func responseWithText(inputTokens, outputTokens int, texts ...string) map[string]any {
504 content := make([]map[string]any, 0, len(texts))
505 for _, text := range texts {
506 content = append(content, map[string]any{"type": "output_text", "text": text})
507 }
508 return map[string]any{
509 "output": []map[string]any{{"type": "message", "role": "assistant", "content": content}},
510 "usage": map[string]any{"input_tokens": inputTokens, "output_tokens": outputTokens},
511 }
512 }
513
514 func responseWithRefusal(refusal string) map[string]any {
515 return map[string]any{"output": []map[string]any{{
516 "type": "message", "role": "assistant",
517 "content": []map[string]any{{"type": "refusal", "refusal": refusal}},
518 }}}
519 }
520
521 func doneTurn(summary string) string {
522 return `{"turn":{"type":"done","summary":"` + summary + `","verification":{"status":"verified","checks":[{"command":"go test ./...","outcome":"passed","evidence":"` + checkEvidence + `"}]},"known_risks":[],"reasoning":null}}`
523 }
524
525 func canonicalDoneWithSummary(summary string) string {
526 return `{"type":"done","summary":"` + summary + `","verification":{"status":"verified","checks":[{"command":"go test ./...","outcome":"passed","evidence":"` + checkEvidence + `"}]},"known_risks":[]}`
527 }
528
529 func input(t *testing.T, body map[string]any) []any {
530 t.Helper()
531 got, ok := body["input"].([]any)
532 if !ok {
533 t.Fatalf("input = %#v, want array", body["input"])
534 }
535 return got
536 }
537
538 func inputAt(t *testing.T, body map[string]any, i int) map[string]any {
539 t.Helper()
540 messages := input(t, body)
541 if len(messages) <= i {
542 t.Fatalf("input = %#v, want index %d", messages, i)
543 }
544 msg, ok := messages[i].(map[string]any)
545 if !ok {
546 t.Fatalf("input[%d] = %#v, want map", i, messages[i])
547 }
548 return msg
549 }
550
551 func contentAt(t *testing.T, msg map[string]any, i int) map[string]any {
552 t.Helper()
553 content, ok := msg["content"].([]any)
554 if !ok || len(content) <= i {
555 t.Fatalf("content = %#v, want index %d", msg["content"], i)
556 }
557 item, ok := content[i].(map[string]any)
558 if !ok {
559 t.Fatalf("content[%d] = %#v, want map", i, content[i])
560 }
561 return item
562 }
563
564 func assertUserInput(t *testing.T, msg map[string]any, text string) {
565 t.Helper()
566 if got, want := msg["role"], "user"; got != want {
567 t.Fatalf("user role = %#v, want %q", got, want)
568 }
569 if got, want := msg["type"], "message"; got != want {
570 t.Fatalf("user type = %#v, want %q", got, want)
571 }
572 item := contentAt(t, msg, 0)
573 if got, want := item["type"], "input_text"; got != want {
574 t.Fatalf("user content type = %#v, want %q", got, want)
575 }
576 if got := item["text"]; got != text {
577 t.Fatalf("user text = %#v, want %q", got, text)
578 }
579 if _, ok := item["annotations"]; ok {
580 t.Fatalf("user annotations = %#v, want omitted", item["annotations"])
581 }
582 }
583
584 func assertAssistantInput(t *testing.T, msg map[string]any, id string) {
585 t.Helper()
586 if got, want := msg["type"], "message"; got != want {
587 t.Fatalf("assistant type = %#v, want %q", got, want)
588 }
589 if got := msg["id"]; got != id {
590 t.Fatalf("assistant id = %#v, want %q", got, id)
591 }
592 if got, want := msg["role"], "assistant"; got != want {
593 t.Fatalf("assistant role = %#v, want %q", got, want)
594 }
595 if got, want := msg["status"], "completed"; got != want {
596 t.Fatalf("assistant status = %#v, want %q", got, want)
597 }
598 item := contentAt(t, msg, 0)
599 if got, want := item["type"], "output_text"; got != want {
600 t.Fatalf("assistant content type = %#v, want %q", got, want)
601 }
602 if got := item["text"]; got != providerDone {
603 t.Fatalf("assistant text = %#v, want %q", got, providerDone)
604 }
605 annotations, ok := item["annotations"].([]any)
606 if !ok || len(annotations) != 0 {
607 t.Fatalf("assistant annotations = %#v, want empty array", item["annotations"])
608 }
609 }
610
611 func assertNoDefaultOptions(t *testing.T, body map[string]any) {
612 t.Helper()
613 if _, ok := body["reasoning"]; ok {
614 t.Fatalf("reasoning = %#v, want omitted by default", body["reasoning"])
615 }
616 if _, ok := body["max_output_tokens"]; ok {
617 t.Fatalf("max_output_tokens = %#v, want omitted by default", body["max_output_tokens"])
618 }
619 }
620
621 func assertStructuredFormat(t *testing.T, body map[string]any) {
622 t.Helper()
623 text, ok := body["text"].(map[string]any)
624 if !ok {
625 t.Fatalf("text = %#v, want map", body["text"])
626 }
627 format, ok := text["format"].(map[string]any)
628 if !ok {
629 t.Fatalf("text.format = %#v, want map", text["format"])
630 }
631 for key, want := range map[string]any{"type": "json_schema", "name": "agent_turn", "strict": true} {
632 if got := format[key]; got != want {
633 t.Fatalf("text.format.%s = %#v, want %#v", key, got, want)
634 }
635 }
636 if _, ok := format["schema"].(map[string]any); !ok {
637 t.Fatalf("text.format.schema = %#v, want schema object", format["schema"])
638 }
639 }
640
641 func assertBashTool(t *testing.T, raw any) {
642 t.Helper()
643 tool, ok := raw.(map[string]any)
644 if !ok {
645 t.Fatalf("tool = %#v, want object", raw)
646 }
647 if tool["type"] != "function" || tool["name"] != "bash" || tool["strict"] != true {
648 t.Fatalf("tool = %#v, want strict bash function", tool)
649 }
650 params := tool["parameters"].(map[string]any)
651 if params["additionalProperties"] != false {
652 t.Fatalf("additionalProperties = %#v, want false", params["additionalProperties"])
653 }
654 required := params["required"].([]any)
655 if len(required) != 2 || required[0] != "command" || required[1] != "workdir" {
656 t.Fatalf("required = %#v, want command/workdir", required)
657 }
658 }
659
660 func mustCanonicalTurn(t *testing.T, turn clnkr.Turn) string {
661 t.Helper()
662
663 raw, err := clnkr.CanonicalTurnJSON(turn)
664 if err != nil {
665 t.Fatalf("CanonicalTurnJSON: %v", err)
666 }
667 return raw
668 }