From fa42f390c1207cc08c9251a5c6fdcca2e4140193 Mon Sep 17 00:00:00 2001 From: sususu Date: Thu, 29 Oct 2026 09:36:31 +0800 Subject: [PATCH 1/2] test(openai): assert websocket disconnect error event --- .../openai_responses_steering_integration_test.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/sdk/api/handlers/openai/openai_responses_steering_integration_test.go b/sdk/api/handlers/openai/openai_responses_steering_integration_test.go index cf13f9f79..8c99db623 100644 --- a/sdk/api/handlers/openai/openai_responses_steering_integration_test.go +++ b/sdk/api/handlers/openai/openai_responses_steering_integration_test.go @@ -121,12 +121,15 @@ func TestResponsesSteeringFullDuplexIntegration(t *testing.T) { for { _, b, err := c.ReadMessage() if err != nil { - if !strings.HasPrefix(scenario, "disconnect_") { - t.Fatalf("early close: %v", err) + t.Fatalf("downstream read before expected terminal event: %v", err) + } + kind := gjson.GetBytes(b, "type").String() + if kind == "error" { + if !strings.HasPrefix(scenario, "disconnect_") || gjson.GetBytes(b, "error.code").String() != "upstream_websocket_lost" { + t.Fatalf("unexpected downstream error: %s", b) } break } - kind := gjson.GetBytes(b, "type").String() if kind == "response.created" && gjson.GetBytes(b, "response.id").String() == "r1" { send(control1) send(control2) @@ -141,6 +144,9 @@ func TestResponsesSteeringFullDuplexIntegration(t *testing.T) { send([]byte(`{"type":"response.create","previous_response_id":"r1","input":[{"type":"function_call_output","call_id":"call1","output":"found"}]}`)) } if kind == "response.completed" && gjson.GetBytes(b, "response.id").String() == "r2" { + if strings.HasPrefix(scenario, "disconnect_") { + t.Fatal("successor completed instead of reporting upstream disconnect") + } completed = gjson.GetBytes(b, "response.output.0.content.0.text").String() == "STEER_OK" _ = c.Close() break From 02ee313962ba0fca3b0c1203813dbba92005c3de Mon Sep 17 00:00:00 2001 From: sususu Date: Thu, 29 Oct 2026 09:46:47 +0800 Subject: [PATCH 2/2] fix(devin): classify JSON control character errors --- .../helps/devin_apply_patch_diagnostic.go | 6 +++++ .../devin_apply_patch_diagnostic_test.go | 27 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/internal/runtime/executor/helps/devin_apply_patch_diagnostic.go b/internal/runtime/executor/helps/devin_apply_patch_diagnostic.go index 7b46f0ca9..7088d95d3 100644 --- a/internal/runtime/executor/helps/devin_apply_patch_diagnostic.go +++ b/internal/runtime/executor/helps/devin_apply_patch_diagnostic.go @@ -2,6 +2,7 @@ package helps import ( "fmt" + "strconv" "strings" "unicode/utf8" @@ -229,6 +230,11 @@ func devinPatchReasonCode(reason string) string { switch { case strings.HasSuffix(reason, "in string literal"): return "invalid control character in apply_patch input" + case strings.HasPrefix(reason, "decode apply_patch input value: invalid character ") && strings.HasSuffix(reason, " in string"): + quoted := strings.TrimSuffix(strings.TrimPrefix(reason, "decode apply_patch input value: invalid character "), " in string") + if character, errUnquote := strconv.Unquote(quoted); errUnquote == nil && len(character) == 1 && character[0] < 0x20 { + return "invalid control character in apply_patch input" + } case strings.Contains(reason, "in \\u hexadecimal character escape"): return "invalid Unicode escape in apply_patch input" case strings.Contains(reason, "in string escape code"): diff --git a/internal/runtime/executor/helps/devin_apply_patch_diagnostic_test.go b/internal/runtime/executor/helps/devin_apply_patch_diagnostic_test.go index a24d42a29..72441febf 100644 --- a/internal/runtime/executor/helps/devin_apply_patch_diagnostic_test.go +++ b/internal/runtime/executor/helps/devin_apply_patch_diagnostic_test.go @@ -2,9 +2,11 @@ package helps import ( "errors" + "fmt" "strings" "testing" + applypatch "github.com/router-for-me/CLIProxyAPI/v8/internal/client/codex/apply-patch" "github.com/router-for-me/CLIProxyAPI/v8/internal/translator/common" ) @@ -58,6 +60,31 @@ func TestDevinApplyPatchDiagnosticsUsesTranslatorReason(t *testing.T) { } } +func TestDevinApplyPatchDiagnosticsControlCharacterReasons(t *testing.T) { + for c := byte(0); c < 0x20; c++ { + t.Run(fmt.Sprintf("control_%02x", c), func(t *testing.T) { + _, err := applypatch.UnwrapInput("{\"input\":\"secret" + string(c) + "secret\"}") + if err == nil { + t.Fatal("expected invalid JSON") + } + state := &common.ApplyPatchErrorState{} + state.SetToolInputError(err) + got := (*DevinApplyPatchDiagnostics)(nil).Render(state, "") + if !strings.Contains(got, `reason="invalid control character in apply_patch input"`) || strings.Contains(got, "secret") { + t.Fatalf("unexpected diagnostic: %s", got) + } + }) + } + for _, reason := range []string{ + `decode apply_patch input value: invalid character 'x' in string`, + `decode apply_patch input value: invalid character 'secret' in string`, + } { + if got := devinPatchReasonCode(reason); got != "other" { + t.Errorf("reason %q classified as %q", reason, got) + } + } +} + func TestDevinApplyPatchDiagnosticsBounded(t *testing.T) { if got := (*DevinApplyPatchDiagnostics)(nil).Render(nil, ""); got != ApplyPatchUpstreamErrorMessage { t.Fatalf("nil diagnostic = %q", got)