Keep transcript sections fixed throughout processing
This commit is contained in:
@@ -162,6 +162,74 @@ func TestRunnerModulesRunSequentially(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunnerKeepsSectionMembershipAfterTextGrowth(t *testing.T) {
|
||||
cfg := runnerTestConfig()
|
||||
cfg.Chunking.MaxSectionTokens = 3
|
||||
cfg.Chunking.MinSectionTokens = 0
|
||||
transcript := &schema.Transcript{Segments: []schema.Segment{
|
||||
{ID: 1, Text: "a"}, {ID: 2, Text: "b"}, {ID: 3, Text: "c"}, {ID: 4, Text: "d"},
|
||||
}}
|
||||
var mu sync.Mutex
|
||||
seen := make(map[int][]int)
|
||||
updatedText := "a one two three four five"
|
||||
r := New(fakeFactory{modules: map[string]contracts.TranscriptModule{
|
||||
"grow": fakeModule{key: "grow", policy: proposals.ReplacementPolicyRequireUnique, proposeF: func(req contracts.ProposalRequest) ([]proposals.CorrectionProposal, error) {
|
||||
if req.Section.Index != 0 {
|
||||
return nil, nil
|
||||
}
|
||||
return []proposals.CorrectionProposal{{TargetSegmentID: 1, OriginalText: "a", CorrectedText: updatedText, Confidence: 1}}, nil
|
||||
}},
|
||||
"inspect": fakeModule{key: "inspect", policy: proposals.ReplacementPolicyRequireUnique, proposeF: func(req contracts.ProposalRequest) ([]proposals.CorrectionProposal, error) {
|
||||
ids := make([]int, len(req.WorkingTranscript.Segments))
|
||||
for i, segment := range req.WorkingTranscript.Segments {
|
||||
ids[i] = segment.ID
|
||||
}
|
||||
mu.Lock()
|
||||
seen[req.Section.Index] = ids
|
||||
mu.Unlock()
|
||||
if req.Section.Index == 0 && req.WorkingTranscript.Segments[0].Text != updatedText {
|
||||
return nil, errors.New("later module did not see updated section text")
|
||||
}
|
||||
return nil, nil
|
||||
}},
|
||||
}})
|
||||
out, err := r.Run(context.Background(), RunInput{Config: &cfg, Transcript: transcript, ModuleSpecs: []contracts.ModuleRunSpec{{ModuleKey: "grow", InstanceName: "grow"}, {ModuleKey: "inspect", InstanceName: "inspect"}}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(out.Sections) != 2 || out.Sections[0].StartSegmentID != 1 || out.Sections[0].EndSegmentID != 2 || out.Sections[0].EstimatedTokens != 2 || len(out.WorkUnits) != 4 {
|
||||
t.Fatalf("initial inventory changed: sections=%+v units=%+v", out.Sections, out.WorkUnits)
|
||||
}
|
||||
if len(seen) != 2 || len(seen[0]) != 2 || seen[0][0] != 1 || seen[0][1] != 2 || len(seen[1]) != 2 || seen[1][0] != 3 || seen[1][1] != 4 {
|
||||
t.Fatalf("later module saw changed section membership: %+v", seen)
|
||||
}
|
||||
if len(out.FinalTranscript.Segments) != 4 || out.FinalTranscript.Segments[0].Text != updatedText || out.FinalTranscript.Segments[3].ID != 4 {
|
||||
t.Fatalf("recombined transcript: %+v", out.FinalTranscript)
|
||||
}
|
||||
if out.WorkUnits[0].CorrectionsApplied != 1 || out.WorkUnits[1].CorrectionsApplied != 0 {
|
||||
t.Fatalf("section application counts: %+v", out.WorkUnits)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunnerInventoriesEmptyWorkAndRejectsImpossibleChunking(t *testing.T) {
|
||||
r := New(fakeFactory{modules: map[string]contracts.TranscriptModule{}})
|
||||
empty, err := r.Run(context.Background(), RunInput{Transcript: &schema.Transcript{}})
|
||||
if err != nil || len(empty.Sections) != 0 || len(empty.WorkUnits) != 0 || len(empty.FinalTranscript.Segments) != 0 {
|
||||
t.Fatalf("empty transcript and pipeline: %+v, %v", empty, err)
|
||||
}
|
||||
input := &schema.Transcript{Segments: []schema.Segment{{ID: 1, Text: "one"}, {ID: 2, Text: "two"}}}
|
||||
noModules, err := r.Run(context.Background(), RunInput{Transcript: input})
|
||||
if err != nil || len(noModules.Sections) != 1 || len(noModules.WorkUnits) != 0 || len(noModules.FinalTranscript.Segments) != 2 {
|
||||
t.Fatalf("empty pipeline inventory: %+v, %v", noModules, err)
|
||||
}
|
||||
cfg := runnerTestConfig()
|
||||
target := 3
|
||||
cfg.Chunking.TargetSections = &target
|
||||
if _, err := r.Run(context.Background(), RunInput{Config: &cfg, Transcript: input}); err == nil {
|
||||
t.Fatal("impossible section target was accepted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunnerProposalsExecutePerChunkSection(t *testing.T) {
|
||||
cfg := runnerTestConfig()
|
||||
cfg.Chunking.MaxSectionTokens = 3
|
||||
|
||||
Reference in New Issue
Block a user