@@ -1004,3 +1004,96 @@ func TestCodexToOpenAIRequestDoesNotLeakMalformedResponsesImagePart(t *testing.T
10041004 t .Fatalf ("expected malformed known Codex part to collapse to empty content: %s" , string (out ))
10051005 }
10061006}
1007+
1008+ func TestCodexToOpenAIRequestNormalizesToolOutputParts (t * testing.T ) {
1009+ req := CodexRequest {Input : []interface {}{
1010+ map [string ]interface {}{
1011+ "type" : "function_call_output" ,
1012+ "call_id" : "call_1" ,
1013+ "output" : []interface {}{
1014+ map [string ]interface {}{"type" : "input_text" , "text" : "a" },
1015+ map [string ]interface {}{"type" : "output_text" , "text" : "b" },
1016+ },
1017+ },
1018+ }}
1019+ body , _ := json .Marshal (req )
1020+ conv := & codexToOpenAIRequest {}
1021+ out , err := conv .Transform (body , "gpt" , false )
1022+ if err != nil {
1023+ t .Fatalf ("Transform: %v" , err )
1024+ }
1025+ if strings .Contains (string (out ), "input_text" ) || strings .Contains (string (out ), "output_text" ) {
1026+ t .Fatalf ("Responses tool output part type leaked into OpenAI request: %s" , string (out ))
1027+ }
1028+ if ! strings .Contains (string (out ), `"content":"ab"` ) {
1029+ t .Fatalf ("expected text-only tool output parts to collapse to string: %s" , string (out ))
1030+ }
1031+ }
1032+
1033+ func TestCodexToOpenAIRequestSkipsToolOutputWithoutCallID (t * testing.T ) {
1034+ req := CodexRequest {Input : []interface {}{
1035+ map [string ]interface {}{"type" : "function_call_output" , "output" : "orphan" },
1036+ }}
1037+ body , _ := json .Marshal (req )
1038+ conv := & codexToOpenAIRequest {}
1039+ out , err := conv .Transform (body , "gpt" , false )
1040+ if err != nil {
1041+ t .Fatalf ("Transform: %v" , err )
1042+ }
1043+ if strings .Contains (string (out ), `"role":"tool"` ) || strings .Contains (string (out ), "orphan" ) {
1044+ t .Fatalf ("expected orphan tool output to be skipped: %s" , string (out ))
1045+ }
1046+ }
1047+
1048+ func TestCodexToOpenAIRequestJSONEncodesUnknownStructuredToolOutput (t * testing.T ) {
1049+ req := CodexRequest {Input : []interface {}{
1050+ map [string ]interface {}{
1051+ "type" : "function_call_output" ,
1052+ "call_id" : "call_1" ,
1053+ "output" : []interface {}{
1054+ map [string ]interface {}{"unknown" : "value" },
1055+ },
1056+ },
1057+ }}
1058+ body , _ := json .Marshal (req )
1059+ conv := & codexToOpenAIRequest {}
1060+ out , err := conv .Transform (body , "gpt" , false )
1061+ if err != nil {
1062+ t .Fatalf ("Transform: %v" , err )
1063+ }
1064+ if ! strings .Contains (string (out ), `"content":"[{\"unknown\":\"value\"}]"` ) {
1065+ t .Fatalf ("expected unknown structured tool output to be JSON encoded: %s" , string (out ))
1066+ }
1067+ }
1068+
1069+ func TestCodexToOpenAIRequestNormalizesFilesImagesAndBareTextParts (t * testing.T ) {
1070+ req := CodexRequest {Input : []interface {}{
1071+ map [string ]interface {}{
1072+ "type" : "message" ,
1073+ "role" : "user" ,
1074+ "content" : []interface {}{
1075+ "prefix" ,
1076+ map [string ]interface {}{"type" : "input_text" , "text" : " body" },
1077+ map [string ]interface {}{"type" : "input_image" , "image_url" : "https://example.com/a.png" , "detail" : "low" },
1078+ map [string ]interface {}{"type" : "input_file" , "file_url" : "https://example.com/a.pdf" , "file_data" : "data" },
1079+ },
1080+ },
1081+ }}
1082+ body , _ := json .Marshal (req )
1083+ conv := & codexToOpenAIRequest {}
1084+ out , err := conv .Transform (body , "gpt" , false )
1085+ if err != nil {
1086+ t .Fatalf ("Transform: %v" , err )
1087+ }
1088+ outStr := string (out )
1089+ for _ , leaked := range []string {"input_text" , "input_image" , "input_file" } {
1090+ if strings .Contains (outStr , leaked ) {
1091+ t .Fatalf ("Responses content part type %q leaked into OpenAI request: %s" , leaked , outStr )
1092+ }
1093+ }
1094+ for _ , expected := range []string {`"text":"prefix"` , `"text":" body"` , `"type":"image_url"` , `"detail":"low"` , `"type":"file"` , `"file_id":"https://example.com/a.pdf"` , `"file_data":"data"` } {
1095+ if ! strings .Contains (outStr , expected ) {
1096+ t .Fatalf ("expected %s in converted request: %s" , expected , outStr )
1097+ }
1098+ }
1099+ }
0 commit comments