Merge pull request #7092 from sususu98/fix/slow-test-disconnect

Fix WebSocket disconnect test and Devin diagnostics
This commit is contained in:
sususu98
2026-10-29 09:58:15 +08:00
committed by GitHub
3 changed files with 42 additions and 3 deletions

View File

@@ -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"):

View File

@@ -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)

View File

@@ -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