mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-11-18 15:48:39 +08:00
Normalize string websocket errors without discarding their messages. Recognize untyped and body-wrapped failures across SSE, websocket, and duplex paths while retaining status, headers, and sequence numbers. Cover transport and format combinations, replay invalidation, credential status precedence, and Responses framing with regression tests.
27 lines
1.0 KiB
Go
27 lines
1.0 KiB
Go
package helps
|
|
|
|
import "testing"
|
|
|
|
func TestCodexResponseEventType(t *testing.T) {
|
|
for _, tc := range []struct{ payload, want string }{
|
|
{`{"error":{"code":"bio_policy"}}`, "error"},
|
|
{`{"body":{"error":"blocked"}}`, "error"},
|
|
{`{"response":{"error":{"code":"bio_policy"}}}`, "error"},
|
|
{`{"code":"bio_policy","message":"blocked"}`, "error"},
|
|
{`{"error":null}`, ""},
|
|
{`{"error":" "}`, ""},
|
|
{`{"body":{"error":null}}`, ""},
|
|
{`{"response":{"error":null,"status":"completed"}}`, ""},
|
|
{`{"message":"This content was flagged for possible biological risk."}`, ""},
|
|
{`{"type":"response.output_text.delta","delta":"blocked","error":{"code":"bio_policy"}}`, "response.output_text.delta"},
|
|
{`{"type":"response.metadata","body":{"error":{"code":"bio_policy"}}}`, "response.metadata"},
|
|
{`{"error":{"code":"bio_policy"}}` + "trailing data", ""},
|
|
} {
|
|
t.Run(tc.payload, func(t *testing.T) {
|
|
if got := CodexResponseEventType([]byte(tc.payload)); got != tc.want {
|
|
t.Fatalf("type = %q, want %q", got, tc.want)
|
|
}
|
|
})
|
|
}
|
|
}
|