Fix overflow in chunk and reconciliation ranges

This commit is contained in:
2026-11-26 01:26:46 +00:00
parent cecd68f161
commit 4026e26e76
6 changed files with 77 additions and 10 deletions

View File

@@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"math"
"reflect"
"strings"
"testing"
@@ -93,6 +94,22 @@ func TestPlanOverlap(t *testing.T) {
}
}
func TestPlanMaximumUnitCount(t *testing.T) {
for _, overlap := range []int{0, math.MaxInt - 1} {
t.Run(fmt.Sprint(overlap), func(t *testing.T) {
chunker := newChunker(t, map[string]any{"max_units": math.MaxInt, "overlap_units": overlap})
result, err := runChunk(context.Background(), chunker, contracts.ChunkInput{Source: testSource(3)})
if err != nil {
t.Fatal(err)
}
want := []source.ChunkRange{{StartUnitID: 1, EndUnitID: 3}}
if !reflect.DeepEqual(result.Value.Ranges, want) {
t.Fatalf("ranges = %#v, want %#v", result.Value.Ranges, want)
}
})
}
}
func TestPlanRejectsInvalidOptions(t *testing.T) {
tests := []struct {
name string