test: check request errors and stop asserting PathRewrite on /v1/models

/v1/models is served from config by ServeHTTP (task 2.5) so it never reaches
routing; the rewrite test now uses a non-reserved path.
This commit is contained in:
Story Crater Bot
2026-08-19 23:55:42 -07:00
parent c8c656046a
commit 8feee6754b
9 changed files with 183 additions and 67 deletions
+46 -31
View File
@@ -16,8 +16,8 @@ import (
// OpenAI-style tool definition
type Tool struct {
Type string `json:"type"`
Function ToolFunction `json:"function"`
Type string `json:"type"`
Function ToolFunction `json:"function"`
}
type ToolFunction struct {
@@ -28,21 +28,21 @@ type ToolFunction struct {
// OpenAI chat completion with tools request
type ChatCompletionRequest struct {
Model string `json:"model"`
Messages []Message `json:"messages"`
Tools []Tool `json:"tools,omitempty"`
Stream bool `json:"stream,omitempty"`
Model string `json:"model"`
Messages []Message `json:"messages"`
Tools []Tool `json:"tools,omitempty"`
Stream bool `json:"stream,omitempty"`
}
type Message struct {
Role string `json:"role"`
Content interface{} `json:"content"`
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
Role string `json:"role"`
Content interface{} `json:"content"`
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
}
type ToolCall struct {
ID string `json:"id"`
Type string `json:"type"`
ID string `json:"id"`
Type string `json:"type"`
Function FunctionCall `json:"function"`
}
@@ -64,21 +64,21 @@ func TestToolCallOpenAIStyle(t *testing.T) {
w.WriteHeader(http.StatusOK)
response := map[string]interface{}{
"id": "chatcmpl-123",
"object": "chat.completion",
"model": "reasoning",
"id": "chatcmpl-123",
"object": "chat.completion",
"model": "reasoning",
"choices": []map[string]interface{}{
{
"index": 0,
"message": map[string]interface{}{
"role": "assistant",
"role": "assistant",
"content": nil,
"tool_calls": []map[string]interface{}{
{
"id": "call_abc123",
"id": "call_abc123",
"type": "function",
"function": map[string]interface{}{
"name": "get_weather",
"name": "get_weather",
"arguments": `{"location":"San Francisco","unit":"celsius"}`,
},
},
@@ -372,10 +372,10 @@ func TestToolCallMultiTurn(t *testing.T) {
"content": nil,
"tool_calls": []map[string]interface{}{
{
"id": "call_abc123",
"id": "call_abc123",
"type": "function",
"function": map[string]interface{}{
"name": "get_weather",
"name": "get_weather",
"arguments": `{"location":"San Francisco"}`,
},
},
@@ -430,7 +430,10 @@ func TestToolCallMultiTurn(t *testing.T) {
}
body1, _ := json.Marshal(turn1)
resp1, _ := http.Post(server.URL+"/v1/chat/completions", "application/json", bytes.NewReader(body1))
resp1, err := http.Post(server.URL+"/v1/chat/completions", "application/json", bytes.NewReader(body1))
if err != nil {
t.Fatalf("request failed: %v", err)
}
var turn1Resp map[string]interface{}
json.NewDecoder(resp1.Body).Decode(&turn1Resp)
resp1.Body.Close()
@@ -472,7 +475,10 @@ func TestToolCallMultiTurn(t *testing.T) {
}
body2, _ := json.Marshal(turn2)
resp2, _ := http.Post(server.URL+"/v1/chat/completions", "application/json", bytes.NewReader(body2))
resp2, err := http.Post(server.URL+"/v1/chat/completions", "application/json", bytes.NewReader(body2))
if err != nil {
t.Fatalf("request failed: %v", err)
}
var turn2Resp map[string]interface{}
json.NewDecoder(resp2.Body).Decode(&turn2Resp)
resp2.Body.Close()
@@ -503,7 +509,7 @@ func TestParallelToolCalls(t *testing.T) {
"content": nil,
"tool_calls": []map[string]interface{}{
{
"id": "call_1",
"id": "call_1",
"type": "function",
"function": map[string]interface{}{
"name": "get_weather",
@@ -511,7 +517,7 @@ func TestParallelToolCalls(t *testing.T) {
},
},
{
"id": "call_2",
"id": "call_2",
"type": "function",
"function": map[string]interface{}{
"name": "get_weather",
@@ -519,7 +525,7 @@ func TestParallelToolCalls(t *testing.T) {
},
},
{
"id": "call_3",
"id": "call_3",
"type": "function",
"function": map[string]interface{}{
"name": "get_weather",
@@ -576,7 +582,10 @@ func TestParallelToolCalls(t *testing.T) {
}
body, _ := json.Marshal(request)
resp, _ := http.Post(server.URL+"/v1/chat/completions", "application/json", bytes.NewReader(body))
resp, err := http.Post(server.URL+"/v1/chat/completions", "application/json", bytes.NewReader(body))
if err != nil {
t.Fatalf("request failed: %v", err)
}
var respData map[string]interface{}
json.NewDecoder(resp.Body).Decode(&respData)
resp.Body.Close()
@@ -627,9 +636,9 @@ func TestAnthropicToolUse(t *testing.T) {
// Anthropic response format with tool_use block
response := map[string]interface{}{
"id": "msg_123",
"type": "message",
"role": "assistant",
"id": "msg_123",
"type": "message",
"role": "assistant",
"content": []map[string]interface{}{
{
"type": "text",
@@ -714,7 +723,10 @@ func TestAnthropicToolUse(t *testing.T) {
body, _ := json.Marshal(anthropicRequest)
// Note: For now we route through a generic path
// In Phase 2.9+, this would be integrated with the Anthropic dialect handler
resp, _ := http.Post(server.URL+"/v1/messages", "application/json", bytes.NewReader(body))
resp, err := http.Post(server.URL+"/v1/messages", "application/json", bytes.NewReader(body))
if err != nil {
t.Fatalf("request failed: %v", err)
}
var respData map[string]interface{}
json.NewDecoder(resp.Body).Decode(&respData)
resp.Body.Close()
@@ -762,7 +774,7 @@ func TestComplexToolArguments(t *testing.T) {
"content": nil,
"tool_calls": []map[string]interface{}{
{
"id": "call_complex",
"id": "call_complex",
"type": "function",
"function": map[string]interface{}{
"name": "create_event",
@@ -832,7 +844,10 @@ func TestComplexToolArguments(t *testing.T) {
}
body, _ := json.Marshal(request)
resp, _ := http.Post(server.URL+"/v1/chat/completions", "application/json", bytes.NewReader(body))
resp, err := http.Post(server.URL+"/v1/chat/completions", "application/json", bytes.NewReader(body))
if err != nil {
t.Fatalf("request failed: %v", err)
}
var respData map[string]interface{}
json.NewDecoder(resp.Body).Decode(&respData)
resp.Body.Close()