fix(codex): normalize null instructions for compact requests
This commit is contained in:
@@ -220,7 +220,8 @@ func (e *CodexExecutor) executeCompact(ctx context.Context, auth *cliproxyauth.A
|
|||||||
body = applyPayloadConfigWithRoot(e.cfg, baseModel, to.String(), "", body, originalTranslated, requestedModel)
|
body = applyPayloadConfigWithRoot(e.cfg, baseModel, to.String(), "", body, originalTranslated, requestedModel)
|
||||||
body, _ = sjson.SetBytes(body, "model", baseModel)
|
body, _ = sjson.SetBytes(body, "model", baseModel)
|
||||||
body, _ = sjson.DeleteBytes(body, "stream")
|
body, _ = sjson.DeleteBytes(body, "stream")
|
||||||
if !gjson.GetBytes(body, "instructions").Exists() {
|
instructions := gjson.GetBytes(body, "instructions")
|
||||||
|
if !instructions.Exists() || instructions.Type == gjson.Null {
|
||||||
body, _ = sjson.SetBytes(body, "instructions", "")
|
body, _ = sjson.SetBytes(body, "instructions", "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,22 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestCodexExecutorCompactAddsDefaultInstructions(t *testing.T) {
|
func TestCodexExecutorCompactAddsDefaultInstructions(t *testing.T) {
|
||||||
|
cases := []struct {
|
||||||
|
name string
|
||||||
|
payload string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "missing instructions",
|
||||||
|
payload: `{"model":"gpt-5.4","input":"hello"}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "null instructions",
|
||||||
|
payload: `{"model":"gpt-5.4","instructions":null,"input":"hello"}`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range cases {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
var gotPath string
|
var gotPath string
|
||||||
var gotBody []byte
|
var gotBody []byte
|
||||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -34,7 +50,7 @@ func TestCodexExecutorCompactAddsDefaultInstructions(t *testing.T) {
|
|||||||
|
|
||||||
resp, err := executor.Execute(context.Background(), auth, cliproxyexecutor.Request{
|
resp, err := executor.Execute(context.Background(), auth, cliproxyexecutor.Request{
|
||||||
Model: "gpt-5.4",
|
Model: "gpt-5.4",
|
||||||
Payload: []byte(`{"model":"gpt-5.4","input":"hello"}`),
|
Payload: []byte(tc.payload),
|
||||||
}, cliproxyexecutor.Options{
|
}, cliproxyexecutor.Options{
|
||||||
SourceFormat: sdktranslator.FromString("openai-response"),
|
SourceFormat: sdktranslator.FromString("openai-response"),
|
||||||
Alt: "responses/compact",
|
Alt: "responses/compact",
|
||||||
@@ -49,10 +65,15 @@ func TestCodexExecutorCompactAddsDefaultInstructions(t *testing.T) {
|
|||||||
if !gjson.GetBytes(gotBody, "instructions").Exists() {
|
if !gjson.GetBytes(gotBody, "instructions").Exists() {
|
||||||
t.Fatalf("expected instructions in compact request body, got %s", string(gotBody))
|
t.Fatalf("expected instructions in compact request body, got %s", string(gotBody))
|
||||||
}
|
}
|
||||||
|
if gjson.GetBytes(gotBody, "instructions").Type != gjson.String {
|
||||||
|
t.Fatalf("instructions type = %v, want string", gjson.GetBytes(gotBody, "instructions").Type)
|
||||||
|
}
|
||||||
if gjson.GetBytes(gotBody, "instructions").String() != "" {
|
if gjson.GetBytes(gotBody, "instructions").String() != "" {
|
||||||
t.Fatalf("instructions = %q, want empty string", gjson.GetBytes(gotBody, "instructions").String())
|
t.Fatalf("instructions = %q, want empty string", gjson.GetBytes(gotBody, "instructions").String())
|
||||||
}
|
}
|
||||||
if string(resp.Payload) != `{"id":"resp_1","object":"response.compaction","usage":{"input_tokens":1,"output_tokens":2,"total_tokens":3}}` {
|
if string(resp.Payload) != `{"id":"resp_1","object":"response.compaction","usage":{"input_tokens":1,"output_tokens":2,"total_tokens":3}}` {
|
||||||
t.Fatalf("payload = %s", string(resp.Payload))
|
t.Fatalf("payload = %s", string(resp.Payload))
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user