Accept span deletions in structured responses
This commit is contained in:
@@ -2,6 +2,7 @@ package validators
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -75,6 +76,43 @@ func mk(index int, orig, corr string) proposals.EnrichedCorrectionProposal {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildLLMValidationRequestPreservesLiteralDeletionAndSpacing(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name, segment, original, replacement, result string
|
||||
}{
|
||||
{name: "deletion", segment: "uh hello", original: "uh ", replacement: "", result: "hello"},
|
||||
{name: "spacing", segment: "hello world", original: " ", replacement: " ", result: "hello world"},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
req := makeReq([]proposals.EnrichedCorrectionProposal{mk(7, tc.original, tc.replacement)})
|
||||
req.WorkingTranscript.Segments[0].Text = tc.segment
|
||||
payload, immediate := BuildLLMValidationRequest("editorial_review", LLMValidatorTypeEditorialReview, req)
|
||||
if len(immediate) != 0 || len(payload.Items) != 1 {
|
||||
t.Fatalf("expected previewable request: %+v, %+v", payload, immediate)
|
||||
}
|
||||
raw, err := json.Marshal(payload)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var decoded struct {
|
||||
ValidatorName string `json:"validator_name"`
|
||||
Corrections []map[string]any `json:"corrections"`
|
||||
}
|
||||
if err := json.Unmarshal(raw, &decoded); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if decoded.ValidatorName != "editorial_review" || len(decoded.Corrections) != 1 {
|
||||
t.Fatalf("wrong validator identity or item count: %s", raw)
|
||||
}
|
||||
item := decoded.Corrections[0]
|
||||
value, present := item["corrected_text"]
|
||||
if !present || value != tc.replacement || item["original_text"] != tc.original || item["original_segment_text"] != tc.segment || item["corrected_segment_text"] != tc.result || item["correction_index"] != float64(7) {
|
||||
t.Fatalf("literal spans or full segment text lost: %s", raw)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestChunkLLMValidationItemsOneSmallBatch(t *testing.T) {
|
||||
items := []LLMValidationItem{{CorrectionIndex: 0, OriginalText: "a", CorrectedText: "b", OriginalSegmentText: "x", CorrectedSegmentText: "y"}}
|
||||
batches, err := ChunkLLMValidationItems(items, 1000, chunking.NewSimpleTokenEstimator())
|
||||
|
||||
Reference in New Issue
Block a user