|
|
|
|
@@ -14,9 +14,9 @@ import (
|
|
|
|
|
func TestValidationContextCarriesAdjacentEvidenceAndRelevantDefinitions(t *testing.T) {
|
|
|
|
|
req := makeReq([]proposals.EnrichedCorrectionProposal{mk(7, "gestures", "Jesters")})
|
|
|
|
|
req.WorkingTranscript = &schema.Transcript{Segments: []schema.Segment{
|
|
|
|
|
{ID: 1, Text: "The performers arrived."},
|
|
|
|
|
{ID: 2, Text: "Those gestures are back."},
|
|
|
|
|
{ID: 3, Text: "Lyra recognized the troupe."},
|
|
|
|
|
{ID: 1, Speaker: "Host", Text: "The performers arrived."},
|
|
|
|
|
{ID: 2, Speaker: "Guest", Text: "Those gestures are back."},
|
|
|
|
|
{ID: 3, Speaker: "Host", Text: "Lyra recognized the troupe."},
|
|
|
|
|
{ID: 4, Text: "Elsewhere."},
|
|
|
|
|
}}
|
|
|
|
|
req.CandidateProposal[0].TargetSegmentID = 2
|
|
|
|
|
@@ -44,14 +44,15 @@ func TestValidationContextCarriesAdjacentEvidenceAndRelevantDefinitions(t *testi
|
|
|
|
|
if strings.Contains(variables["PayloadJSON"], `"segment_id":`) || rendered[0].CorrectionIndex != 1 || payload.Items[0].CorrectionIndex != 7 {
|
|
|
|
|
t.Fatalf("leaked internal identity or mutated request: %s", variables["PayloadJSON"])
|
|
|
|
|
}
|
|
|
|
|
if len(rendered[0].NeighboringSegments) != 2 || rendered[0].GlossaryEntries[0].Description != "A traveling troupe" {
|
|
|
|
|
if rendered[0].Speaker != "Guest" || len(rendered[0].NeighboringSegments) != 2 || rendered[0].NeighboringSegments[0].Speaker != "Host" || rendered[0].GlossaryEntries[0].Description != "A traveling troupe" {
|
|
|
|
|
t.Fatalf("rendered context: %+v", rendered)
|
|
|
|
|
}
|
|
|
|
|
// The context-free endpoint must not reach beyond the current chunk.
|
|
|
|
|
req.WorkingTranscript.Segments = req.WorkingTranscript.Segments[1:2]
|
|
|
|
|
req.WorkingTranscript.Segments[0].Speaker = ""
|
|
|
|
|
req.Glossary = nil
|
|
|
|
|
isolated, _ := BuildLLMValidationRequest("editorial_review", LLMValidatorTypeEditorialReview, req)
|
|
|
|
|
if len(isolated.Items[0].NeighboringSegments) != 0 || len(isolated.Items[0].GlossaryEntries) != 0 {
|
|
|
|
|
if isolated.Items[0].Speaker != "" || len(isolated.Items[0].NeighboringSegments) != 0 || len(isolated.Items[0].GlossaryEntries) != 0 {
|
|
|
|
|
t.Fatalf("unexpected external context: %+v", isolated)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -63,12 +64,18 @@ func TestValidationContextFitsBudgetWithoutDiscardingCandidate(t *testing.T) {
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
base.Speaker = "Guest speaker with a long identifying label"
|
|
|
|
|
withSpeaker, err := estimateBatchTokens(estimator, []LLMValidationItem{base})
|
|
|
|
|
if err != nil || withSpeaker <= required {
|
|
|
|
|
t.Fatalf("speaker missing from token accounting: before=%d after=%d err=%v", required, withSpeaker, err)
|
|
|
|
|
}
|
|
|
|
|
required = withSpeaker
|
|
|
|
|
enriched := base
|
|
|
|
|
enriched.NeighboringSegments = []NeighboringSegment{{Position: "following", Text: strings.Repeat("long context ", 300)}}
|
|
|
|
|
enriched.GlossaryEntries = []glossary.Entry{{Name: "cat", Description: strings.Repeat("long definition ", 300)}}
|
|
|
|
|
fitted := fitValidationContext(enriched, required, estimator)
|
|
|
|
|
tokens, err := estimateBatchTokens(estimator, []LLMValidationItem{fitted})
|
|
|
|
|
if err != nil || tokens > required || fitted.OriginalSegmentText != base.OriginalSegmentText || fitted.CorrectedSegmentText != base.CorrectedSegmentText {
|
|
|
|
|
if err != nil || tokens > required || fitted.Speaker != base.Speaker || fitted.OriginalSegmentText != base.OriginalSegmentText || fitted.CorrectedSegmentText != base.CorrectedSegmentText {
|
|
|
|
|
t.Fatalf("fitted: %+v tokens=%d err=%v", fitted, tokens, err)
|
|
|
|
|
}
|
|
|
|
|
full, _ := estimateBatchTokens(estimator, []LLMValidationItem{enriched})
|
|
|
|
|
|