perf(service): 优化重试场景 thinking 过滤性能
- 避免全量 Unmarshal 请求体,改为仅解析 messages 子树 - 顶层 thinking 使用 sjson 直接删除,减少整体重写 - content 仅在需要修改时延迟分配 new slice - 增加 FilterThinkingBlocksForRetry 基准测试 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -450,9 +450,9 @@ func TestParseGatewayRequest_TypeValidation(t *testing.T) {
|
||||
errSubstr: "invalid model field type",
|
||||
},
|
||||
{
|
||||
name: "model 为 null — gjson Null 类型触发类型校验错误",
|
||||
body: `{"model":null}`,
|
||||
wantErr: true, // gjson: Exists()=true, Type=Null != String → 返回错误
|
||||
name: "model 为 null — gjson Null 类型触发类型校验错误",
|
||||
body: `{"model":null}`,
|
||||
wantErr: true, // gjson: Exists()=true, Type=Null != String → 返回错误
|
||||
errSubstr: "invalid model field type",
|
||||
},
|
||||
{
|
||||
@@ -468,9 +468,9 @@ func TestParseGatewayRequest_TypeValidation(t *testing.T) {
|
||||
errSubstr: "invalid stream field type",
|
||||
},
|
||||
{
|
||||
name: "stream 为 null — gjson Null 类型触发类型校验错误",
|
||||
body: `{"stream":null}`,
|
||||
wantErr: true, // gjson: Exists()=true, Type=Null != True && != False → 返回错误
|
||||
name: "stream 为 null — gjson Null 类型触发类型校验错误",
|
||||
body: `{"stream":null}`,
|
||||
wantErr: true, // gjson: Exists()=true, Type=Null != True && != False → 返回错误
|
||||
errSubstr: "invalid stream field type",
|
||||
},
|
||||
{
|
||||
@@ -499,16 +499,16 @@ func TestParseGatewayRequest_TypeValidation(t *testing.T) {
|
||||
// Task 7.2 — 可选字段缺失测试
|
||||
func TestParseGatewayRequest_OptionalFieldsMissing(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
body string
|
||||
wantModel string
|
||||
wantStream bool
|
||||
wantMetadataUID string
|
||||
wantHasSystem bool
|
||||
wantThinking bool
|
||||
wantMaxTokens int
|
||||
wantMessagesNil bool
|
||||
wantMessagesLen int
|
||||
name string
|
||||
body string
|
||||
wantModel string
|
||||
wantStream bool
|
||||
wantMetadataUID string
|
||||
wantHasSystem bool
|
||||
wantThinking bool
|
||||
wantMaxTokens int
|
||||
wantMessagesNil bool
|
||||
wantMessagesLen int
|
||||
}{
|
||||
{
|
||||
name: "完全空 JSON — 所有字段零值",
|
||||
|
||||
Reference in New Issue
Block a user