Share a source index across each pipeline run

This commit is contained in:
2026-11-26 01:34:51 +00:00
parent 4b03a439cb
commit 6345727601
10 changed files with 127 additions and 13 deletions

View File

@@ -2,8 +2,10 @@ package pipeline
import (
"context"
"fmt"
"testing"
"gitea.maximumdirect.net/eric/notarius/internal/core/source"
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
)
@@ -40,3 +42,50 @@ func TestRunnerUsesProvidedSessionWithoutSourceFallback(t *testing.T) {
})
}
}
func TestRunnerSharesWholeSourceIndexAcrossJobsAndSteps(t *testing.T) {
prepared := preparedOrderedPipeline(t, 3, orderedLaneSpec{"first", "notes"}, orderedLaneSpec{"second", "notes"})
indexes := make(chan *source.DocumentIndex, 6)
for step := range prepared.Steps {
lane := &prepared.Steps[step].lanes[0]
original := lane.typed.extract
lane.typed.extract = func(ctx context.Context, impl any, request contracts.ExtractionInput, execution ExecutionContext[any]) (erasedTypedResult, error) {
if request.SourceIndex == nil {
return erasedTypedResult{}, fmt.Errorf("missing source index")
}
for position, unit := range request.Source.Units {
if got, ok := request.SourceIndex.Position(unit.ID); !ok || got != position {
return erasedTypedResult{}, fmt.Errorf("source index position for %d = %d, %t, want %d", unit.ID, got, ok, position)
}
}
indexes <- request.SourceIndex
return original(ctx, impl, request, execution)
}
}
var previous *source.DocumentIndex
for run := 0; run < 2; run++ {
doc := typedTestDocumentWithUnits(3)
if run == 1 {
doc.Units[0], doc.Units[2] = doc.Units[2], doc.Units[0]
doc.Digest, _ = source.DigestDocument(doc)
}
prepared.input.(*typedTestInput).doc = doc
prepared.chunker = &typedTestChunker{key: "typed/chunk", plan: typedTestPlan(doc)}
if _, err := New().Run(context.Background(), RunInput{Prepared: prepared, RawInput: []byte("input"), Workers: 3}); err != nil {
t.Fatal(err)
}
if len(indexes) != 6 {
t.Fatalf("observed %d extraction jobs, want 6", len(indexes))
}
first := <-indexes
for i := 1; i < 6; i++ {
if got := <-indexes; got != first {
t.Fatal("jobs did not share the run source index")
}
}
if first == previous {
t.Fatal("separate runs shared a source index")
}
previous = first
}
}