| 1 | package agent |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | func TestResponseFormatContextRoundTrip(t *testing.T) { |
| 9 | ctx := WithResponseFormat(context.Background(), "json_object") |
| 10 | if got := responseFormatFromContext(ctx); got != "json_object" { |
| 11 | t.Fatalf("format = %q, want json_object", got) |
| 12 | } |
| 13 | // Empty format is a no-op: context stays byte-identical (nil read). |
| 14 | if got := responseFormatFromContext(WithResponseFormat(ctx, " ")); got != "json_object" { |
| 15 | t.Fatalf("empty format must be ignored, got %q", got) |
| 16 | } |
| 17 | if got := responseFormatFromContext(context.Background()); got != "" { |
| 18 | t.Fatalf("default ctx format = %q, want empty", got) |
| 19 | } |
| 20 | if got := responseFormatFromRequest(ctx); got == nil || got.Type != "json_object" { |
| 21 | t.Fatalf("request format = %#v, want json_object", got) |
| 22 | } |
| 23 | if got := responseFormatFromRequest(context.Background()); got != nil { |
| 24 | t.Fatalf("request format must be nil on plain ctx, got %#v", got) |
| 25 | } |
| 26 | } |
| 27 |