Fix output repair diagnostics and concurrency tests

This commit is contained in:
2026-08-25 11:54:50 +00:00
parent 465dc1389d
commit 36ce5a5099
3 changed files with 39 additions and 10 deletions

View File

@@ -132,7 +132,8 @@ func formatRepairDiagnostics(errors []string) string {
if len(encoded) > 1 {
separator = 1
}
if len(encoded)+separator+len(entry)+1+len(omission)+1 <= maxRepairDiagnosticBytes {
available := maxRepairDiagnosticBytes - len(encoded) - separator - 1 - len(omission) - 1
if len(entry) <= available {
if separator != 0 {
encoded = append(encoded, ',')
}
@@ -140,7 +141,9 @@ func formatRepairDiagnostics(errors []string) string {
continue
}
available := maxRepairDiagnosticBytes - len(encoded) - separator - 1 - len(omission) - 1
if available < len(`""`) {
break
}
if separator != 0 {
encoded = append(encoded, ',')
}
@@ -157,17 +160,24 @@ func formatRepairDiagnostics(errors []string) string {
func truncateDiagnosticJSONValue(value string, maxBytes int) []byte {
if maxBytes < len(`""`) {
return []byte(`""`)
return nil
}
low, high := 0, len(value)
boundaries := []int{0}
for end := 0; end < len(value); {
_, size := utf8.DecodeRuneInString(value[end:])
end += size
if end+len(`""`) > maxBytes {
break
}
boundaries = append(boundaries, end)
}
low, high := 0, len(boundaries)-1
best := []byte(`""`)
for low <= high {
mid := low + (high-low)/2
for mid > 0 && mid < len(value) && !utf8.RuneStart(value[mid]) {
mid--
}
candidate, _ := json.Marshal(value[:mid])
candidate, _ := json.Marshal(value[:boundaries[mid]])
if len(candidate) <= maxBytes {
best = candidate
low = mid + 1