mirror of
https://github.com/cexll/myclaude.git
synced 2026-02-05 02:30:26 +08:00
## 问题 - 执行 rg 等命令时,如果匹配到 minified 文件,单行输出可能超过 10MB - 旧实现使用 bufio.Scanner,遇到超长行会报错并中止整个解析 - 导致后续的 agent_message 无法读取,任务失败 ## 修复 1. **parser.go**: - 移除 bufio.Scanner,改用 bufio.Reader + readLineWithLimit - 超长行(>10MB)会被跳过但继续处理后续事件 - 添加 codexHeader 轻量级解析,只在 agent_message 时完整解析 2. **utils.go**: - 修复 logWriter 内存膨胀问题 - 添加 writeLimited 方法限制缓冲区大小 3. **测试**: - parser_token_too_long_test.go: 验证超长行处理 - log_writer_limit_test.go: 验证日志缓冲限制 ## 测试结果 - ✅ TestParseJSONStream_SkipsOverlongLineAndContinues - ✅ TestLogWriterWriteLimitsBuffer - ✅ 完整测试套件通过 Fixes #64 Generated with swe-agent-bot Co-Authored-By: swe-agent-bot <agent@swe-agent.ai>
32 lines
1023 B
Go
32 lines
1023 B
Go
package main
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestParseJSONStream_SkipsOverlongLineAndContinues(t *testing.T) {
|
|
// Exceed the 10MB bufio.Scanner limit in parseJSONStreamInternal.
|
|
tooLong := strings.Repeat("a", 11*1024*1024)
|
|
|
|
input := strings.Join([]string{
|
|
`{"type":"item.completed","item":{"type":"other_type","text":"` + tooLong + `"}}`,
|
|
`{"type":"thread.started","thread_id":"t-1"}`,
|
|
`{"type":"item.completed","item":{"type":"agent_message","text":"ok"}}`,
|
|
}, "\n")
|
|
|
|
var warns []string
|
|
warnFn := func(msg string) { warns = append(warns, msg) }
|
|
|
|
gotMessage, gotThreadID := parseJSONStreamInternal(strings.NewReader(input), warnFn, nil, nil)
|
|
if gotMessage != "ok" {
|
|
t.Fatalf("message=%q, want %q (warns=%v)", gotMessage, "ok", warns)
|
|
}
|
|
if gotThreadID != "t-1" {
|
|
t.Fatalf("threadID=%q, want %q (warns=%v)", gotThreadID, "t-1", warns)
|
|
}
|
|
if len(warns) == 0 || !strings.Contains(warns[0], "Skipped overlong JSON line") {
|
|
t.Fatalf("expected warning about overlong JSON line, got %v", warns)
|
|
}
|
|
}
|