History

Merge branch 'router-for-me:main' into main

Luis Pater committed 9 months agov6.8.8-0

Commit 91841a52 parents 532fbf0 eaab1d62 files · +111 −1Browse files

Unified · Split

2 files
  1. internal/api/modules/amp/response_rewriter.go +1 −1
  2. internal/api/modules/amp/response_rewriter_test.go +110 −0
internal/api/modules/amp/response_rewriter.go+1−1
@@ -122,7 +122,7 @@ func (rw *ResponseRewriter) Flush() { · 121 unmodified lines
122}122}
123 123
124// modelFieldPaths lists all JSON paths where model name may appear124// modelFieldPaths lists all JSON paths where model name may appear
125var modelFieldPaths = []string{"model", "modelVersion", "response.modelVersion", "message.model"}125var modelFieldPaths = []string{"message.model", "model", "modelVersion", "response.model", "response.modelVersion"}
126 126
127// rewriteModelInResponse replaces all occurrences of the mapped model with the original model in JSON127// rewriteModelInResponse replaces all occurrences of the mapped model with the original model in JSON
128// It also suppresses "thinking" blocks if "tool_use" is present to ensure Amp client compatibility128// It also suppresses "thinking" blocks if "tool_use" is present to ensure Amp client compatibility
internal/api/modules/amp/response_rewriter_test.go+110−0
@@ -0,0 +1,110 @@
1package amp
2
3import (
4 "testing"
5)
6
7func TestRewriteModelInResponse_TopLevel(t *testing.T) {
8 rw := &ResponseRewriter{originalModel: "gpt-5.2-codex"}
9
10 input := []byte(`{"id":"resp_1","model":"gpt-5.3-codex","output":[]}`)
11 result := rw.rewriteModelInResponse(input)
12
13 expected := `{"id":"resp_1","model":"gpt-5.2-codex","output":[]}`
14 if string(result) != expected {
15 t.Errorf("expected %s, got %s", expected, string(result))
16 }
17}
18
19func TestRewriteModelInResponse_ResponseModel(t *testing.T) {
20 rw := &ResponseRewriter{originalModel: "gpt-5.2-codex"}
21
22 input := []byte(`{"type":"response.completed","response":{"id":"resp_1","model":"gpt-5.3-codex","status":"completed"}}`)
23 result := rw.rewriteModelInResponse(input)
24
25 expected := `{"type":"response.completed","response":{"id":"resp_1","model":"gpt-5.2-codex","status":"completed"}}`
26 if string(result) != expected {
27 t.Errorf("expected %s, got %s", expected, string(result))
28 }
29}
30
31func TestRewriteModelInResponse_ResponseCreated(t *testing.T) {
32 rw := &ResponseRewriter{originalModel: "gpt-5.2-codex"}
33
34 input := []byte(`{"type":"response.created","response":{"id":"resp_1","model":"gpt-5.3-codex","status":"in_progress"}}`)
35 result := rw.rewriteModelInResponse(input)
36
37 expected := `{"type":"response.created","response":{"id":"resp_1","model":"gpt-5.2-codex","status":"in_progress"}}`
38 if string(result) != expected {
39 t.Errorf("expected %s, got %s", expected, string(result))
40 }
41}
42
43func TestRewriteModelInResponse_NoModelField(t *testing.T) {
44 rw := &ResponseRewriter{originalModel: "gpt-5.2-codex"}
45
46 input := []byte(`{"type":"response.output_item.added","item":{"id":"item_1","type":"message"}}`)
47 result := rw.rewriteModelInResponse(input)
48
49 if string(result) != string(input) {
50 t.Errorf("expected no modification, got %s", string(result))
51 }
52}
53
54func TestRewriteModelInResponse_EmptyOriginalModel(t *testing.T) {
55 rw := &ResponseRewriter{originalModel: ""}
56
57 input := []byte(`{"model":"gpt-5.3-codex"}`)
58 result := rw.rewriteModelInResponse(input)
59
60 if string(result) != string(input) {
61 t.Errorf("expected no modification when originalModel is empty, got %s", string(result))
62 }
63}
64
65func TestRewriteStreamChunk_SSEWithResponseModel(t *testing.T) {
66 rw := &ResponseRewriter{originalModel: "gpt-5.2-codex"}
67
68 chunk := []byte("data: {\"type\":\"response.completed\",\"response\":{\"id\":\"resp_1\",\"model\":\"gpt-5.3-codex\",\"status\":\"completed\"}}\n\n")
69 result := rw.rewriteStreamChunk(chunk)
70
71 expected := "data: {\"type\":\"response.completed\",\"response\":{\"id\":\"resp_1\",\"model\":\"gpt-5.2-codex\",\"status\":\"completed\"}}\n\n"
72 if string(result) != expected {
73 t.Errorf("expected %s, got %s", expected, string(result))
74 }
75}
76
77func TestRewriteStreamChunk_MultipleEvents(t *testing.T) {
78 rw := &ResponseRewriter{originalModel: "gpt-5.2-codex"}
79
80 chunk := []byte("data: {\"type\":\"response.created\",\"response\":{\"model\":\"gpt-5.3-codex\"}}\n\ndata: {\"type\":\"response.output_item.added\",\"item\":{\"id\":\"item_1\"}}\n\n")
81 result := rw.rewriteStreamChunk(chunk)
82
83 if string(result) == string(chunk) {
84 t.Error("expected response.model to be rewritten in SSE stream")
85 }
86 if !contains(result, []byte(`"model":"gpt-5.2-codex"`)) {
87 t.Errorf("expected rewritten model in output, got %s", string(result))
88 }
89}
90
91func TestRewriteStreamChunk_MessageModel(t *testing.T) {
92 rw := &ResponseRewriter{originalModel: "claude-opus-4.5"}
93
94 chunk := []byte("data: {\"message\":{\"model\":\"claude-sonnet-4\",\"role\":\"assistant\"}}\n\n")
95 result := rw.rewriteStreamChunk(chunk)
96
97 expected := "data: {\"message\":{\"model\":\"claude-opus-4.5\",\"role\":\"assistant\"}}\n\n"
98 if string(result) != expected {
99 t.Errorf("expected %s, got %s", expected, string(result))
100 }
101}
102
103func contains(data, substr []byte) bool {
104 for i := 0; i <= len(data)-len(substr); i++ {
105 if string(data[i:i+len(substr)]) == string(substr) {
106 return true
107 }
108 }
109 return false
110}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t