|
|
|
|
@@ -61,7 +61,7 @@ func TestCodecRoundTripsValidFixture(t *testing.T) {
|
|
|
|
|
func TestBuildCanonicalizesAnnotationFormatting(t *testing.T) {
|
|
|
|
|
first := acceptedBuildRequest(t)
|
|
|
|
|
second := acceptedBuildRequest(t)
|
|
|
|
|
second.Plan.Annotations["dnd/scenes"] = json.RawMessage(" { \n \t\"title\" : \"Gate\" \n } ")
|
|
|
|
|
second.Plan.Annotations["test/chunker"] = json.RawMessage(" { \n \t\"label\" : \"fixture\" \n } ")
|
|
|
|
|
canonical, err := source.CanonicalizeChunkPlan(second.Plan)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("CanonicalizeChunkPlan() error = %v", err)
|
|
|
|
|
@@ -108,7 +108,7 @@ func TestCodecRejectsInvalidDurableBoundaries(t *testing.T) {
|
|
|
|
|
{name: "invalid range", mutate: func(value *ChunkMap) { value.Chunks[0].SourceRef.StartUnitID = 0 }},
|
|
|
|
|
{name: "invalid count", mutate: func(value *ChunkMap) { value.Chunks[0].UnitCount = 0 }},
|
|
|
|
|
{name: "invalid namespace", mutate: func(value *ChunkMap) { value.PlanAnnotations[" "] = json.RawMessage(`null`) }},
|
|
|
|
|
{name: "invalid annotation", mutate: func(value *ChunkMap) { value.Chunks[0].Annotations["dnd/scenes"] = json.RawMessage(`{`) }},
|
|
|
|
|
{name: "invalid annotation", mutate: func(value *ChunkMap) { value.Chunks[0].Annotations["test/chunker"] = json.RawMessage(`{`) }},
|
|
|
|
|
{name: "plan digest mismatch", mutate: func(value *ChunkMap) { value.PlanDigest = "sha256:" + strings.Repeat("a", 64) }},
|
|
|
|
|
} {
|
|
|
|
|
t.Run(test.name, func(t *testing.T) {
|
|
|
|
|
@@ -131,13 +131,13 @@ func TestCodecRejectsInvalidDurableBoundaries(t *testing.T) {
|
|
|
|
|
t.Fatalf("Decode(%s) error = nil, want strict JSON rejection", raw)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
formatted := bytes.Replace(content, []byte(`{"title":"Gate"}`), []byte("{\n \"title\": \"Gate\"\n}"), 1)
|
|
|
|
|
formatted := bytes.Replace(content, []byte(`{"label":"fixture"}`), []byte("{\n \"label\": \"fixture\"\n}"), 1)
|
|
|
|
|
decoded, err := New().Decode(formatted)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("Decode(formatted annotations) error = %v", err)
|
|
|
|
|
}
|
|
|
|
|
if string(decoded.PlanAnnotations["dnd/scenes"]) != `{"title":"Gate"}` {
|
|
|
|
|
t.Fatalf("decoded annotation = %s, want canonical JSON", decoded.PlanAnnotations["dnd/scenes"])
|
|
|
|
|
if string(decoded.PlanAnnotations["test/chunker"]) != `{"label":"fixture"}` {
|
|
|
|
|
t.Fatalf("decoded annotation = %s, want canonical JSON", decoded.PlanAnnotations["test/chunker"])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -187,7 +187,7 @@ func TestEncodeDoesNotMutateValue(t *testing.T) {
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
value.Chunks[0].Annotations["dnd/scenes"] = json.RawMessage(" { \n \"kind\" : \"narrative\" \n } ")
|
|
|
|
|
value.Chunks[0].Annotations["test/chunker"] = json.RawMessage(" { \n \"category\" : \"sample\" \n } ")
|
|
|
|
|
before := clone(value)
|
|
|
|
|
if _, err := New().Encode(value); err != nil {
|
|
|
|
|
t.Fatalf("Encode() error = %v", err)
|
|
|
|
|
@@ -203,14 +203,14 @@ func TestChunkMapOwnershipIsIndependent(t *testing.T) {
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
request.Plan.Annotations["dnd/scenes"][0] = '['
|
|
|
|
|
first.PlanAnnotations["dnd/scenes"][0] = '['
|
|
|
|
|
request.Plan.Annotations["test/chunker"][0] = '['
|
|
|
|
|
first.PlanAnnotations["test/chunker"][0] = '['
|
|
|
|
|
second, err := Build(acceptedBuildRequest(t))
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
if string(second.PlanAnnotations["dnd/scenes"]) != `{"title":"Gate"}` {
|
|
|
|
|
t.Fatalf("Build() shared mutable annotations: %s", second.PlanAnnotations["dnd/scenes"])
|
|
|
|
|
if string(second.PlanAnnotations["test/chunker"]) != `{"label":"fixture"}` {
|
|
|
|
|
t.Fatalf("Build() shared mutable annotations: %s", second.PlanAnnotations["test/chunker"])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -232,11 +232,11 @@ func chunkDocument(value map[string]any, index int) map[string]any {
|
|
|
|
|
func acceptedBuildRequest(t *testing.T) BuildRequest {
|
|
|
|
|
t.Helper()
|
|
|
|
|
document := &source.SourceDocument{
|
|
|
|
|
ID: "session-7", Kind: "transcript", Format: "application/json",
|
|
|
|
|
ID: "source-test", Kind: "transcript", Format: "application/json",
|
|
|
|
|
Units: []source.SourceUnit{
|
|
|
|
|
{ID: 10, Kind: "segment", Text: "At the gate.", Ref: source.SourceRef{SourceID: "session-7", StartUnitID: 10, EndUnitID: 10}},
|
|
|
|
|
{ID: 3, Kind: "segment", Text: "The guard speaks.", Ref: source.SourceRef{SourceID: "session-7", StartUnitID: 3, EndUnitID: 3}},
|
|
|
|
|
{ID: 20, Kind: "segment", Text: "The party enters.", Ref: source.SourceRef{SourceID: "session-7", StartUnitID: 20, EndUnitID: 20}},
|
|
|
|
|
{ID: 10, Kind: "segment", Text: "First unit.", Ref: source.SourceRef{SourceID: "source-test", StartUnitID: 10, EndUnitID: 10}},
|
|
|
|
|
{ID: 3, Kind: "segment", Text: "Second unit.", Ref: source.SourceRef{SourceID: "source-test", StartUnitID: 3, EndUnitID: 3}},
|
|
|
|
|
{ID: 20, Kind: "segment", Text: "Third unit.", Ref: source.SourceRef{SourceID: "source-test", StartUnitID: 20, EndUnitID: 20}},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
digest, err := source.DigestDocument(document)
|
|
|
|
|
@@ -246,9 +246,9 @@ func acceptedBuildRequest(t *testing.T) BuildRequest {
|
|
|
|
|
document.Digest = digest
|
|
|
|
|
plan := source.ChunkPlan{
|
|
|
|
|
SourceDigest: digest,
|
|
|
|
|
Annotations: source.ChunkAnnotations{"dnd/scenes": json.RawMessage(`{"title":"Gate"}`)},
|
|
|
|
|
Annotations: source.ChunkAnnotations{"test/chunker": json.RawMessage(`{"label":"fixture"}`)},
|
|
|
|
|
Ranges: []source.ChunkRange{
|
|
|
|
|
{StartUnitID: 10, EndUnitID: 3, Annotations: source.ChunkAnnotations{"dnd/scenes": json.RawMessage(`{"kind":"narrative"}`)}},
|
|
|
|
|
{StartUnitID: 10, EndUnitID: 3, Annotations: source.ChunkAnnotations{"test/chunker": json.RawMessage(`{"category":"sample"}`)}},
|
|
|
|
|
{StartUnitID: 20, EndUnitID: 20},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
@@ -257,7 +257,7 @@ func acceptedBuildRequest(t *testing.T) BuildRequest {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
return BuildRequest{
|
|
|
|
|
Source: document, Plan: plan, Chunks: chunks, RequestedChunker: "dnd/scenes",
|
|
|
|
|
Producer: Producer{InputModule: "seriatim", ChunkModule: "dnd/scenes", LLMProfile: "dnd-scenes"},
|
|
|
|
|
Source: document, Plan: plan, Chunks: chunks, RequestedChunker: "chunk/requested",
|
|
|
|
|
Producer: Producer{InputModule: "input/producer", ChunkModule: "chunk/producer", LLMProfile: "profile/test"},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|