Add canonical chunk plan source model

This commit is contained in:
2026-07-17 23:47:22 +00:00
parent 1c13e1d64a
commit 3bfac14397
16 changed files with 755 additions and 73 deletions

View File

@@ -1,6 +1,7 @@
package source
import (
"encoding/json"
"strings"
"testing"
)
@@ -258,6 +259,28 @@ func TestDigestChunkIsDeterministicAndIncludesReference(t *testing.T) {
}
}
func TestDigestChunkIncludesAnnotationScopes(t *testing.T) {
doc := validDocument()
chunk := Chunk{
ID: "chunk-1", SourceID: doc.ID, Ref: SourceRef{SourceID: doc.ID, StartUnitID: 1, EndUnitID: 2},
Content: []byte("content"), MediaType: "text/plain", Units: doc.Units,
Annotations: ChunkAnnotations{"scope": json.RawMessage(`{"value":1}`)},
PlanAnnotations: ChunkAnnotations{"scope": json.RawMessage(`{"value":2}`)},
}
base, err := DigestChunk(chunk)
if err != nil {
t.Fatalf("DigestChunk() error = %v", err)
}
chunk.Annotations["scope"] = json.RawMessage(`{"value":3}`)
rangeChanged, _ := DigestChunk(chunk)
chunk.Annotations["scope"] = json.RawMessage(`{"value":1}`)
chunk.PlanAnnotations["scope"] = json.RawMessage(`{"value":3}`)
planChanged, _ := DigestChunk(chunk)
if base == rangeChanged || base == planChanged || rangeChanged == planChanged {
t.Fatalf("annotation scope digests did not change distinctly: %q %q %q", base, rangeChanged, planChanged)
}
}
func TestValidateRefValid(t *testing.T) {
doc := validDocument()
ref := SourceRef{